|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdbrown.Hangman
public class Hangman
The main Hangman game class. It provides the attributes and methods for playing the game.
Nested Class Summary | |
---|---|
static class |
Hangman.GameStateFlags
The possible states of the game. |
Field Summary | |
---|---|
static char |
FIRST_LETTER
The end points of the valid phrase letters. |
static java.lang.String |
FORFEIT
|
private Hangman.GameStateFlags |
gameState
Contains the current state of the game. |
static java.lang.String |
GUESS
|
private boolean[] |
guessedLetters
Letters of the alphabet may be guessed or not yet guessed and their states are contained in this array. |
private java.lang.StringBuffer |
guessedPhrase
The phrase guessed so far is stored in a mutable structure. |
static char |
LAST_LETTER
|
static java.lang.String |
LOSE
|
static int |
MAX_WRONG_GUESSES
The maximum number of allowed wrong guesses. |
static java.lang.String |
NEW_GAME
|
static int |
NUM_LETTERS
The number of letters in the alphabet. |
static java.util.regex.Pattern |
pattern
Regular expressions are used to convert the phrase to a string of asterisks. |
private java.beans.PropertyChangeSupport |
pcs
Allows views to listen to generic or named changes in the hangman game. |
private java.lang.String |
phrase
The phrase to be guessed. |
private PhraseList |
phrases
The list of phrases to be guessed. |
static java.lang.String |
WIN
|
private int |
wrongGuesses
The number of wrong guesses made so far. |
Constructor Summary | |
---|---|
Hangman(java.lang.String filename)
|
Method Summary | |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Allows for generic listeners. |
void |
addPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Allows for named listeners. |
void |
forfeit()
Forfeits the game and exposes the phrase to be guessed. |
java.lang.String |
getGuessedPhrase()
|
int |
getWrongGuesses()
|
void |
guess(char letter)
Accepts a letter guessed by the player and checks to see whether it has already been guessed and whether is is part of the phrase to be guessed. |
private void |
initGuessedLetters(boolean state)
Initializes the list of guessed letters to not guessed so far. |
boolean |
isPlaying()
|
boolean |
lost()
|
void |
newGame()
Initializes a new game by selecting a phrase from the file of phrases in the phraseList object. |
void |
newGame(java.lang.String newPhrase)
Initializes a new game with a given phrase. |
boolean |
wasGuessed(char letter)
Determines whether a character guessed by the player has already been guessed or not. |
boolean |
won()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String FORFEIT
public static final java.lang.String NEW_GAME
public static final java.lang.String WIN
public static final java.lang.String LOSE
public static final java.lang.String GUESS
public static final char FIRST_LETTER
public static final char LAST_LETTER
public static final int MAX_WRONG_GUESSES
public static final int NUM_LETTERS
public static final java.util.regex.Pattern pattern
private Hangman.GameStateFlags gameState
private final boolean[] guessedLetters
private java.lang.StringBuffer guessedPhrase
private java.lang.String phrase
private PhraseList phrases
private int wrongGuesses
private final java.beans.PropertyChangeSupport pcs
Constructor Detail |
---|
public Hangman(java.lang.String filename) throws java.io.FileNotFoundException
filename
- - the name of the file to open that contains the phrases to be
guessed
java.io.FileNotFoundException
Method Detail |
---|
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- public void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
propertyName
- listener
- public void forfeit()
public java.lang.String getGuessedPhrase()
public int getWrongGuesses()
public void guess(char letter) throws java.lang.Exception
letter
- - the letter guessed by the player
java.lang.Exception
- - when the letter has already been guessedpublic boolean isPlaying()
public boolean lost()
public void newGame()
phraseList
object.
public void newGame(java.lang.String newPhrase)
newPhrase
- the phrase for the player to guess.public boolean wasGuessed(char letter) throws java.lang.IllegalArgumentException
letter
- the letter the player has guessed as being part of the current
phrase
java.lang.IllegalArgumentException
- when the character passed as a parameter is not part of the
alphabetpublic boolean won()
private void initGuessedLetters(boolean state)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |