Class Board

java.lang.Object
  extended by Board

public class Board
extends java.lang.Object

Board is the game board in a hangman game. Importantly the board consists of the hidden word, but it also keeps track of which letters have been correctly guessed by the player. Note: Board is not part of the visual display, rather it is the game information itself.


Field Summary
private  java.lang.String hiddenWord
          The hidden word the player tries to guess
private  int kMaxWordLength
           
private  java.lang.StringBuffer userWord
          The "user word" of letters the player has guessed correctly placed in their proper position in the word.
 
Constructor Summary
Board()
          Default constructor
Board(Board brd)
          Copy constructor returns a copy of the given board.
 
Method Summary
private  void addLetter(char goodLetter)
          Add a correctly guessed letter to user's word.
private  boolean contains(char guess)
          Determine if the guessed letter is part of the hidden word.
 java.lang.String getBoardDisplay()
          Format the current state of the board for display.
(package private)  java.lang.String getUserWord()
          Accessor to user word for testing
 boolean isWin()
          Determine if the player won (guessed all the letters in the hidden word).
 boolean makeMove(char guess)
          Process a user guess.
 void setHidden(java.lang.String word)
          Initialize the hidden word for a game and reset user's word.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hiddenWord

private java.lang.String hiddenWord
The hidden word the player tries to guess


kMaxWordLength

private final int kMaxWordLength
See Also:
Constant Field Values

userWord

private java.lang.StringBuffer userWord
The "user word" of letters the player has guessed correctly placed in their proper position in the word. Letters which have not yet been guessed are blank.

Constructor Detail

Board

public Board()
Default constructor


Board

public Board(Board brd)
Copy constructor returns a copy of the given board.

Parameters:
brd - a Board from which we are to construct a copy.
Method Detail

setHidden

public void setHidden(java.lang.String word)
Initialize the hidden word for a game and reset user's word.

Parameters:
word - the hidden word to be used for this game.

makeMove

public boolean makeMove(char guess)
Process a user guess. Determine if the guess is correct and if so, handle it.

Parameters:
guess - the letter the player guessed.
Returns:
true if guess was correct, false otherwise
Precondition:
'A' <= guess <= 'Z'

contains

private boolean contains(char guess)
Determine if the guessed letter is part of the hidden word.

Parameters:
guess - the player's guess
Returns:
true if hiddenWord contains guess, false otherwise.

addLetter

private void addLetter(char goodLetter)
Add a correctly guessed letter to user's word. That is, place the user's correct guess in its proper position in the user's word. If it occurs more than once, do ALL occurrences.

Parameters:
goodLetter - the player's guess.
Precondition:
goodLetter is in the hidden word.
Postcondition:
userWord is updated with letter in each correct position

isWin

public boolean isWin()
Determine if the player won (guessed all the letters in the hidden word).

Returns:
true if all letters are guessed.

getUserWord

java.lang.String getUserWord()
Accessor to user word for testing


getBoardDisplay

public java.lang.String getBoardDisplay()
Format the current state of the board for display.

Returns:
the user word as a formatted, displayable string.