becker.xtras.hangman
Interface IHangman

All Known Implementing Classes:
SampleHangman

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.

Author:
Byron Weber Becker

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

FIRST_LETTER

static final char FIRST_LETTER
The first letter that can be guessed.

See Also:
Constant Field Values

LAST_LETTER

static final char LAST_LETTER
The last letter that can be guessed.

See Also:
Constant Field Values

NUM_LETTERS

static final int NUM_LETTERS
The number of letters that can be guessed.

See Also:
Constant Field Values

MAX_WRONG_GUESSES

static final int MAX_WRONG_GUESSES
The number of incorrect guesses the player is allowed to have.

See Also:
Constant Field Values
Method Detail

newGame

void newGame(String thePhrase)
Begin a new game with the player trying to guess the given phrase.

Parameters:
thePhrase - the phrase to guess

newGame

void newGame()
Begin a new game with a randomly chosen phrase for the player to guess.


numWrongGuesses

int numWrongGuesses()
How many wrong guesses has the player used?

Returns:
the number of wrong guesses made

lost

boolean lost()
Has the player lost the game (had more than MAX_WRONG_GUESSES or has forfeit)?

Returns:
true if the player has lost; false otherwise

won

boolean won()
Has the player won the game by correctly guessing all the letters in the phrase?

Returns:
true if the player has won; false otherwise

processGuess

void processGuess(char theLetter)
Process a letter the player has guessed.

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:

Parameters:
theLetter - the letter guessed

wasGuessed

boolean wasGuessed(char aLetter)
Has the given letter been guessed before?

Parameters:
aLetter -
Returns:
true if the letter was already guessed; false otherwise

forfeit

void forfeit()
The user has given up and forfeited the game.


getGuessedPhrase

String getGuessedPhrase()
Return the phrase that has been guessed so far. If the player has already lost the game, return the phrase they were trying to guess.

Examples:

PhraseLetters guessedReturn
WAIT A MINUTEnone. . . .   .   . . . . . .
WAIT A MINUTEA I. A I .   A   . I . . . .
WAIT A MINUTElost gameW A I T   A   M I N U T E

Returns:
the guessed phrase

addView

void addView(IView aView)
Add a view (graphical user interface) to the game. The view's updateView method must be called each time the game's state changes.