Question: Battleship Program c++! I meed help implementing my play game function. We were given some code but needed to program one function to play the

Battleship Program c++!
I meed help implementing my play game function. We were given some code but needed to program one function to play the game. Heres the main.cpp:
#include
#include
#include
#include
#include
using namespace std;
// check if a certain position on the board is occupied by a human ship. 1 indicates health ship, 2 indicated sunk portion of ship
string checkPos(int x, int y, int human[][6])
{
string str = "";
if(human[x][y] == 1)
str = "O";
else if(human[x][y] == 2)
str = "X";
else
str = " ";
return str;
}
//print the human's side of the board. This will show if the ships placed are hit
void printBoard(int human[][6], int computer[][6])
{
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
}
void initializePieces(int human[][6], int computer[][6])
{
for(int i = 0; i
for(int j = 0; j
{
human[i][j] = 0;
computer[i][j] = 0;
}
}
void playGame(int human[][6], int computer[][6])
{
///complete this function
}
int main()
{
int human[6][6];
int computer[6][6];
initializePieces(human, computer);
//playGame(human, computer);
return 0;
}
Can someone help me complete the playGame function? It needs to be on a 6x6 board. There will only be 2 ships both of length 2. A healthy ship is marked by O and a hit shit is marked by X
We need to First ask the player to enter the coordinates of the first ship. Make sure that this input is on the board and actually makes up a ship of length 2. Next ask the player to enter the coordinates of the second ship. Again, make sure that these inputs are on the board and make up a ship of length 2. However, this time, also check that the ships are not on top of each other. Next you need to have the computer select the coordinates for his ship. Have the computer first generate a coordinate randomly. After this have the computer pick a random direction to extend the ship. Make sure that these coordinates are valid. Use this same logic to generate the position of the computers second ship making sure the ships do not overlap again. Now the game will begin. Have the human select a coordinate the attack and check if it is a hit or miss. Next have the computer randomly select a location to attack. If it computer registers a hit, print the board to show the outcome of the attack. Once the computer or the human has sunk both ships, print the winner and end the game.
Please help!
 Battleship Program c++! I meed help implementing my play game function.
CAUserst dhaslam Desktop\BattleShip\Solution bin\Debug)BattleShip.exe 5 10 3 10 0 1 23 4 5 Computer has placed his ships randomly Player. enter the position you would like to attack (ex: 1 1>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!