Question: I have a project in which we are creating a Battle Boats game in Java (similar to Battleship) and I'm unsure of how to approach.
I have a project in which we are creating a Battle Boats game in Java (similar to Battleship) and I'm unsure of how to approach. Code would be nice but of course I'd like to understand the solution as well so an explanation would be great.
We are required to use a BattleboatsBoard class to represent the board with a 2D array, however the type of this 2D array is our choice and I'm not sure what the best choice is. My first instinct was booleans but I'm not sure that has enough information because of the other requirements of the project.
A boat is a line of 3 consecutive squares on the board. They may not overlap, extend outside, or be placed diagonally. The program should determine the direction and placement of boats randomly. I have no idea how to approach this in any efficient manner. Quantity of the boats is determined by the width and height of the board like so:
| Dimensions | Boats |
| width == 3 or height == 3 | 1 |
| 3 < width <= 5 or 3 < height <= 5 | 2 |
| 5 < width <= 7 or 5 < height <= 7 | 3 |
| 7 < width <= 9 or 7 < height <= 9 | 4 |
| 9 < width <= 12 or 9 < height <= 12 | 6 |
Using a scanner the player enters an x,y location to attack. If no boat, print miss. If they have already attacked that location or the location is out of bounds, penalty. If there is a penalty the user's next turn will be skipped. If there is a boat, print hit, if this attack sinks the boat, print sunk. I'm unsure of how to keep track of all of this information in the program.
However, and this part confuses me as well, the player has an option for a "drone" mode to scan a small area of the board. If they use this, print "recon", 4 of their turns are skipped, and then the contents of an input location and the immediately surrounding squares are revealed to them. Game is over when all boats are sunk. Total attacks and total turns are printed, with lower scores being better. The board with what the user should know about it is printed after every turn.
Finally, there is a requirement to include a debug mode in which all of the game board's information is printed on the screen in any clearly understandable format before every turn. However, you must differentiate what would be visible to the player and what wouldn't be in normal play. Before play begins you are to get input to determine whether to run the game in "normal" mode or debug mode.
I don't have a firm grasp on 2D arrays so this project is hard to wrap my mind around so a full solution isn't necessary, but some advice on how to approach the parts of this project would be appreciated.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
