| Your First Delphi Game: Tic Tac Toe | |||||||||||||||||||||||
| Page 4: New Game? | |||||||||||||||||||||||
There are two more handlers we have to code: create a procedure for a new game, and a procedure that will reset the score.
Note: a player can click on the btnNewGame button after the game is finished (bGameOver = True) or during a game (bGameOver = False). Because of that it would be nice to ask the user to confirm his decision.
In this particular case there would be negligible damage or there would be no damage at all. Just remember that good programming practice implicate getting the user's confirmation.
Double click the btnNewGame button to create and add the code for the New Game option:
Note: if you are using a Non English Delphi version and want to have dialog buttons and messages on your local language, explore the article: "The fastest path to Delphi localization".
The task is simple: set iXScore and iOScore values to zero, and update lblXScore.Caption and lblOScore.Caption.
Off course, get the user's confirmation first.
![]() Some exercises for you...Please, take a look at that CheckWin function again. Note that in case of a "we have a winner" it returns an integer number from 0 to 8. What is this number for? See the picture:![]() If we have a winner and the winner has occupied the middle row, the CheckWin will retun 2.
Anyway be sure to see the full Tic Tac Toe game code. To the next chapter: A Beginner's Guide to Delphi Programming If you need any kind of help at this point, please post to the Delphi Programming Forum where all the questions are answered and beginners are treated as experts. First page > Preparing the Game GUI > Page 1, 2, 3, 4 A Beginner's Guide to Delphi Programming: Next Chapter >> |
|||||||||||||||||||||||


