How do i make a play again button?

So im making a tic tac toe game, and i want a play again button to appear if the user wins. Here is some pseudocode i sketched up to give you an idea of what i want to happen if the user wins:

1
2
3
4
5
-Display the message "You win!" to the screen
-Display a Play Again button
-If the user clicks the button
     -Draw the board again over everything to appear as if it were cleared
     -jump to outer while loop to start the game all over again


here is my main function
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**********/
int main( int argc, char* argv[] )
{
	if( Init() == false )
		return 1;

	if( LoadFiles() == false )
		return 1;

	Board gameBoard;
	bool done = false;

	//Render the text
	youWinMessage = TTF_RenderText_Solid( font, "You win!", textColor );
	youLoseMessage = TTF_RenderText_Solid( font, "You LOSE!", textColor );

	//Draw the tic-tac-toe board
	ApplySurface(0, 0, background, screen );

	//Update the screen
	if( SDL_Flip( screen ) == -1 )
		return 1;

	playAgain:
	while( !done )
	{
		while( SDL_PollEvent( &event ) )
		{
			
			if( event.type == SDL_MOUSEBUTTONDOWN )
			{
				if( event.button.button == SDL_BUTTON_LEFT )
				{
					//Get the coordinates where the mouse button was pressed
					int x = event.button.x;
					int y = event.button.y;

					//Handle the user
					gameBoard.DrawUserPiece( gameBoard.PickBox( x, y ), screen );
					if( SDL_Flip( screen ) == -1 )
						return 1;

					//If the user wins
					if( gameBoard.UserWin() )
					{
						ApplySurface( 200, 160, youWinMessage, screen );
						ApplySurface( 200, 200, playAgain, screen );
						if( SDL_Flip( screen ) == -1 )
							return 1;
						
						done = true;
					}
					else
					{
						//Handle the AI
						gameBoard.DrawAIPiece( gameBoard.AIPickBox(),screen );
						if( SDL_Flip( screen ) == -1 )
							return 1;
						SDL_Delay(20);

						if( gameBoard.AIWin() == true )
						{
							ApplySurface( 200, 160, youLoseMessage, screen );
							if( SDL_Flip( screen ) == -1 )
								return 1;
	
							SDL_Delay( 1000 );
							done = true;
						}
					}
				}
			}
			if( event.type == SDL_QUIT )
			{
				done = true;
			}
		}	
	}
	CleanUp();
	return 0;
}

1
2
3
4
5
6
7
8
int main()
{
    bool __continue= false;
    do{
          // game
          // button check
    }while(__continue);
}


make continue true if the button is pressed.
Last edited on
Topic archived. No new replies allowed.