|
|||||||||
| Home >> All >> [ hangman1 overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
hangman1
Class Game

java.lang.Objecthangman1.Game
- public class Game
- extends java.lang.Object
Tracks the players progress through the game, including guessed letters and incorrect guesses remaining.
| Field Summary | |
private boolean[] |
_guessed
|
private int |
_incorrectGuessesLeft
|
private char[] |
_letters
|
private java.lang.String |
_targetWord
|
private boolean |
_win
|
| Constructor Summary | |
Game()
|
|
| Method Summary | |
boolean[] |
getGuessedLetters()
Returns an array of flags indicating which letters have already been guessed. |
int |
getIncorrectGuessesLeft()
Returns the number of incorrect guesses remaining. |
char[] |
getLetters()
Returns an array of letters that have been guessed by the player, with an underscore for each unguessed position. |
boolean |
isWin()
Returns true if the player has guessed all letters in the word. |
boolean |
makeGuess(char letter)
The player makes a guess. |
void |
start(java.lang.String word)
Initializes the Game with a new target word. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
_targetWord
private java.lang.String _targetWord
_incorrectGuessesLeft
private int _incorrectGuessesLeft
_letters
private char[] _letters
_guessed
private boolean[] _guessed
_win
private boolean _win
| Constructor Detail |
Game
public Game()
| Method Detail |
isWin
public boolean isWin()
- Returns true if the player has guessed all letters in the word.
getLetters
public char[] getLetters()
- Returns an array of letters that have been guessed by the player, with
an underscore for each unguessed position. Once the player loses,
this returns the array of actual letters in the target word.
The caller must not modify this array.
getIncorrectGuessesLeft
public int getIncorrectGuessesLeft()
- Returns the number of incorrect guesses remaining.
An incorrect guess when this is already zero results
in a loss.
getGuessedLetters
public boolean[] getGuessedLetters()
- Returns an array of flags indicating which letters have already been guessed.
There are 26 flags, one for each letter, starting with 'A' at index 0, up to 'Z' at
index 25.
The caller must not modify this array.
start
public void start(java.lang.String word)
- Initializes the Game with a new target word. This resets the
incorrectGuessesLeft count, and initializes the array of
letters and letters guessed.
makeGuess
public boolean makeGuess(char letter)
- The player makes a guess. If the letter has already been
guessed, then no change occurs. Otherwise, there's a check
to see if the guess fills in any positions in the target word.
This may result in a win. If the guess doesn't match any
letter of the word, then a failure occurs; when enough
failures occur, the game results in a loss.
|
|||||||||
| Home >> All >> [ hangman1 overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
hangman1.Game