Question
The programming language is Java Create a program that allows the user to play a game of Fog Over Fisher Bank with the computer. Part
The programming language is Java
Create a program that allows the user to play a game of Fog Over Fisher Bank with the computer. Part I: Set-Up You should have two grids: one for the user, and one for the users model of the computers grid. Each cell of the grid should contain a single character. The users model of the computers grid should be initialized to contain only - (minus sign) characters. Internally, the computer should also generate a list of random locations for its own ships during this set up process. To build the users own grid, the program should ask the user where they wish to place their ships. The program should validate the input to make sure that the location entered actually exists on the grid and no other ship has already been placed there. These locations will be represented on the players grid with the capital letter O. All other cells of the grid should be initialized to contain a - (minus sign). One possible initial board is given below. -------- --------
-------- -------- -------- -------- -------- ============== -------- -O------ -------- ----O--O -------- -------- -----O-- -------- Although Fog Over Fisher Bank is traditionally played with two 8 by 8 grids and 4 ships per player, you are free to choose a grid of any size and any number of ships you choose provided that they may all fit in a grid. Part II: Gameplay The two players will take turns firing missiles, or guessing the locations of their opponents ship. The program should always let the user guess first. Before every guess, the program should print the current state of both grids to the console. During the users turn, the program should prompt them for a grid cell to fire upon. After validating the input: If the computer placed a ship at this location, the users representation of the computers grid should be updated to show the capital letter X at that location and the program should report on the console that a ship was sunk. -------- -------- -------- -------- -------- -------- -------- -------- ============== O------- -O------ --O-----
---O---- -------- -------- -------- -------- Please enter the row you want to shoot at: 1 Please enter the column you want to shoot at: 1 You sunk my ship! If there was no ship in that location, the program should determine the sum of the number of ships that were in the same row or the same column as the guessed location. The players representation of the computers grid should be updated to show that number at the location they guessed. -------- -X------ -------- ----1--- -------- -------- -------- -------- ============== O------- -O------ --O----- ---O---- -------- -------- -------- --------
During the computers turn, a random location should be generated to fire upon. The program should report on the console where the computer fired before the board is printed again. -------- -X------ -------- ----1--- -------- -------- --------
============== O------- -O------ --O----- ---O---- -------- -------- -------- -------- The computer shot at (2,6). If the computer sinks one of the Players ships, that ship should be represented by the capital letter X in subsequent reports of the board state. -------- -X------ -------- ----1--- ------0- -------- -------- -------- ============== O------- -O------ --O----- ---X---- -------- -------- -------- --------
The game ends when one player has sunk ALL of their opponents ships. The program should report whether the user won or lost at this time.
1. The two players will take turns guessing the locations of their opponents ships. How will you structure your main loop so that each player is able to take a turn but also end the program after one of the two players has lost?
2. It requires a lot of variables to keep track of a row and column for four ships for each of two players. What classes might you write to make this more manageable?
3. One of the primary distinctions between traditional Battleship and this variant is that players must report how many ships are in the same row or in the same column as the guessed location. How will you determine this number?
4. The user will be asked to enter cells on the grid at least once, but possibly many times if they make typos or do not understand. What kind of loop is best suited for this task?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started