CPTR 124 Fundamentals of Programming


In this lab you will construct a prototype for a graphical interface to the game Tic-Tac-Toe.


Teams

You are encouraged to work with a partner for this lab. You and your partner should begin thinking about the problems and begin writing the code before lab time.

Background

For a background on the Tic-Tac-Toe game, see http://en.wikipedia.org/wiki/Tic-tac-toe. Your task is to provide a prototype for a graphical interface for Tic-Tac-Toe. This assignment is the first part of a two-part project. In the second part you will implement a game engine that controls the execution of a two-player Tic-Tac-Toe game. This part of the project provides a good start to the look and feel of the overall application, but you will need to adapt your prototype from this assignment to behave properly with your completed game engine.

What to do

For this assignment you must write a Python program that uses Turtle graphics to draw a Tic-Tac-Toe board. Your program must allow a user to click an area of the board to place a player. The possible players are X and O. The figure below shows the application during its execution.

Screenshot of Tic-Tac-Toe prototype application

We will identify the areas of the board by the strings shown in the table below.

String

Meaning

Role

"NorthWest"

Top-left square

Board location

"North"

Top-middle square

Board location

"NorthEast"

Top-right square

Board location

"West"

Left-middle square

Board location

"Center"

Center square

Board location

"East"

Right-middle square

Board location

"SouthWest"

Bottom-left square

Board location

"South"

Bottom-middle square

Board location

"SouthEast"

Bottom-right square

Board location

In this assignment your program will not enforce player alternating turns or prevent placing a mark over an existing mark. Your program will allow the user to select the current player by pressing the X or O key on the keyboard. For this assignment you will not attempt to detect a winning configuration, nor will you attempt to prevent illegal moves. The goal of this assignment is to perfect the visual elements of the game.

You have considerable freedom to write your code as you see fit, but the functions below are highly recommended to get your code up and running and to ease the transition to the second part of the assignment:

Your program should run indefinitely until the user closes the application. This means the last line in your code should not call done or exitonclose; instead, your last line should be

mainloop()

This passes control of your program to the Turtle graphics event loop. The event loop monitors users' actions such as clicking the mouse and pressing keys on the keyboard. You have the opportunity to write code that can react to these events. In your program you should write three more functions—the callback functions that you must register with the graphical framework:

Notes

Check out

Your finished program will be evaluated for correctness and compliance. Once you have been checked out you may submit your code to eclass.e.southern.edu.