Hello!
I've got a simple problem I think, but for some reason it's puzzling me. I intend for the error messages (and other text) to be printed below the board. Here are the two functions that have to deal with the printing of the board. The *this pointer simply prints out the board. Many thanks!
First an overloaded function, (still get same problem without an overloaded version)
and now the play function
I've got a simple problem I think, but for some reason it's puzzling me. I intend for the error messages (and other text) to be printed below the board. Here are the two functions that have to deal with the printing of the board. The *this pointer simply prints out the board. Many thanks!
First an overloaded function, (still get same problem without an overloaded version)
ostream &operator << (ostream &print, const C4Board &B)/>
{
print << "\033[2J\033[1;1H" << "\n";
//start at maxDiscsRow (top row), and work way down
for(int i = B.Board[0].getMaxDiscs() - 1; i >= 0; i--) //assume getMaxDiscs is const
{
for(int j = 0; j <= B.numCols + 1; j++)
{
print << B.Board[j].getDisc(i) << " | ";
}
print << "\n";
}
return print;
}
and now the play function
void C4Board::play()
{
int position;
int turn = 0;
int sentinel = 0; //sentinel value
char playerOneMove = 'X';
char playerTwoMove = 'O';
string choice;
cout << "Two player game or play the CPU?" << endl;
cout << "Type TWO for two player" << endl;
cin >> choice;
cout << *this << endl;
if(choice.compare("TWO") == 0) //checks if input is TWO
{
while(sentinel != -1)
{
cout << "Which column do you want to put your disc in?(1-7)\n";
cin >> position;
if(position > 7 || position < 0) //checks is user places disc in valid column
{
cout << "INVALID MOVE. TRY AGAIN." << endl;
}
else if((turn % 2) + 1 == 1)
{
Board[position].addDisc(playerOneMove); //places X
turn = turn + 1; //next turn if valid move
printf("\033[2J\033\[H");
}
else if((turn % 2) + 1 != 1)
{
Board[position].addDisc(playerTwoMove); //places O
turn = turn + 1; //next turn if valid move
printf("\033[2J\033\[H");
}
if(victory(playerOneMove) == 1 || victory(playerTwoMove) == 1)
{
sentinel = -1;
}
cout << *this << endl;
}
}