Question: This is C++, and having a lot of difficulty figuring this out. Write a program to play a game in which you try to sink
Write a program to play a game in which you try to sink a fleet of five navy vessels by guessing their locations on a grid. The program uses random numbers to position its ships on a 15 x 15 grid. The ships are of different lengths as follows: Frigate: 2 locations Tender: 2 locations Destroyer: 3 locations Cruiser: 3 locations Carrier: 4 locations The program must pick one square (at random) as the starting location, then pick the direction of the ship on the board and mark off the number of squares in that direction to represent the size of the ship. The direction of placement can be one of these four: up, down, right, left. It can not place ships on diagonals. It must not allow a ship to overlap with another ship or to run off the board, i.e., part of the ship goes out of the board boundary. This means that it is possible to pick a starting location, and the direction of the placement of the ship, and find out that these combination does not fit the ship properly on the board, without overlapping with existing ships and without being out of the board. So, the process of placing the ship needs to be repeated. Figure 1 shows an example where all Five ships were properly placed on board. Figure 1 Ships placed properly on board (F: Frigate, T: Tender, D: Destroyer, C: Cruiser, A: Carrier) The user is prompted to enter the coordinates in the range of I through 15 for the rows and A through O for the columns. The program checks this location, and reports whether it is a hit or a miss. If it is a hit, the program also checks whether the ship has been hit in every location that it occupies. If every location of a ship is hit, the ship is sunk by the user The user gets 60 shots to attempt to sink the fleet. Appropriate message should be given to the user on whether the shot hits or misses a ship, and whether a ship is sunk. If the
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
