maze.structure
Class Maze

java.lang.Object
  extended byjava.util.Observable
      extended bymaze.structure.Maze

public class Maze
extends java.util.Observable

Describes the maze as a grid of cells with a given geometry and filling algorithm. There are two principle interfaces to this class: construction of the maze (used by a filler), drawing the maze (used by a canvas).


Field Summary
protected  java.awt.Rectangle canvasRect
          The Rectangle in graphics coordinates in which to draw the Maze.
protected  java.util.Observer theCellObserver
          An Observer of the Maze who will redraw it as it changes.
protected  MazeCell[][] theCells
          The Cells of the Maze.
protected  MazeFiller theFillStrategy
          The MazeFiller algorithm used to fill the Maze.
 MazeGeometry theGeometry
          The underlying MazeGeometry of the Maze.
 
Constructor Summary
Maze(int h, int v)
          Constructs a new, empty Maze.
Maze(MazeGeometry g)
          Constructs a new, empty maze using the given MazeGeometry to specify both the geometry as well as the size of the Maze.
 
Method Summary
 void addCellObserver(java.util.Observer o)
          Sets an Observer for each Cell of the Maze.
 MazeCell at(Coordinate c)
          Returns the Cell at the given Coordinates.
 void clear()
          Sets all Cells to Empty.
 void draw(java.awt.Graphics g)
          Draws the Maze with the given Graphics context.
 void draw(java.awt.Graphics g, MazeCell cell)
          Draws the given Maze Cell with the given Graphics context.
 void fill()
          Fills the Maze.
 void makeCellWall(Coordinate c)
          Makes a CellWall instance at a given set of coordinates.
 void makeCellWall(Coordinate c, int d1)
          Makes a CellWall instance at a given set of coordinates.
 void makeCellWall(Coordinate c, int d1, int d2)
          Makes a CellWall instance at a given set of coordinates.
 void makeCellWall(Coordinate c, int d1, int d2, int d3)
          Makes a CellWall instance at a given set of coordinates.
 void makeCellWallExcept(Coordinate c, int d1, int d2)
          Makes a CellWall instance at a given set of coordinates.
 void makeCellWallExcept(Coordinate c, int d1, int d2, int d3)
          Makes a CellWall instance at a given set of coordinates.
 void setCellRect(java.awt.Rectangle r)
          Sets the graphics Rectangle for a given Cell.
 void setFiller(MazeFiller f)
          Sets the MazeFiller algorithm for this Maze.
 
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

theCells

protected MazeCell[][] theCells
The Cells of the Maze.


theGeometry

public MazeGeometry theGeometry
The underlying MazeGeometry of the Maze.


theFillStrategy

protected MazeFiller theFillStrategy
The MazeFiller algorithm used to fill the Maze.


theCellObserver

protected java.util.Observer theCellObserver
An Observer of the Maze who will redraw it as it changes.


canvasRect

protected java.awt.Rectangle canvasRect
The Rectangle in graphics coordinates in which to draw the Maze.

Constructor Detail

Maze

public Maze(int h,
            int v)
Constructs a new, empty Maze. This will create a default RectGeometry from the given size parameters.

Parameters:
h - int horizontal size of the Maze.
v - int vertical size of the Maze.

Maze

public Maze(MazeGeometry g)
Constructs a new, empty maze using the given MazeGeometry to specify both the geometry as well as the size of the Maze.

Parameters:
g - MazeGeometry for this Maze.
Method Detail

clear

public void clear()
Sets all Cells to Empty.


setFiller

public void setFiller(MazeFiller f)
Sets the MazeFiller algorithm for this Maze.

Parameters:
f - MazeFiller to use when filling this Maze.

addCellObserver

public void addCellObserver(java.util.Observer o)
Sets an Observer for each Cell of the Maze.

Parameters:
o - Observer for each Cell of the Maze.

setCellRect

public void setCellRect(java.awt.Rectangle r)
Sets the graphics Rectangle for a given Cell.

Parameters:
r - Rectangle with the extent of this Cell.

fill

public void fill()
Fills the Maze. This uses the given fill strategy object to update maze cells. This class notifies observers of the cell-by-cell changes. It also notifies them at the end of filling that the maze as a whole is changed.


draw

public void draw(java.awt.Graphics g)
Draws the Maze with the given Graphics context.

Parameters:
g - Graphics used to draw the Maze.

draw

public void draw(java.awt.Graphics g,
                 MazeCell cell)
Draws the given Maze Cell with the given Graphics context.

Parameters:
g - Graphics used to draw the Cell
cell - Cell to be drawn.

at

public MazeCell at(Coordinate c)
Returns the Cell at the given Coordinates.

Parameters:
c - Coordinates of a Cell.
Returns:
Cell at the given Coordinates.

makeCellWall

public void makeCellWall(Coordinate c)
Makes a CellWall instance at a given set of coordinates.

Parameters:
c - Coordinates for the new CellWall.

makeCellWall

public void makeCellWall(Coordinate c,
                         int d1)
Makes a CellWall instance at a given set of coordinates. Adds a Wall in the given direction.

Parameters:
c - Coordinates for the new CellWall.
d1 - int direction for a wall.

makeCellWall

public void makeCellWall(Coordinate c,
                         int d1,
                         int d2)
Makes a CellWall instance at a given set of coordinates. Adds two Walls in the given directions.

Parameters:
c - Coordinates for the new CellWall.
d1 - int direction for a wall.
d2 - int direction for a wall.

makeCellWall

public void makeCellWall(Coordinate c,
                         int d1,
                         int d2,
                         int d3)
Makes a CellWall instance at a given set of coordinates. Adds three Walls in the given directions.

Parameters:
c - Coordinates for the new CellWall.
d1 - int direction for a wall.
d2 - int direction for a wall.
d3 - int direction for a wall.

makeCellWallExcept

public void makeCellWallExcept(Coordinate c,
                               int d1,
                               int d2)
Makes a CellWall instance at a given set of coordinates. Adds Walls except in the given directions.

Parameters:
c - Coordinates for the new CellWall.
d1 - int direction for a wall.
d2 - int direction for a wall.

makeCellWallExcept

public void makeCellWallExcept(Coordinate c,
                               int d1,
                               int d2,
                               int d3)
Makes a CellWall instance at a given set of coordinates. Adds Walls except in the given directions.

Parameters:
c - Coordinates for the new CellWall.
d1 - int direction for a wall.
d2 - int direction for a wall.
d3 - int direction for a wall.