CPTR 124 Fundamentals of Programming


In this lab you will construct a graphical Tic-Tac-Toe game.


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 write a graphical Tic-Tac-Toe game in C++ using the SGL library's procedural interface. You may begin with blue square graphical program that we developed in class.

What to do

For this assignment you must complete a C++ program that uses the procedural interface to the SGL graphics library to implement a rudimentary Tic-Tac-Toe game. 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

The skeletal code you should begin with is found in tic_tac_toe_skeleton.cpp.

We will identify the areas of the board by the Square enumeration types (Square::Northwest, Square::North, etc.) as shown in the following table:

Square

Meaning

Role

Square::Northwest

Top-left square

Board location

Square::North

Top-middle square

Board location

Square::NorthEast

Top-right square

Board location

Square::West

Left-middle square

Board location

Square::Center

Center square

Board location

Square::East

Right-middle square

Board location

Square::SouthWest

Bottom-left square

Board location

Square::South

Bottom-middle square

Board location

Square::SouthEast

Bottom-right square

Board location

You should use nine global variables to keep track of the mark corresponding to each of these locations (I called mine nw, n, etc.). Each one of these variables holds a Player value. They all start out with the value Player::None to indicate at the beginning of the game no square holds any marks.

You should use a global variable to keep track of whose turn it is (I called mine current_player). This variable holds a Player value as well—Player::X or Player::O. In Tic-Tac-Toe X always has the first move.

Your program should enforce player alternating turns and prevent a player from placing a mark over an existing mark.

In this assignment you do not need to check for a winning configuration.

You must complete the functions that appear in the skeletal code.

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.