|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectMazeCell
public class MazeCell
A MazeCell represents a single cell in a Maze
. The class
includes a number of methods to get information about the cell's location,
neighbors, visitation state and so on. MazeRunners may also store arbitrary
"extra info" with each MazeCell using the get/setExtraInfo methods, which may
be useful for keeping track of paths to the donut.
Nested Class Summary | |
---|---|
static class |
MazeCell.CellState
CellState is an enumeration that represents the state of a given cell in the current search. |
Field Summary | |
---|---|
private int |
col
The column this cell is on. |
private java.lang.Object |
info
A piece of state that may be used to hold information about the current search, if useful. |
private boolean |
isDonutCell
Whether or not this cell is the donut cell. |
private boolean |
isStartCell
Whether or not this cell is the start cell. |
private java.util.ArrayList<MazeChangeListener> |
mazeChangeListeners
A list of the MazeChangeListener that will be notified on a
visitation state change. |
private int |
numWalls
The number of walls this cell has. |
private int |
row
The row this cell is on. |
private MazeCell.CellState |
state
The current visitation state of this cell. |
private boolean[] |
walls
An array to keep track of which walls exist on this cell. |
Constructor Summary | |
---|---|
MazeCell(int cellRow,
int cellCol,
boolean isStart,
boolean isDonut,
boolean northWall,
boolean eastWall,
boolean southWall,
boolean westWall)
Creates a new MazeCell with the given parameters. |
Method Summary | |
---|---|
void |
addMazeChangeListener(MazeChangeListener listener)
Adds a new MazeChangeListener to listen to changes in this cell. |
protected void |
broadcastChange()
Notifies all MazeChangeListener that have been previously
registered via addMazeChangeListener of a change in this
cell's visitation state. |
int |
getCol()
Returns the column this cell is in. |
java.lang.Object |
getExtraInfo()
Gets the object that was previously stored in this cell with setExtraInfo(Object newInfo) . |
int |
getMaxNumWalls()
Returns the total possible number of walls this cell has. |
int |
getNumWalls()
Returns the number of walls that this cell has |
int |
getRow()
Returns the row this cell is in. |
MazeCell.CellState |
getState()
Returns the current visitation state of the Cell. |
boolean |
isDonut()
Returns true if this cell is a donut cell. |
boolean |
isStart()
Returns true if this cell is a start cell. |
boolean |
isWall(Direction d)
Returns true if there is a wall in the direction
d . |
void |
setExtraInfo(java.lang.Object newInfo)
Stores an object in this cell that can be later retrieved with a call to getExtraInfo() . |
void |
setState(MazeCell.CellState s)
Sets the current visitation state of the Cell. |
java.lang.String |
toString()
A defined toString function that will output a nicely formated string that specifies the location (row,col) of this cell. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private java.lang.Object info
private MazeCell.CellState state
private java.util.ArrayList<MazeChangeListener> mazeChangeListeners
MazeChangeListener
that will be notified on a
visitation state change.
private boolean[] walls
private int numWalls
private boolean isStartCell
private boolean isDonutCell
private int row
private int col
Constructor Detail |
---|
public MazeCell(int cellRow, int cellCol, boolean isStart, boolean isDonut, boolean northWall, boolean eastWall, boolean southWall, boolean westWall)
cellRow
- The row this cell is on.cellCol
- The column this cell is on.isStart
- true
if this cell is the start cell.isDonut
- true
if this cell is the donut cell.northWall
- true
if this cell has a wall to the North.eastWall
- true
if this cell has a wall to the East.southWall
- true
if this cell has a wall to the South.westWall
- true
if this cell has a wall to the West.Method Detail |
---|
public MazeCell.CellState getState()
CellState
.
public void setState(MazeCell.CellState s)
CellState
.
s
- Sets the visitation state to the state in s
public java.lang.Object getExtraInfo()
setExtraInfo(Object newInfo)
. This can be used to implement
a form of closures on operations with this cell.
setExtraInfo(Object newInfo)
. If there was no
previous call to setExtraInfo
, null
is returned.public void setExtraInfo(java.lang.Object newInfo)
getExtraInfo()
. This can be used to implement a form of
closures on operations with this cell.
newInfo
- The object to store in this cell. This object may later be
retrieved with a call to getExtraInfo()
.
newInfo
may be null
. This will remove
any previously stored object from this cell.public void addMazeChangeListener(MazeChangeListener listener)
listener
- Adds listener
to the list of
MazeChangeListener
that will be notified when the
visitation state of this cell is changed via
setState(CellState s)
protected void broadcastChange()
MazeChangeListener
that have been previously
registered via addMazeChangeListener
of a change in this
cell's visitation state.
public boolean isStart()
true
if this cell is a start cell.
false
otherwise.public boolean isDonut()
true
if this cell is a donut cell.
false
otherwise.public java.lang.String toString()
toString
in class java.lang.Object
public boolean isWall(Direction d)
true
if there is a wall in the direction
d
.
d
- The direction in which to check for a wall.
true
if there is a wall in the direction
d
.public int getNumWalls()
public int getMaxNumWalls()
public int getRow()
public int getCol()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |