|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IHangman
Objects implementing IHangman
are used to play the game of
Hangman.
Please see the package description for a more in-depth discussion of using this class.
Field Summary | |
---|---|
static char |
FIRST_LETTER
The first letter that can be guessed. |
static char |
LAST_LETTER
The last letter that can be guessed. |
static int |
MAX_WRONG_GUESSES
The number of incorrect guesses the player is allowed to have. |
static int |
NUM_LETTERS
The number of letters that can be guessed. |
Method Summary | |
---|---|
void |
addView(IView aView)
Add a view (graphical user interface) to the game. |
void |
forfeit()
The user has given up and forfeited the game. |
String |
getGuessedPhrase()
Return the phrase that has been guessed so far. |
boolean |
lost()
Has the player lost the game (had more than MAX_WRONG_GUESSES or has forfeit)? |
void |
newGame()
Begin a new game with a randomly chosen phrase for the player to guess. |
void |
newGame(String thePhrase)
Begin a new game with the player trying to guess the given phrase. |
int |
numWrongGuesses()
How many wrong guesses has the player used? |
void |
processGuess(char theLetter)
Process a letter the player has guessed. |
boolean |
wasGuessed(char aLetter)
Has the given letter been guessed before? |
boolean |
won()
Has the player won the game by correctly guessing all the letters in the phrase? |
Field Detail |
---|
static final char FIRST_LETTER
static final char LAST_LETTER
static final int NUM_LETTERS
static final int MAX_WRONG_GUESSES
Method Detail |
---|
void newGame(String thePhrase)
thePhrase
- the phrase to guessvoid newGame()
int numWrongGuesses()
boolean lost()
boolean won()
void processGuess(char theLetter)
This method is called by the user interface when the user clicks
on a letter to guess it. Assuming wasGuessed(theLetter)
,
won()
, and lost()
all
return false
before this method is called and
numWrongGuesses
returns n, then after this
method is called the following should be true:
wasGuessed(theLetter)
returns true
.theLetter
, then getGuessedPhrase
will have theLetter
included in the string it returns
and numWrongGuesses()
will return n.theLetter
,
numWrongGuesses()
will return n+1.
theLetter
- the letter guessedboolean wasGuessed(char aLetter)
aLetter
-
void forfeit()
String getGuessedPhrase()
Examples:
Phrase Letters guessed Return WAIT A MINUTE none . . . . . . . . . . . WAIT A MINUTE A I . A I . A . I . . . . WAIT A MINUTE lost game W A I T A M I N U T E
void addView(IView aView)
updateView
method must be called each time the game's state changes.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |