Question
Please use C++! implement a battleship game.The output and input have to be same as the sample. The two boards should appear side by side.
Please use C++!
implement a battleship game.The output and input have to be same as the sample.
The two boards should appear side by side.
void displayBoards(char [][10], char [][10]);
Note:When you display the board, you are also displaying the contents of the 2D arrays, even though initially they will be empty.
Your program should have the following:
Global constants storing the size of each of the 5 ships
Global constant storing the size of the fleet
A struct named Point, storing two ints that will have the row and column index of a particular cell in the grid
A struct named Ship, that will store at least 4 variables.
The name of the ship
The size of the ship
The current hitcount of the ship
A vector of Point structs that will store the indices of each of the cells in the grid the ship occupies.
A struct named PlayerBoard that
Stores the 10 x 10 board (char) for that particular player
Stores an array of Ship structs of size FLEET_SIZE
A setShip function that takes in a Ship object by reference and a playerboard and places the ship onto the board. The setShip function calls the getShipInfo function to determine which spots on the board the ship will occupy.
A getShipInfo function that takes in four parameters by reference, two ints holding the row and the column of the starting coordinates of the ship, a char that will hold the orientation of the ship (horizontal or vertical), and the ship. The function will prompt the user for the starting row and column coordinates of the ship which the user will enter as: letter number. These will then need to be converted to the proper row and column index of the array. The function will also prompt the user for the horizontal or vertical orientation of the ship.
An initBoard function that takes in two PlayerBoard objects by reference, and calls the setShip function for each ship in the fleet. After each ship is placed on the board the boards should be displayed.
An initFleet function that takes in a PlayerBoard object as a parameter and initializes all the ships in the fleet with the appropriate information. For example, the name and size of the ship should be initialized within the function.
The rest of your implementation is up to you. Notice in the sample file you will have to do some input validation.
# Class of ship Size 1 Carrier 5 2 Battleship 4 3 Cruiser 3 4 Submarine 3 5 Destroyer 2
.....player 2 set board.
Your Board Enemy Board 1 23 4 5 6 78 9 10 1 2 3 4 5 6 78 9 10 I) I I I I Your Board Enemy Board 1 23 4 5 6 78 9 10 1 2 3 4 5 6 78 9 10 I)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started