CS 202 - Computer Science II - Spring 2008
Project 4
Loyola College >
Department of Computer Science >
Dr. James Glenn >
CS 202 >
Projects >
Project 4
Due
Monday, April 28th at 11:59pm.
Projects submitted after the due date will be assessed a 20% penalty per day.
Projects will not be accepted more than four days late.
Objectives
- to use the model/view/controller architecture
- to use Java Swing classes
- to perform network communication
Introduction
Pig
is a two-player game played with a single six-sided die.
On each turn, the current player rolls the die and, if the result
is not 1, adds the result to the turn score. After each roll, the
player has the option of ending the turn, adding the turn score
to the total score, and passing control to the next player,
or rolling again. If a player rolls a 1 then
the turn is over and nothing is added to the total score. The game is
over when one player reaches 100 or more points. After each roll,
players must strategically determine whether so much progress has been made
that it is not worth risking another roll.
Assignment
Create a GUI version of Pig that allows human vs. computer play. The
human should go first. You can create a simple computer player that
rolls until it has won or until the turn total is at least some fixed
amount (20 in the applet given above).
Your program should follow the model/view/controller architecture.
In addition, at the end of a game, you should connect to the server
at port 4502 on gunpowder.cs.loyola.edu and send a play-by-play
account of the game. Each line in the account should be in the form
human-score:computer-score:current-player:turn-total:action
where current-player is 0 or 1 (for human and computer respectively)
and action is ROLL:result or END. For example,
the following describes a game
0:0:0:0:ROLL:3
0:0:0:3:ROLL:6
0:0:0:9:ROLL:2
0:0:0:11:END
11:0:1:0:ROLL:1
11:0:0:0:ROLL:6
11:0:0:6:ROLL:6
11:0:0:12:END
At the end
of the account you must send a single line containing the string "DONE".
You must not send the account until the end of the game.
Files
You needn't write the server. For testing, you can use the following server
that displays every message that is sent to it and keeps track of human
wins and computer wins. To test on your own computer, run
PigServer and PigWindow at the same time
(this requires a trick in jGRASP). If the server is running
on your computer, have the client connect to host "127.0.0.1" on port 4502.
Advice
- Start by creating and testing the model. To determine what methods
your model should have, think about what the view will need to know
in order to draw the game and what the controller will need to do
in response to user input.
- Your GUI needn't look the same as the one given above, but it
should provide the same information. It should be clear to the
player what input is expected at all times.
- My computer player is a separate class from the model. It is
essentially a second controller. My GUI controller sends a message
to the computer player (by invoking a method), which then checks the
state of the model and uses the same methods used by "Roll" and "Hold"
to tell the model what the computer would like to do.
- You can use the Observable class and the Observer
interface to have the model inform the controller and the view when
it has changed. The model would be a subclass of Observable,
from which it would inherit addObserver, setChanged,
and notifyObservers. The model would invoke
its setChanged
and notifyObservers methods any time it changed;
that would cause the update method to be invoked for
the controller and the view if they have registered themselves with the
model using addObserver.
Grading
- 70% correct execution
- 20% design (model/view/controller separation, HCI principles)
- 10% comments and style
Submissions
Submit through e-mail the source code (.java files) for any class you
created.
JAR or ZIP archives are preferred (but not required).