My professor wants to me to create a battleship program that has a grid of 15x15. The battleship program should have five boats in the game:
Frigate: 2 locations
Tender: 2 locations
Destroyer: 3 locations
Cruiser: 3 locations
Carrier: 4 locations
-The ships cannot overlap or be located outside of the board.
-It should allow the user to enter a location.
-The program should display hit or miss..
-The board should display the location the user hit and occupied.
-After the user has sunk the ship, a message should display which ship has been sunk.
-The user gets 60 tries.
I have no idea how to start this program or to make it.. I was just hoping someone could send me a link or program that is similar to this assignment, so I could have a better understanding. Thanks.
You can represent the grid in a two-dimensional 15x15. You can use an enumeration to create a separate state for each index, something that would look like this:
enum STATE { EMPTY, FRIGATE, TENDER, DESTROYER, CRUISER, CARRIER }
If you know:
a. arrays
b. for and while loops
c. rand and srand
d. if statements
e. cin and cout
you should be away!
To start with I would prob use a char rather than an enum. Then you can print the data in your array directly rather than mapping the enum to a displayable string/char. So where ascii suggested EMPTY, FRIGATE, TENDER, DESTROYER, CRUISER, CARRIER, I think you could get away with using '.', 'F', 'T', 'D', 'C', and 'A' (for "aircraft carrier"?)
Why does he need to map each ship do a char? The way he described it, you never actually see any ships, you just shoot at an enemies ships. This means all that needs to be displayed when he draws the game are empty spaces, spaces he has already shot at and missed, and spaces where he hit a ship. This way he can have each square in his game array be set to one of the values in the STATE enum.
The discription of the requiremets, esp. "The board should display the location the user hit and occupied." made me think it would display a board with markers where the user had stuck his "peg" is. Like you do with the real, plastic game?
@asicc - on reflection, I (mostly) get your point. While it's not needed for the actual game, it might be useful to display what's where for debug purposes.
Unless you want a two-way game like the real plastic one. Then your board should display what's where?