Problem: Create a program to play a variation of the “Battleship” game using computer generated locations of the ships. The ships will be located on a 15 by 15 grid. Your program should use random...


Problem: Create a program to play a variation of the “Battleship” game using computer generated locations of the ships. The ships will be located on a 15 by 15 grid. Your program should use random numbers (remember to seed the random number function so it does not put the ships in the same location every game) to locate the five ships and direction of the ships (may be up/down or right/left). The lengths of the ships are:


Frigate: 2 squares


Tender: 2 squares


Destroyer: 3 squares


Cruiser: 4 squares


Carrier: 5 squares


Your program must select the location of the first square of each ship and then choose the direction for the remaining squares for the particular ship using random numbers. Ships cannot go off the grid and cannot overlap. Store the ship locations in one 2-dimensional array that indicates ship type and location.


Once the program has generated the location of the ships, your program should ask the player to select a possible square by coordinates of 1 through 15 for the rows and A through O for the column. Your program should determine if the user’s guess was a hit or miss and store the result in a second 2-Dimensional array. If the result was a hit, your program will need to check whether the specific ship that was hit has been hit in all of that ship’s location and is therefore sunk. If a ship has been sunk, your program should output which ship was sunk. After each guess, your program should output the 2-dimensional array showing the player’s guesses, indicating whether the guesses were hits or misses, and squares not chosen as guesses yet.


Game ends when the player sinks all 5 ships or has exhausted all 150 of his/her allotted guesses. If all 5 ships were sunk, the program should output a message stating the player won. If not all 5 ships were sunk, the message should state the player lost. In either case the 2-D array showing the location of the ships should be output. Ship locations should also indicate what type of ship was located there, i.e. use a different symbol for frigate than used for carrier. Your program should allow the player to play the game again without exiting the program.


Your code should employ a function to output the 2-dimensional array. You may build other functions as you want.


For both options, do not use any concepts beyond Chapter 7 of your text book. Do not use defined pointers. Remember that function definitions should occur after main and you should have comments for each function immediately before the function heading (header) that describes the purpose of the function, input to the function (what is sent to the function), output from the function (what is sent back to the function call by reference parameters or by a return statement), and processing for the function. Make sure that you follow assignment guidelines.



Apr 15, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here