Help making Tic-Tac-Toe Game

So I'm making a Tic-Tac-Toe game, I've got up to where x can be placed on the board but I don't know how to decide which player turn it is. I would be highly appreciated if I could get some help.

the graphics library I'm using is SDL
the link to the source code and images is here
http://www.mediafire.com/?tihfigoh2d458hu
Here is one way you could do it...
First add a bool checking which players turn it is, and a surface to hold the current symbol they are using.

1
2
bool Player1 = true; 
SDL_Surface *Symbol = NULL;


Then in your handle_events() function you could add
1
2
3
4
5
6
7
8
9
if(Player1 == true)
{
	Symbol = o; 
}

else
{
	Symbol = xO;
}


Finally you can add a function to change the player every time a player places a piece on the board
1
2
3
4
5
6
7
8
9
10
11
12
13

void Change_Player()
{
	if(Player1 == true)
	{
		Player1 = false;
	}

	else
	{
		Player1 = true; 
	}
}


You will also need to change your event function so it displays the "Symbol" instead of just X so it keeps up with the current player, and make sure it changes the player each time.

1
2
3
4
5
     if ( ( x > board[0].x ) && ( x < board[0].x + board[0].w) && ( y > board[0].y) && (y < board[0].y + board[0].h) )
            {
                apply_surface(0, 0, Symbol, screen);
		Change_Player();
            }


Hopefully that gives you some ideas on how it works anyway, you could also add some text showing which players turn it is at the top right etc.
Last edited on
Topic archived. No new replies allowed.