Class Game

java.lang.Object
  extended by java.util.Observable
      extended by Game

public class Game
extends java.util.Observable

Game represents the Hangman game control logic. A Game manages the flow of the game and coordinates the operation of the game board and informs the user interface when it should be updated.


Field Summary
private  Board gameBoard
          the playing area
private  int guessCount
          The count of wrong guesses
static int kGuessLimit
          The limit on number of incorrect guesses allowed.
private  java.lang.String secret
          The hidden word
private  I_WordSource words
          the source of secret words.
 
Constructor Summary
Game(Board board, I_WordSource wordSource)
          Construct a Game.
 
Method Summary
 boolean gameOver()
          Determine if the game is over.
 Board getBoardCopy()
          Return a copy of the board.
 int getTurns()
          Accessor to turn count.
 boolean isLoser()
          Determine if the player lost the game (ran out of turns)
 boolean isWin()
          Determine if the player won the game.
 void newGame()
          Start a new round of hangman by obtaining a hidden word and giving it to the board.
 void processMove(char guess)
          Game logic for handling each user guess
 java.lang.String solution()
          Accessor to the hidden word.
 void start()
          Start this game.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gameBoard

private Board gameBoard
the playing area


words

private I_WordSource words
the source of secret words.


guessCount

private int guessCount
The count of wrong guesses


kGuessLimit

public static final int kGuessLimit
The limit on number of incorrect guesses allowed.

See Also:
Constant Field Values

secret

private java.lang.String secret
The hidden word

Constructor Detail

Game

public Game(Board board,
            I_WordSource wordSource)
Construct a Game.

Parameters:
board - is the board to be used in this game.
wordSource - is the source of secret words for the game.
Method Detail

getBoardCopy

public Board getBoardCopy()
Return a copy of the board.

Returns:
a copy of the board.

start

public void start()
Start this game.


newGame

public void newGame()
Start a new round of hangman by obtaining a hidden word and giving it to the board.

Postcondition:
guessCount = 0, secret = hidden word

isLoser

public boolean isLoser()
Determine if the player lost the game (ran out of turns)

Returns:
true if the number of turns exceeds the limit

getTurns

public int getTurns()
Accessor to turn count.

Returns:
int number of turns.

solution

public java.lang.String solution()
Accessor to the hidden word.

Returns:
String hidden word

processMove

public void processMove(char guess)
Game logic for handling each user guess

Parameters:
guess - the letter that was entered by the user.

gameOver

public boolean gameOver()
Determine if the game is over.

Returns:
true if the game is either won or lost.

isWin

public boolean isWin()
Determine if the player won the game.

Returns:
true if the player guessed the word.