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
|
using namespace std;
const int fill0 = 0;
const int fill1 = 1;
const int fill2 = 2;
void Xturn(char tic[3][3], int row, int column, bool& player);
void didXwin(char tic[3][3], bool& win);
void Yturn(char tic[3][3], int row, int column, bool& player);
void didYwin(char tic[3][3], bool& win);
int main() {
char keeplaying = 'n';
char again = 'y';
cout << "New Game: X goes first." << endl;
while (again == 'y') {
char tic[3][3];
while (keeplaying == 'n') {
cout << "--------------------------" << endl;
cout << "|R/C| 0 | 1 | 2 | " << endl;
cout << "--------------------------" << endl;
cout << "| 0 | " << tic[fill0][fill0] << " | " << tic[fill0][fill1] << " | " << tic[fill0][fill2] << " |" << endl;
cout << "--------------------------" << endl;
cout << "| 1 | " << tic[fill1][fill0] << " | " << tic[fill1][fill1] << " | " << tic[fill1][fill2] << " |" << endl;
cout << "--------------------------" << endl;
cout << "| 2 | " << tic[fill2][fill0] << " | " << tic[fill2][fill1] << " | " << tic[fill2][fill2] << " |" << endl;
cout << "--------------------------" << endl;
cout << "X's turn" << endl;
cout << "Where do you want your X placed?" << endl;
cout << "Please select a number and column number seperate by a space." << endl;
int row, column, test = 1;
bool player = true;
bool winner = true;
cin >> row >> column;
Xturn(tic, row, column, player);
cout << "You have entered row#" << row << endl;
cout << "And column #" << column << endl;
cout << "Thankyou for your selection." << endl;
didXwin(tic, winner);
if (winner == false)
break;
cout << "--------------------------" << endl;
cout << "|R/C| 0 | 1 | 2 | " << endl;
cout << "--------------------------" << endl;
cout << "| 0 | " << tic[fill0][fill0] << " | " << tic[fill0][fill1] << " | " << tic[fill0][fill2] << " |" << endl;
cout << "--------------------------" << endl;
cout << "| 1 | " << tic[fill1][fill0] << " | " << tic[fill1][fill1] << " | " << tic[fill1][fill2] << " |" << endl;
cout << "--------------------------" << endl;
cout << "| 2 | " << tic[fill2][fill0] << " | " << tic[fill2][fill1] << " | " << tic[fill2][fill2] << " |" << endl;
cout << "--------------------------" << endl;
cout << "O's turn." << endl;
cout << "Where do you want your O placed" << endl;
cout << "Please enter row number and column number seperated by a space." << endl;
cin >> row >> column;
Yturn(tic, row, column, player);
didYwin(tic, winner);
if (winner == false)
break;
}
cout << "Would you like to play again?(y/n)" << endl;
cin >> again;
}
}
|