Class HangmanGame

java.lang.Object
  extended by HangmanGame

public class HangmanGame
extends java.lang.Object

A program to play a game of Hangman.


Constructor Summary
HangmanGame()
          Creates a new HangmanGame object with a default wordList.
HangmanGame(java.lang.String onlyWord)
          Creates a new HangmanGame object, with the wordlist containing only the given word.
 
Method Summary
 java.lang.String arrayToString(char[] array)
          A helper method that returns a String representation of the given char[].
 boolean containsLetter(char guessedLetter)
          A helper method that checks if the word-to-guess contains the gussed letter
 char getGuess()
          A helper method that prompts the user to provide a guessed letter.
 int leftToGuess()
          A helper method which counts how many letters are left to guess
 boolean playAgain()
          A helper method that asks the user whether they want to play again.
 void playGame()
          A method that plays a complete game of Hangman.
 void replaceLetter(char guessedLetter)
          A helper method that replaces blank spots in the word-so-far with the guessedLetter
 void setupGame()
          A helper method which re-initializes variables for the start of a new game.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HangmanGame

public HangmanGame()
Creates a new HangmanGame object with a default wordList.


HangmanGame

public HangmanGame(java.lang.String onlyWord)
Creates a new HangmanGame object, with the wordlist containing only the given word. This enables testing of the game using a known word.

Parameters:
onlyWord - The single word in the wordlist, used for testing and debugging
Method Detail

arrayToString

public java.lang.String arrayToString(char[] array)
A helper method that returns a String representation of the given char[].

Parameters:
array - the char[] to convert to a String.
Returns:
A String displaying the current guess of the word. Has the form "g _ e _ _ ".

containsLetter

public boolean containsLetter(char guessedLetter)
A helper method that checks if the word-to-guess contains the gussed letter

Parameters:
guessedLetter - the letter that was guessed
Returns:
Whether or not the guessedLetter is in the word.

getGuess

public char getGuess()
A helper method that prompts the user to provide a guessed letter. This method converts any guesses into a single, lower-case character.

Returns:
a single, lower-case char that the player guessed

leftToGuess

public int leftToGuess()
A helper method which counts how many letters are left to guess

Returns:
The number of letters that have not been guessed.

playAgain

public boolean playAgain()
A helper method that asks the user whether they want to play again.

Returns:
Returns whether the user wants to play again or not.

playGame

public void playGame()
A method that plays a complete game of Hangman.


replaceLetter

public void replaceLetter(char guessedLetter)
A helper method that replaces blank spots in the word-so-far with the guessedLetter

Parameters:
guessedLetter - the letter that was guessed

setupGame

public void setupGame()
A helper method which re-initializes variables for the start of a new game. Resets the word to guess, the current letters guessed, the number of lives, etc.