Question
Battleship(Java Code - Please make it as simple as possible, no private class preferred) In this assignment we recreate the 2-player game Battleship. This assignment
Battleship(Java Code - Please make it as simple as possible, no private class preferred)
In this assignment we recreate the 2-player game Battleship. This assignment will give you lots of practice with two dimensional arrays.
In part 1, we will make a one player version and we will start with our ships in set positions. This makes it easy for you in testing your program, and easy for me to help you. In part 2 we will deal with randomized ship placements.
Battleship starts with two boards for a player. There is a board with the ship's location, and a second board for the players' guesses. Each guess is marked at a hit or a miss. On the final hit on a ship, the guesser is told that they have sunk the ship.
Here is the Ship Location Board that we will use in Part 1:
| 1 | 2 | 3 | 4 | 5 | 6 |
A | 2 |
|
|
|
|
|
B | 2 |
|
|
| 3 |
|
C |
|
|
|
| 3 |
|
D |
|
|
|
| 3 |
|
E |
|
|
|
|
|
|
F |
|
| 4 | 4 | 4 | 4 |
Where the numbers in the grid mean the length of that ship. The ship of length 2 is called the Patrol Boat, of length 3 is the Destroyer and of length 4 is the Battleship.
Then there is the players guess board that would look like this after this series of guesses: C3, A4, D1, B5
| 1 | 2 | 3 | 4 | 5 | 6 |
A |
|
|
| O |
|
|
B |
|
|
|
| X |
|
C |
|
| O |
|
|
|
D | O |
|
|
|
|
|
E |
|
|
|
|
|
|
F |
|
|
|
|
|
|
Here O represents a miss while X represents a hit
You need to ask the user to input guesses in the form of B5 or b5 and say hit or miss. Upon sinking a ship you need to display You sunk the Battleship, or whichever ship was sunk. When the final ship has been sunk, you need to display Game over, You Win!.
In my example, I made a display grid with lines. You dont need to do this. You could simply initialize your guesses matrix with ., and replace them with Xs or Os as needed.
Sample Run #1
Here is my board after the third guess:
B1 is a hit
You sunk the Patrol Boat
ENEMY
1 2 3 4 5 6
___ ___ ___ ___ ___ ___
A |_X_|_O_|___|___|___|___|
B |_X_|___|___|___|___|___|
C |___|___|___|___|___|___|
D |___|___|___|___|___|___|
E |___|___|___|___|___|___|
F |___|___|___|___|___|___|
Please enter a guess in the form 'B5':
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