Tic Tac Toe reset Button

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
TheRoflReaper
Posts: 4
Joined: June 3rd, 2012, 9:57 pm

Tic Tac Toe reset Button

Post by TheRoflReaper » June 4th, 2012, 10:28 am

Hi... just finished video 12, and while I can't imagine how to build a better AI I did want implement the enter button to reset the game without exiting and restarting... So I did it :D
soo if you've written your code exactly how Chili did in video 12.. all you need to do is add a few lines of code after the DrawEndScreen function is executed

i'm sure there are better more logical ways of doing this but i don't know and that's why i'm here soooo
here is my version of the button

Code: Select all

void Game::ComposeFrame()
{
	const int baseX = 250;
	const int baseY = 150;
	const int squareSize = 100;

	XOState victoryState = CheckForVictory();
	if( victoryState == EMPTY && nTurns < 9 )
	{
		DoUserInput();
		DrawCursor( baseX + cursorX * squareSize,baseY + cursorY * squareSize );
	}
	else
	{
		DrawEndScreen( 358,495,victoryState );
		if( kbd.EnterIsPressed())
		{
			activePlayer = X;
			victoryState = EMPTY;
			nTurns = 0;
			for( int index = 0; index < 9; index++ )
			{
				SetSquareState( index,EMPTY );
			}
			
		}
	}
if anyone wanted to implement a button i hope this helped :D

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Tic Tac Toe reset Button

Post by chili » June 4th, 2012, 3:08 pm

Looks like a good solution to me. ;)
Chili

Post Reply