首页 > 其他分享 >BattleShip Human Player

BattleShip Human Player

时间:2024-10-21 18:10:07浏览次数:1  
标签:code player BattleShip ships will Player grid Human ship

Game Description

Battleship is a classic two-player game in which you aim to sink all of your opponent's ships before they sink yours.Each player has a fleet of ships that they place on a grid, and they take turns guessing the locations of theiropponent's ships. In this game version, one player is a human, and the other is a computer.

SETUP

Board: Each player has a 10x10 grid (board) where they place their ships.Ships: Each player has a fleet consisting of different types of ships:

Battleship: Occupies 4 cells.Carrier: Occupies 5 cells.Submarine: Occupies 3 cells.Patrol Boat: Occupies 2 cells.Ships can be placed either horizontally or vertically othe grid.

GAME PLAY

Ship Placement:  Human Player: The human player manually places their ships on their grid. They are prompted to select the type ofship, its starting coordinates, and its orientation (horizontal or vertical).Computer Player: The computer player's ships are automatically placed on its grid based on predefinedconfigurations read from a configuration file (config.txt).

TAKING TURNS:

Players take turns guessing the locations of their opponent's ships by specifying coordinates (x, y) on the grid.The game announces whether the guess is a "hit" or a "miss." A hit means that part of a ship is located at theguessed coordinates. A miss means there is no ship at the guessed coordinates.

WINNING THE GAME:

The game continues until one player has sunk all their opponent's ships.A ship is considered sunk when all of its cells have been hit.The player who sinks all of their opponent's ships first is declared the winner.Game Specifications:The 代 写BattleShip  Human Player game board is a 10x10 grid, each cell represented by square brackets []. The grid is used to place ships andmake guesses. Each cell can either be empty, contain part of a ship, or be marked as a hit or miss.

This is what the empty game board looks like before ships have been placed:Here is a sample board that the human player will see when placing their own ships:

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][P][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][P][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][B][B][B][B][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][C][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][C][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][C][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][C][ ][ ][ ][S][S][S]

[ ][ ][ ][C][ ][ ][ ][ ][ ][ ]TRACK HITS AND MISSES

Another board is used to keep track of the hits and misses.A hit is marked with an X.A miss is marked with an O.Here is an example board:

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][O][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][X][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][O][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ][ ][X][ ]

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

CONFIG.TXT

A configuration file must be read to set up the computer player's arrangement of the board. The configuration fileshould contain a separate line for each type of ship. Each line should include the ship's name, the x coordinate, they coordinate, and whether the placement ishorizontal (H) or vertical (V).Here is a sample config.txt:

Submarine 2 2 H

Battleship 3 3 H

PatrolBoat 4 5 V

Carrier 5 6 H

This is the result:

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][S][S][S][ ][ ][ ][ ][ ]

[ ][ ][ ][B][B][B][B][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][P][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][P][C][C][C][C][C]

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]PROMPT

The program will first read and parse the config file, building the game grid for the computer player. Then, thehuman player will be prompted to input the type of ship, the starting x and y coordinates, and whether the shipshould be placed horizontally or vertically on the game board. After entering the details of each ship, the playerhould see the grid displayed. Once all of the ships have been placed (one of each kind), the player will beprompted to guess the location of one of the computer’s ships by entering the x and y coordinates. If the playerguesses the correct location of one of the ships, the player receives a message indicating a hit. The player shouldbe able to take another turn if they correctly “hit” the computer’s ship. If the player receives a “miss,” the

computer should take a turn, printing out its guess to the player and indicating whether it was a hit or miss. Theprompt should also indicate when a ship has been “sunk” (all spots on the grid for that ship are guessed). Thegame continues until one player sinks all of the opponent's ships. The player who sinks all of the opponent's shipsfirst is declared the winner.

Requirements

The base game components have been provided to you in D2L. Those *.java files contain the clues you need tocomplete a functioning Battleship game. You shouldn’t need to re-write any existing code provided; you must use

the methods and data types indicated. However, you can add any additional classes or enums if you wish.You are to avoid the use of global variables or non-private class variables (using enums is permitted).SubmissionSubmit your completed *.java files to D2L. Do not submit *.class files or any other files. Include your name andUCID at the top of both of those files.DemonstrationYou must demonstrate your assignment to the tutorial leader. The tutorial leader will ask questions to test your

understanding of your submitted code. If you cannot sufficiently answer the questions, your assignment will

receive an incomplete. You will then need to arrange a peer-programming session with the TA to demonstrate

your knowledge of the fundamental aspects of this assignment, where you will be capable of receiving a maximum

grade of C-. Failure to complete this session satisfactorily will result in an F for the assignment.

Unit Tests

To prove your implementation, you must create unit test cases for the code’s functionality.Grading

We will simplify the grading process for this assignment.

A GRADE REQUIREMENTS:

Submission: The assignment is submitted on time to D2L with all required files and a link to GitLab with the TA as adeveloper.Full Functionality: All required functionality is implemented.Code Documentation: The student explains the code with clear comments and documentation.Code Explanation: The student satisfactorily answers the tutorial leader's questions about the code and clearlyunderstands the implementation.

Unit Tests: Adequately tests the program and demonstrates the various principles of unit testing.B GRADE REQUIREMENTS:Submission: The assignment is submitted on time to D2L with all required files and a link to GitLab with the TA as adeveloper.Full Functionality: All required functionality is implemented.

Code Explanation: The student satisfactorily answers the tutorial leader's questions about the code and clearlyunderstands the implementation.One or more of these are insufficient:Test Cases: Some test cases are missing or not comprehensive.

Documentation: Some parts of the code are not adequately documented.

Code Quality: The code is mostly clean and well-organized but may have minor issues in naming conventionsor structure.

C GRADE REQUIREMENTS:Submission: The assignment is submitted on time to D2L with all required files and a link to GitLab with the TA as adeveloper.Code Explanation: The student satisfactorily answers the tutorial leader's questions about the code and clearlyunderstands the implementation.One or more of the following apply:Limited Functionality: File reading/user input is complete, but other methods/mechanics are not.Limited/No Test Cases: Some test cases are missing or not comprehensive.Limited/No Documentation: Some parts of the code are not adequately documented.Code Quality: The code is mostly clean and well-organized but may have minor naming conventions orstructure issues.

标签:code,player,BattleShip,ships,will,Player,grid,Human,ship
From: https://www.cnblogs.com/goodlunn/p/18489192

相关文章

  • EasyPlayer.js 很不错的在线直播播放器支持h.265 h.264
    下载地址:https://github.com/EasyDarwin/EasyPlayer.js?tab=readme-ov-file代码比较简单:<scriptsrc="/scripts/EasyPlayer/EasyPlayer-pro.js"></script><divclass="demo_play"name="demo_play"></div><script>......
  • FFmpeg开发笔记(五十六)使用Media3的Exoplayer播放网络视频
    ​Android早期的MediaPlayer控件对于网络视频的兼容性很差,所以后来单独推出了Exoplayer库增强支持网络视频,在《AndroidStudio开发实战:从零基础到App上线(第3版)》一书第14章的“14.3.3 新型播放器ExoPlayer”就详细介绍了Exoplayer库的详细用法。现在Android官方再次升级Exop......
  • 【Unity】数据持久化PlayerPrefs
    PlayerPrefs存储数据,数据为[key-value]形式可以用保存用户的设置、偏好;历史得分数据等;保存的数据位置不同的系统数据将被保存在不同的位置。Windows系统保存的数据将会被存储在系统注册表中,位置如下:(编辑器运行模式)\HKEY_CURRENT_USER\SOFTWARE\Unity\UnityEditor\DefaultCom......
  • PotPlayer(免费媒体播放器) v1.7.22233.0 多语便携版
    概述PotPlayer是一款由韩国企业Daum开发的免费媒体播放器,它提供了丰富的功能和特点,使其成为许多用户的首选播放器。 软件功能支持多种音视频格式:PotPlayer支持大多数常见的音视频格式,包括MP4、AVI、MKV、MOV、FLV、MP3、WAV等。高质量的音视频播放:PotPlayer采用了先进的解码......
  • CS 417/517: Introduction to Human Computer Interaction
    CS417/517:IntroductiontoHumanComputerInteraction Project1(Fall2024)1IntroductionInthisassignment,yourtaskistoimplementaConvolutionalNeuralNetwork(CNN)andevaluatetsperformanceinclassifyinghandwrittendigits.Aftercompleti......
  • 为什么越来越多的开发者选择了EasyPlayer播放器?
    在当今快速发展的多媒体和数字化时代,视频和音频的播放与处理已成为众多应用的核心功能之一。随着物联网(IoT)、嵌入式系统、智能硬件以及移动应用的普及,寻找一个高效、灵活且易于集成的多媒体播放解决方案成为了开发者们的重要需求。而EasyPlayer播放器凭借其卓越的性能和广泛的......
  • vue 使用LivePlayer H5播放器播放m3u8格式视频
    一、官方网址 https://www.liveqing.com/docs/manuals/LivePlayer.html#%E5%9C%A8-vue-%E4%B8%AD%E4%BD%BF%E7%94%A8二、安装依赖npminstall@liveqing/liveplayer三、复制依赖文件在node_modules下找到这三个文件将他们复制到public文件夹下四、在index.html中引入liveplayer-li......
  • Web video player errors All In One
    WebvideoplayererrorsAllInOneerrorsUncaught(inpromise)DOMException:Theplay()requestwasinterruptedbyacalltopause().Uncaught(inpromise)DOMException:Theplay()requestwasinterruptedbyanewloadrequest.<videoid="video&q......
  • 解决QFC810.exe运行时错误:soundplayer.dll文件丢失,恢复音频播放的实用指南
    当遇到QFC810.exe运行时错误,提示soundplayer.dll文件丢失时,这通常意味着你的系统或应用程序目录中缺少了必要的动态链接库文件(DLL),导致音频播放功能无法正常工作。以下是一份恢复音频播放的实用指南:一、确认问题首先,确认错误消息确实是由于soundplayer.dll文件丢失引起的。这......
  • 使用MPlayer播放音视频
    目录一、MPlayer简介二、MPlayer的安装1.在Linux上安装2.在Windows上安装3.在macOS上安装三、MPlayer的基本用法1.播放本地文件2.播放网络视频流3.播放DVD四、常用选项和参数1.全屏播放2.指定音频/视频输出设备3.调整音量和亮度4.控制播放速度......