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
|
int main()
{
char numgrid[3][3] = {
{ '1' ,'2' ,'3' },
{ '4', '5', '6' },
{ '7', '8', '9' } };
char grid[3][3] = {
{ ' ' , ' ' , ' ' },
{ ' ', ' ', ' ' },
{ ' ', ' ', ' ' } };
int result{};
std::size_t count{};
std::cout << "\n NAUGHTS AND CROSSES\n" << std::endl;
std::cout << "---------------------\n" << std::endl;
printGrid(grid);
std::cout << "--------------------\n" << std::endl;
printFirstGrid(numgrid);
std::cout << "--------------------\n" << std::endl;
std::cout << "\nPLAYER 1 = O\n" << std::endl;
std::cout << "PLAYER 2 = X \n" << std::endl;
bool stillPlaying = true;
while (stillPlaying)
{
player1Turn(grid, numgrid);
std::cout << "------------------" << std::endl;
printFirstGrid(numgrid);
std::cout << "------------------" << std::endl;
result = win(grid, count);
if (result == 1)
{
std::cout << "\n GAME OVER - PLAYER 1 HAS WON\n" << std::endl;
bool stillPlaying = false;
break;
}
else if (result == 2)
{
std::cout << "\n GAME OVER - PLAYER 2 HAS WON \n" << std::endl;
bool stillPlaying = false;
break;
}
else if (result == 3)
{
std::cout << "\n THE GAME IS A TIE.\n" << std::endl;
break;
}
player2turn(grid, numgrid);
std::cout << "------------------" << std::endl;
printFirstGrid(numgrid);
std::cout << "------------------" << std::endl;
result = win(grid, count);
if (result == 1)
{
std::cout << "\n GAME OVER - PLAYER 1 HAS WON\n" << std::endl;
bool stillPlaying = false;
break;
}
else if (result == 2)
{
std::cout << "\n GAME OVER - PLAYER 2 HAS WON \n" << std::endl;
bool stillPlaying = false;
break;
}
else if (result == 3)
{
std::cout << "\n THE GAME IS A TIE.\n" << std::endl;
break;
}
}
return 0;
}
|