|
|||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
IHangman
interface.
See:
Description
Interface Summary | |
---|---|
IHangman | Objects implementing IHangman are used to play the game of
Hangman. |
Class Summary | |
---|---|
GallowsView | Draw the gallows for the game of Hangman, showing how many wrong guesses the player has had and a message if the game is over. |
HangmanGUI | A graphical user interface for the game of Hangman. |
SampleHangman | A sample implementation of IHangman used to demonstrate the
operation of the game of Hangman. |
Provides a graphical user interface (GUI) for a game of Hangman that
uses an instance of a student-written class implementing the IHangman
interface. The GUI appears like
this:
The object of the game is to guess the phrase displayed at the bottom of the user interface. It displays a dot for each letter in the phrase. Guesses are made by clicking on one of the letters on the right side. When a letter is clicked, one of two things happen:
The player loses by using too many guesses (the body on the gallows has a head, body, two arms and two legs), or the player forfeits. The player wins by guessing all letters in the phrase before the body is complete.
A typical main
method to run this program would be
import becker.xtras.hangman.*; public class DemoHangman extends Object { public static void main(String[] args) { IHangman model = new Hangman(); HangmanGUI view = new HangmanGUI(model); } }
where Hangman
is written by the student and implements the IHangman
interface. The library includes an
implementation of IHangman
named SampleHangman
.
Substituting it for Hangman
in the above code will yield a working demonstration program.
This program uses the Model-View-Controller pattern. The class implementing IHangman
is the model. It must arrange to update the views each time the model's state (that is, one of
its instance variables) changes. This can be done easily with code such as the following:
import becker.util.IView; import becker.util.ViewList; public class Hangman implements IHangman { private ViewList views = new ViewList(); ... public void stateChangingMethod() { ... this.views.updateViews(); } public void addView(IView aView) { this.views.addView(aView); } }
|
|||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |