11 A classic game of Tic-Tac-Toe

 

This chapter covers

  • Using mouse events in the app
  • Drawing lines
  • Drawing shapes
  • Creating a Drop-down box

Tic-Tac-Toe or noughts and crosses (as it is known in the UK since the shape of the symbols used in the game are the X and O, X refers to the cross and nought it is an old name for zero) has been traced back to 1300BC when similar style boards were found in Egypt. An even earlier version of the game was discovered in the Roman Empire, where they used three pebbles to mark off their positions in the game.

However you call the game, it is clear that it has been a staple favorite for many people all around the world. In 1952, Sandy Douglas developed a computer version of the game called OXO, which went on to be known as one of the first computer games.

WHAT YOU WILL BUILD

In this chapter we build a version of Tic-Tac-Toe and the twist is that the players will be able to draw their responses. Commonly Tic-Tac-Toe computer games use the X and O keys, and the player presses the relevant character on the keyboard. Some versions have also used a symbol that the player presses to play their turn. Our project will enable you to draw the symbols on screen creating new layer of interactivity.

Creating the project

 

Creating a new file

 
 

Importing the modules

 

Creating the variables

 
 

Creating functions that enable you to draw

 

Building the main app

 
 

Creating Tic-Tac-Toe

 
 
 

Creating final versions of Tic-Tac-Toe

 
 
 
 

Importing the modules

 
 
 
 

Creating the functions

 

Building the main app

 
 

Running and testing your GUI program

 
 
 

Summary

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest