com.blackledge.david.game.crossword
Class CrosswordPuzzle

java.lang.Object
  extended by com.blackledge.david.game.crossword.CrosswordPuzzle

public class CrosswordPuzzle
extends Object

Embodiment of a Crossword puzzle. Needs to be populated, but knows how to validate that the population is correct.

Version:
$Revision: 1.3 $

Nested Class Summary
static class CrosswordPuzzle.Puzzleword
          Embodiment of an entry in a Crossword Puzzle - word, position, direction, and clue.
 
Field Summary
static char BLACKED_OUT
           
static char BLANK
           
 
Constructor Summary
CrosswordPuzzle(int width, int height)
          Create a new Crossword Puzzle core of the given width and height.
 
Method Summary
 void addCrossword(CrosswordPuzzle.Puzzleword crossword)
          Add an entry to the puzzle.
 boolean checkWin()
          See if the current state of the puzzle matches the solution.
 int getHeight()
           
 CrosswordPuzzle.Puzzleword getPuzzleword(int x, int y, boolean horizontal)
           
 char getState(int x, int y)
          Gets the current character entered at the position.
 int getWidth()
           
 boolean isValidated()
           
 void setGuess(int x, int y, String letter)
          Sets the letter guessed for a particular position.
 String toString()
          Prints out the solution and clues.
 void validatePuzzle()
          Ensure validity and assign clue numbers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BLACKED_OUT

public static final char BLACKED_OUT
See Also:
Constant Field Values

BLANK

public static final char BLANK
See Also:
Constant Field Values
Constructor Detail

CrosswordPuzzle

public CrosswordPuzzle(int width,
                       int height)
Create a new Crossword Puzzle core of the given width and height.

Parameters:
width -
height -
Method Detail

setGuess

public void setGuess(int x,
                     int y,
                     String letter)
Sets the letter guessed for a particular position. Does nothing of the puzzle is not validated, the letter is null/empty/invalid, or the position is a blacked-out square.

Parameters:
x - (left-to-right position)
y - (top-to-bottom position)
letter -

getState

public char getState(int x,
                     int y)
Gets the current character entered at the position.

Parameters:
x - (left-to-right position)
y - (top-to-bottom position)
Returns:
a space, a previously guessed letter, or # to represent a blacked-out space.

getPuzzleword

public CrosswordPuzzle.Puzzleword getPuzzleword(int x,
                                                int y,
                                                boolean horizontal)

getWidth

public int getWidth()

getHeight

public int getHeight()

isValidated

public boolean isValidated()

checkWin

public boolean checkWin()
See if the current state of the puzzle matches the solution. Does nothing if the puzzle is not validated.

Returns:
true if the game has been won.

validatePuzzle

public void validatePuzzle()
Ensure validity and assign clue numbers. Must be run successfully before puzzle is played.

Throws:
IllegalArgumentException - if any tests fail.

addCrossword

public void addCrossword(CrosswordPuzzle.Puzzleword crossword)
Add an entry to the puzzle. Invalidates the puzzle.

Parameters:
crossword -

toString

public String toString()
Prints out the solution and clues.

Overrides:
toString in class Object