Class Game
- java.lang.Object
-
- org.apache.wicket.examples.hangman.Game
-
- All Implemented Interfaces:
Serializable,IClusterable
public class Game extends 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
Constructors Constructor Description Game()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetGuessesRemaining()Return the number of guesses remaining.List<Letter>getLetters()WordgetWord()Get the current word that is being guessed or has been guessed.booleanguess(Letter letter)Guess the given letter for the current word.booleanisLost()Check whether the user has used up all of their guesses.booleanisWon()Check whether the user has successfully guessed all of the correctLetters in the word.voidnewGame()Play another game with same settingsvoidnewGame(int guessesAllowed, WordGenerator wordGenerator)Initialise the hangman read for a new game.
-
-
-
Method Detail
-
getGuessesRemaining
public int getGuessesRemaining()
Return the number of guesses remaining.- Returns:
- The number of guesses
-
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 allowedwordGenerator- The word generator
-
-