I am completely stuck now on my void setupships, bool check position, and the play game. I know that the setting up ships requires the players to choose the coordinates of their five ships, the check position will be the computer(if I am correct) checking whether or not a ship is there, if so an S will be placed on the grid. The play game requires the players to choose coordinates and then a hit a miss will come up. Any help is much appreciated. Thanks
#include <iostream>
using namespace std;
void initializeBoard();//Starting the board
void displayBoard();//Displays p1 and p2 board
void setupShips();//Seting the chips up, choosing the locations of the ships
bool checkPosition(int xpos, int ypos, int player);//checking the players position if the position is correct then it is a hit, if not it is a miss
void playGame();
int main()//my main functions
{
initializeBoard();
displayBoard();
setupShips();
// checkPosition(xpos, ypos, player);//x and y positions of each pleayer
// playGame();
return 0;
} // close main function
// Initialize Board function.
void initializeBoard()
{
for (int i = 0; i<10; i++)
{
for (int j = 0; j < 10; j++)
{
p1board[i][j] = '0';
p2board[i][j] = '0';
} // close inner loop.
} // close outer loop.
} // close initializeBoard function.
} // close inside loop.
cout << endl;
} // close loop.
cout << "\n\n";
cout << "\n1 2 3 4 5 6 7 8 9\n";
for (int i = 0; i < 10; i++)
{
if(i<9)
{
cout << i + 1 << " ";
}
else
{
cout << "10 ";
}
for (int j = 0; j < 10; j++)
{
cout << p2board[i][j];
} // close inside loop.
cout << endl;
} // close loop.
cout << "\n\n";
} // close displayBoard function.
// Setup Ships function
void setupShips()
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
p1board[i][j] = '*'; //This is where the players will choose where...
p2board[i][j] = '*';//..they want their ships to be placed on grid..
} // close inner for loop.
} // close outer for loop.
} // close setupShips function.
// bool CheckPosition goes here.
bool checkPosition(int xpos, ypos)
{ //This is where the player will choose coordinates and if there is a ship it will..
//say S
if (p1board[xpos][ypos] = '*') & (p1board[xpos][ypos] = 's')
{
return true;
} // close if block.
return false;
else if (p2board[xpos][ypos] = '*') & (p2board[xpos][ypos] = 's')
{
return true;
} // close else if block.
return false;
} // close checkPosition function.
// playGame function goes here.// Pretty stuck here
// Declare variables.
char miss = 'm';
char hit = 'h';
char mark = '*';
int xpos, ypos, player;
bool validMove;
char winner = '?';
#include <iostream>
usingnamespace std;
void initializeBoard();//Starting the board
void displayBoard();//Displays p1 and p2 board
void setupShips();//Seting the chips up, choosing the locations of the ships
bool checkPosition(int xpos, int ypos, int player);//checking the players position if the position is correct then it is a hit, if not it is a miss
void playGame();
char p1board[10][10];//player 1 board
char p2board[10][10];//player 2 board
int main()//my main functions
{
initializeBoard();
displayBoard();
setupShips();
// checkPosition(xpos, ypos, player);//x and y positions of each pleayer
// playGame();
return 0;
} // close main function
// Initialize Board function.
void initializeBoard()
{
for (int i = 0; i<10; i++)
{
for (int j = 0; j < 10; j++)
{
p1board[i][j] = '0';
p2board[i][j] = '0';
} // close inner loop.
} // close outer loop.
} // close initializeBoard function.
// Display Board function.
void displayBoard()
{
cout << "\n1 2 3 4 5 6 7 8 9\n";
for (int i = 0; i < 10; i++)
{
if(i<9)
{
cout << i + 1 << " ";
}
else
{
cout << "10 ";
}
for (int j = 0; j < 10; j++)
{
cout << p1board[i][j];
} // close inside loop.
cout << endl;
} // close loop.
cout << "\n\n";
cout << "\n1 2 3 4 5 6 7 8 9\n";
for (int i = 0; i < 10; i++)
{
if(i<9)
{
cout << i + 1 << " ";
}
else
{
cout << "10 ";
}
for (int j = 0; j < 10; j++)
{
cout << p2board[i][j];
} // close inside loop.
cout << endl;
} // close loop.
cout << "\n\n";
} // close displayBoard function.
// Setup Ships function
void setupShips()
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
p1board[i][j] = '*'; //This is where the players will choose where...
p2board[i][j] = '*';//..they want their ships to be placed on grid..
} // close inner for loop.
} // close outer for loop.
} // close setupShips function.
// bool CheckPosition goes here.
bool checkPosition(int xpos, ypos)
{
//This is where the player will choose coordinates and if there is a ship it will..
//say S
if (p1board[xpos][ypos] = '*') & (p1board[xpos][ypos] = 's')
{
returntrue;
} // close if block.
returnfalse;
elseif (p2board[xpos][ypos] = '*') & (p2board[xpos][ypos] = 's')
{
returntrue;
} // close else if block.
returnfalse;
} // close checkPosition function.
// playGame function goes here.// Pretty stuck here
// Declare variables.
char miss = 'm';
char hit = 'h';
char mark = '*';
int xpos, ypos, player;
bool validMove;
char winner = '?';
First thing I noticed is you your bool checkPosition function declaration is different than your function definition header.
You have bool checkPosition(int xpos, int ypos, int player); as a declaration but: bool checkPosition(int xpos, ypos) as a header.
Try changing to:
bool checkPosition(int xpos, int ypos);
&
bool checkPosition(int xpos, int ypos) respectively. You can add the int player to both as needed.
Secondly plboard is not defined. If it is a class definition post it so we can help.
Ok I fixed the bool declaration. I don't think I want it as a class definition. elvenspike, if you see the problem can you share that with me so I can fix it. As I said I am pretty stuck. Thanks