org.apache.wicket.examples.hangman
Class Game

java.lang.Object
  extended by org.apache.wicket.examples.hangman.Game
All Implemented Interfaces:
java.io.Serializable, IClusterable

public class Game
extends java.lang.Object
implements IClusterable

Implementation of the actual hangman game model. The model holds the word generator, the current word, retries remaining and the correctLetters that have been guessed. It also answers questions such as whether all retries have been used.

Author:
Chris Turner, Jonathan Locke
See Also:
Serialized Form

Constructor Summary
Game()
           
 
Method Summary
 int getGuessesRemaining()
          Return the number of guesses remaining.
 java.util.List getLetters()
           
 Word getWord()
          Get the current word that is being guessed or has been guessed.
 boolean guess(Letter letter)
          Guess the given letter for the current word.
 boolean isLost()
          Check whether the user has used up all of their guesses.
 boolean isWon()
          Check whether the user has successfully guessed all of the correctLetters in the word.
 void newGame()
          Play another game with same settings
 void newGame(int guessesAllowed, WordGenerator wordGenerator)
          Initialise the hangman read for a new game.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Game

public Game()
Method Detail

getGuessesRemaining

public int getGuessesRemaining()
Return the number of guesses remaining.

Returns:
The number of guesses

getLetters

public java.util.List getLetters()
Returns:
The letters in the game

getWord

public Word getWord()
Get the current word that is being guessed or has been guessed.

Returns:
The current word

guess

public boolean guess(Letter letter)
Guess the given letter for the current word. If the letter matches then the word is updated otherwise the guesses remaining counter is reduced. The letter guessed is also recorded.

Parameters:
letter - The letter being guessed
Returns:
True if guess was correct

isLost

public boolean isLost()
Check whether the user has used up all of their guesses.

Returns:
Whether all of the user's guesses have been used

isWon

public boolean isWon()
Check whether the user has successfully guessed all of the correctLetters in the word.

Returns:
Whether all of the correctLetters have been guessed or not

newGame

public void newGame()
Play another game with same settings


newGame

public void newGame(int guessesAllowed,
                    WordGenerator wordGenerator)
Initialise the hangman read for a new game.

Parameters:
guessesAllowed - Number of guesses allowed
wordGenerator - The word generator


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.