Hello,
I have an assignment to make a tic tac toe game using 1-9 in a grid (but without 1 l 2 l 3 and instead, 1 2 3 etc.). I'm having an impossible time figuring out how to redisplay the new x or o (see function comments).
Is there anyone out there that can give me a hint as to what direction I should go to display the updated game grid? I've seen many tic tac toe examples on here but a lot of them are more advanced than necessary or are using attributes I'm not familiar with.
Thanks!
#include <iostream>
using namespace std;
int Change_Board_X(int& Player_1_Move); ////Change from the # ////entered by Player 1 to an X on the board
int main ( )
{
int Player_1_Move = 0;
char Repeat = 0;
int game_grid[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
do
{
for(int index1 = 0; index1 < 3; index1++)
{
for(int index2 = 0; index2 < 3; index2++)
{
cout << " " << game_grid[index1][index2] << " ";
}
putchar('\n');
}
cout << endl << "Here is your tic tac toe gameboard. Player 1 will be X and Player 2 will be O.\n" << endl;
cout << "Player 1: Please make your first move by entering a number between 1 and 9: \n";
cin >> Player_1_Move;
Change_Board_X (Player_1_Move);
cout << endl << "Would you like to do this again? "
<< "Enter (Y) for Yes and (N) for No and Press Enter: ";
cin >> Repeat;
cout << endl;
} while ( Repeat == 'y' || Repeat == 'Y' );
return 0;
}
int Change_Board_X(int& Player_1_Move) //Obviously this function doesn't work yet. I had hoped to do a swap_values function or something to trade out a number entered with an x or o but I can't find a way to tap into my array if I have specific 1-9 values. I also thought about searching the array but I couldn't get it to search properly on a 2d array
{
return (Player_1_Move);
}