|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object smithers.logicpuzzles.Hanjie
public class Hanjie
Class to store a hanjie puzzle.
Constructor Summary | |
---|---|
Hanjie(int[][] rowClues,
int[][] columnClues)
Constructs a new black and white puzzle from a grid of clues. |
|
Hanjie(int[][] rowClues,
int[][] rowColours,
int[][] columnClues,
int[][] columnColours,
java.awt.Color[] colours)
Constructs a new colour puzzle from a grid of clues. |
|
Hanjie(int height,
int width)
Constructs a new black and white puzzle of the specified size. |
|
Hanjie(int height,
int width,
java.awt.Color[] colours)
Constructs a new colour puzzle of the specified size. |
Method Summary | |
---|---|
void |
addClue(boolean isRow,
int index,
int[] clue)
Adds a clue to a black and white puzzle. |
void |
addClue(boolean isRow,
int index,
int[] clue,
int[] colour)
Adds a clue to a colour puzzle. |
int |
getColourCount()
Gets the number of colours. |
java.awt.Color[] |
getColours()
Gets the colour array. |
int[] |
getColumnClue(int column)
Gets the clue for the specified column. |
int[] |
getColumnColour(int column)
Gets the colour information for the clue for the specified column. |
int |
getHeight()
Gets the height of the puzzle. |
int[] |
getRowClue(int row)
Gets the clue for the specified row. |
int[] |
getRowColour(int row)
Gets the colour information for the clue for the specified row. |
int |
getWidth()
Gets the width of the puzzle. |
boolean |
hasColour()
Gets whether or not this puzzle has colour. |
boolean |
isMutable()
Checks whether this puzzle can be modified. |
static Hanjie |
load(java.io.File file)
Loads a hanjie puzzle from a file. |
static void |
main(java.lang.String[] args)
|
Hanjie |
makeImmutableCopy()
Creates a copy of this puzzle which cannot be modified further. |
void |
save(java.io.File file)
Saves the puzzle to a file. |
java.lang.String |
toString()
Generates a String representing the puzzle's clues. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Hanjie(int height, int width)
height
- the height of the puzzlewidth
- the width of the puzzle
java.lang.IllegalArgumentException
- if the width or height are negativepublic Hanjie(int height, int width, java.awt.Color[] colours)
height
- the height of the puzzlewidth
- the width of the puzzlecolours
- the colours, where colours[0]
is the blank colour
java.lang.IllegalArgumentException
- if the width or height are negativepublic Hanjie(int[][] rowClues, int[][] columnClues)
int[]
for each row/column, containing the clue for that
row/column.
rowClues
- the clues for the rowscolumnClues
- the clues for the columnspublic Hanjie(int[][] rowClues, int[][] rowColours, int[][] columnClues, int[][] columnColours, java.awt.Color[] colours)
int[]
for each row/column, containing the clue
for that row/column.
rowClues
- the clues for the rowsrowColours
- the colours for the row cluescolumnClues
- the clues for the columscolumnColours
- the colours for the colum cluescolours
- the colours, where colours[0]
is the blank
colourMethod Detail |
---|
public static Hanjie load(java.io.File file) throws java.io.IOException
file
- the file to load from
java.io.IOException
- if one occurs
PuzzleFormatException
- if the file is not in the right formatsave(java.io.File)
public void save(java.io.File file) throws java.io.IOException
file
- the file to save to
java.io.IOException
- if one occursload(java.io.File)
public boolean isMutable()
Puzzle
isMutable
in interface Puzzle
true
iff this puzzle is mutablepublic Hanjie makeImmutableCopy()
Puzzle
Puzzle
is used to construct a State
or Solver
, the constructer should call this method to get an
immutable copy. Copies created by this method should return false
to Puzzle.isMutable()
and throw ImmutablePuzzleException
when a method attempts to modify them.
makeImmutableCopy
in interface Puzzle
public int getHeight()
public int getWidth()
public int[] getRowClue(int row)
row
- the row index (starting from 0)
row
th rowpublic int[] getRowColour(int row)
row
- the row index (starting from 0)
row
th rowpublic int[] getColumnClue(int column)
column
- the column index (starting from 0)
column
th columnpublic int[] getColumnColour(int column)
column
- the column index (starting from 0)
column
th columnpublic boolean hasColour()
true
iff this is a colour puzzlepublic int getColourCount()
public java.awt.Color[] getColours()
null
if this puzzle is black and whitepublic void addClue(boolean isRow, int index, int[] clue)
int[]
specifying the clue for an enitire row/column. To add a clue to a colour
puzzle, use addClue(boolean, int, int[], int[])
.
isRow
- true
if the clue is for a row, false
for a
columnindex
- the position of the clueclue
- the clue to addaddClue(boolean, int, int[], int[])
public void addClue(boolean isRow, int index, int[] clue, int[] colour)
int[]
s specifying
the clue for an enitire row/column. The clue
and colour
arguments should have the same length. To add a clue to a black and
white puzzle, use addClue(boolean, int, int[])
.
isRow
- true
if the clue is for a row, false
for a
columnindex
- the position of the clueclue
- the clue to addcolour
- the colours of the clueaddClue(boolean, int, int[])
public java.lang.String toString()
String
representing the puzzle's clues.
toString
in interface Puzzle
toString
in class java.lang.Object
String
representing the puzzlepublic static void main(java.lang.String[] args) throws java.io.IOException
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |