CS 2121 Introduction to Java:
Programming Assignment 4
Due April 9, 35 points
For this lab you will write a program to play tic tac toe.
The game has two players, the user and the computer.
The program implements a good, but not perfect, strategy for the computer.
When you are finished, your applet should look like the following
demonstration applet.
To play the game, follow the instructions in the message label at the
bottom of the applet.
When a "Push Start New Game button." message appears, you can start a game
by clicking on the "Start New Game" button.
When a "Your play." message appears, you can make a play by clicking on one
of the empty cells.
When it is the computer's turn, a "Push Make Computer Play button." message
appears.
The computer's play will be made when you click on the "Make Computer Play"
button.
The message label will announce when the game is over with one of three
messages: "Game over: Drawn!", "Game over: I win!", or "Game over: You
win!".
At this time, you can start a new game by clicking on the
"Start New Game" button.
The first player for new games will alternate between you and the computer.
Demonstration Applet
The development of this program is broken up into the following steps.
-
Step 1 -
In this step, you will lay out the major components:
a "Start New Game" button,
a "Make Computer Play" button,
a game board,
and a label for messages to the user.
-
Step 2 -
In this step you will add game board cells to the game board.
The cells display X and O marks for the players.
-
Step 3 -
In this step you will set up the response to mouse clicks in cells.
-
Step 4 -
In this step you will set up the response to clicks on the
"Start New Game" button.
-
Step 5 -
In this step you will set up alternate plays between the user and the
computer.
-
Step 6 -
In this step you will detect the end of the game and display an appropriate
message in the message label.
-
Step 7 -
In this step you will implement a game playing strategy for the computer.
-
Step 8 -
In this step you will do a tiny bit of Java 2D graphics to make the X and
O marks look better.