Battleship. Create a project titled Lab8_Battleship. You are to program a simplified version of the Battleship guessing game. The field (ocean) is a square 5x5 grid. One of the coordinates of the grid is a number (from 1 to 5) and the other -- a letter (from 'a' to 'e'). Your program should randomly place a fleet of five ships in the ocean. Each ship takes up exactly one location in the ocean. Multiple ships cannot be placed in the same location. The ships, however, can be placed in adjacent locations. The user fires on the ships by specifying the coordinates of the shot. The program reports whether each shot was a hit or a miss. If the shot was a hit, the ship is sunk. The game continues until all ships are sunk. The program does not keep track of the locations of the previously fired shots.
You should use this header file. The header file defines structures and prototypes functions used in the program. You should implement your functions incrementally: start with location functions, then ship functions, then fleet (array of ships) functions. Use the following file to test your implementation. Presently, the file has location functions commented in while ship and fleet functions commented out. Once you implemented and tested your location functions, comment in ship and then fleet functions and test those. Note that successful compilation of this file does not guarantee correct implementation of the functions. It is just a test.
The header file defines two structures:
The header file prototypes the functions to be used in the implementation. You are advised to define (implement) the functions incrementally in the order prototyped in the header file. As you complete a function, invoke it in main() to make sure it works correctly.
The functions are separated into three groups:
declare a variable that stores the number of the deployed ships, initially zero
this variable is to be used as an index in the array of ships
loop until all ships are deployed
invoke pick() to get a new random location in the ocean
invoke check() to verify whether this location is occupied
if this location is available then
deploy the next ship at this location by storing the coordinates
of this location in the ship's location, change the status of
the ship to "not sunk"
increment the number of the deployed ships
Hint: To randomly assign a character coordinate (from 'a' to 'e') for the location in pick(), randomly select a number from 1 to 5 and then use a switch to select the appropriate letter.
Hint 2: The logic of initialize(), check() and deploy() is very similar to the logic of lottery number selection functions in one of the previous labs.
The printout is done using the following functions.
while at least one ship is operational
invoke fire() to get the location of the next shot from the user
invoke check() to see if this location is occupied by a ship
if location is occupied then
invoke sink() to sink the ship
report a hit
else
report a miss