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
|
Description:Program allows two players to play tic tac toe. The program must run in a loop that:
1. Displays the contents of the board array.
2. Allows alternating player 1 or 2 to select a location on the board for an X or an O. The program should ask the user to enter the selected location or the row and column number.
3. Determine whether a player has won after each selection. The program should declare the winner if it occurred. Then the program ends.
4. Do not allow the players to select locations already taken.
5. For extra credit, test each selection to see if a tie has occurred and notify the user of the tie to end that session.
Limitations or issues:
Credits: Not Applicable
*/
#include <iostream>
#include <iomanip>
using namespace std;
//Constant for array size
const int ARRAYSIZE = 9; //Lazy, not passing with functions
// Function prototypes
void displayBoard(char []); //displays the board
void playerTurn(char [], char); //places X or O in correct location
bool gameOver(char []); //uses playerWins() and checkForCatGame()
//to see if game is over
bool playerWins(char [], char); // check to see if either X or O won
bool checkForCatGame( char []); //check to see if no moves remaining
void displayWinner(char []); //uses playerWins() to double check
//who won
int main()
{
void displayBoard(char[]);
/* char gameBoard[ARRAYSIZE] =
{ '1', '2', '3',
'4', '5', '6',
'7', '8', '9'
};
cout << " Columns\n";
cout << "Row: ";
for (int ARRAYSIZE = 0; ARRAYSIZE < 3; ++ARRAYSIZE)
cout << gameBoard[ARRAYSIZE] << " ";
cout << endl;
cout << "Row: ";
for (int ARRAYSIZE = 3; ARRAYSIZE <6; ++ARRAYSIZE)
cout << gameBoard[ARRAYSIZE] << " ";
cout << endl;
cout << "Row: ";
for (int ARRAYSIZE = 6; ARRAYSIZE <9; ++ARRAYSIZE)
cout << gameBoard[ARRAYSIZE] << " ";
cout << endl;*/
system("pause");
return 0;
}
void displayBoard(char[])
{ // Array for the game board.
char gameBoard[ARRAYSIZE] =
{ '1', '2', '3',
'4', '5', '6',
'7', '8', '9'
};
cout << " Columns\n";
cout << "Row: ";
for (int ARRAYSIZE = 0; ARRAYSIZE < 3; ++ARRAYSIZE)
cout << gameBoard[ARRAYSIZE] << " ";
cout << endl;
cout << "Row: ";
for (int ARRAYSIZE = 3; ARRAYSIZE <6; ++ARRAYSIZE)
cout << gameBoard[ARRAYSIZE] << " ";
cout << endl;
cout << "Row: ";
for (int ARRAYSIZE = 6; ARRAYSIZE <9; ++ARRAYSIZE)
cout << gameBoard[ARRAYSIZE] << " ";
cout << endl;
}
|