1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include "TicTacToe.hpp"
#include "Board.hpp"
#include <iostream>
using namespace std;
int main()
{
char select;
cout << "This game will generate a tic tac toe board and allow the user ";
cout << "\nto enter coordinates for player1 and player2 . It will continue ";
cout << "\nwith the game until someone wins or it is a draw.." << endl;
cout << "\n\nPlease select who player1 will be, either 'x' or 'o': ";
cin >> select;
TicTacToe game(select);//object declared
game.play();//play function call
return 0;
}
/**********************************************************************
* int TicTacToe::TicTacToe()
*
* This is the constructor which wil take in the user inut for player1 and
* pass that to the game object.
***********************************************************************/
TicTacToe::TicTacToe(char select)
{
player1 = select;//sets player 1 to x or o based on main
}
/**********************************************************************
* void TicTacToe::play()
*
* This function will take in who is player one then loop through each
* players turn until there is a winner or a draw.
***********************************************************************/
void TicTacToe::play()
{
char rowIn, columnIn, player2, currentPlayer;
cout << player1 << " has chosen the begin the game. " << endl;
do
{
newPlay.print();//prints initial board normally
cout << "\nPlease enter the coordinates for your move: ";
cin >> rowIn >> columnIn;//take in values for row and clolumn
currentPlayer = player1;sets current player to player1
while (!newPlay.makeMove(rowIn, columnIn, currentPlayer)//incoplete loop that checks for valid input
{
cout << "\nInvalid entry, please enter valid coordinates";
cout << \nPlease enter valid coordinates: "
cin >> rowIn, columnIn, currentPlayer;
}
newPlay.print();//should print updated board, here it prints the double board
if (player1 == 'x')//if else to change players
{
player2 = 'o';
}
else if (player1 == 'o')
{
player2 = 'x';
}
cout << "\nPlayer 2, please enter the coordinates for your move: ";
cin >> rowIn >> columnIn;
currentPlayer = player2;//sets current player to player2 for makeMove function
while (!newPlay.makeMove(rowIn, columnIn, currentPlayer)
{
cout << "\nInvalid entry, please enter valid coordinates";
cout << "\nPlease enter valid coordinates: ";
cin >> rowIn, columnIn;
}
newPlay.print();//should print updated board, prints normal board
}
while (newPlay.gameState() == Continue);
|