Implement the classic game of Battleship, which allows a human player (user) to face the computer (CPU player).
The game is played on two grids, one for each player. The grids are typically square – usually 10×10 – and the individual squares in the grid are identified by letter and number Before play begins, each player secretly arranges their ships on their grid. Each ship occupies a number of consecutive squares on the grid, arranged either horizontally or vertically. The number of squares for each ship is determined by the type of the ship. The types and numbers of ships allowed are the same for each player. There are two typical complements of ships: Type of ship Size Number per player
aircraft carrier 5 1
battleship 4 2
frigate 3 2
submarine 2 2
The application will ask to the user to specify the location where he wants to place the ships, and will verify that the position of the ships is correct. The ships cannot overlap (i.e., only one ship can occupy any given square in the grid) and a ship cannot “touch” another ship. If the position of the ships is not correct, the application will ask the player to specify the ships location again. After the ships have been positioned by the user, the application will randomly set the location of the CPU player ships.
The game proceeds in a series of rounds. User goes first, and the application will ask the user a grid (ie (2, 5)). If he hits his shoot, he will shoot again (successively). If he misses, his round is over. In the CPU player round, the application will generate a random grid and if it is a hit, the CPU will shoot again. The next shoot will be the grid on top of the previous hit, the grid on the right of the previous hit, the grid at the bottom of the previous hit, and the grid on the left of the previous hit. IN THAT ORDER. ie, if (3,5) is a hit, the next shoot will be (2,5). If it is another hit, next shoot will be (1, 5), and the CPU will look for the ship up and down. But if (2, 5) was a miss, the next shoot will be (3,6) and the CPU will look for the ship right and left.
If (3,6) was a miss, the next shoot will be (4,5) and if (4,5) is a miss, the next shoot will be (3,4) When all of the squares of a ship have been hit, the ship is sunk, if all of a player's ships have been sunk, the game is over and their opponent wins. The application has to implement a mechanism to leave the game if the user doesn’t want to keep playing.
The application will be coded in Java. Be warned that you must use the characteristics of the programming language (object orientation, inheritance ,etc .). Using the Java language in a “Unnatural" way (ie, using Java to use an imperative programming) is not allowed and the project will be rejected.