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
|
int main()
{
cout << "Welcome to Tic-Tac-Toe" << endl<< "----------------------" << endl << endl;
//create player objects
player player1, player2;
//create temp string to store player name
string tempName;
//random person to start game
unsigned seed = time(0);
srand(seed);
int starterNumber = 1 + rand() % 2;
//enter player 1 name, then set name and player number
cout << "Enter your name, Player 1: ";
cin >> tempName;
player1.setValue(tempName, 1);
tempName = "";
//enter player 1 name, then set name and player number
cout << "Enter your name, Player 2: ";
cin >> tempName;
player2.setValue(tempName, 2);
tempName = "";
//display toss winner
if(starterNumber == 1)
cout << player1.getName() << " won the toss."<< endl;
else if (starterNumber == 2)
cout << player2.getName() << " won the toss."<< endl;
//display game board
tictactoe tictactoe1;
//input row and column, player1 or player2
int row, column, playerNumber, playerIndex;
//playerNumber = starterNumber;
if(starterNumber == 1)
playerNumber = 2;
else
playerNumber = 1;
// ALWAYS RETURNING TRUE FIX IT!!!!
do
{
if(playerNumber == 1)
playerNumber = 2;
else
playerNumber = 1;
if(playerNumber == 1)
{
cout << "Make your move " << player1.getName() << ": ";
cin >> row >> column;
playerIndex = 1;
while (tictactoe1.setValue(row, column, playerIndex) != true);
{
cout << "Invalid Move, make your move " << player1.getName() << ": ";
cin >> row >> column;
playerIndex = 1;
}
}
else
{
cout << "Make your move " << player2.getName() << ": ";
cin >> row >> column;
playerIndex = 2;
while (tictactoe1.setValue(row, column, playerIndex) != true);
{
cout << "Invalid Move, make your move " << player1.getName() << ": ";
cin >> row >> column;
playerIndex = 1;
}
}
}while (tictactoe1.getStatus() == 3);
}
| |