Class 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 Detail

      • Game

        public Game()
    • Method Detail

      • getGuessesRemaining

        public int getGuessesRemaining()
        Return the number of guesses remaining.
        Returns:
        The number of guesses
      • getLetters

        public List<Letter> 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