Class Maze

java.lang.Object
  extended by Maze

public class Maze
extends java.lang.Object

The Maze class represents a maze constructed as a rectangle of square cells (each of which is represented by a MazeCell class). We create Mazes using the nested class MazeFactory and solve Mazes using instances of the MazeRunner abstract class.

Author:
Albert J. Wong (awong@cs)

Nested Class Summary
static class Maze.MazeFactory
          MazeFactory is a Factory Design Pattern that generates a new Maze.
private  class Maze.MazeIterator
          An iterator class that iterates over all the cells in a Maze.
private  class Maze.NeighborIterator
          An iterator class that iterates over all neighbors that can be reached from the cell the iterator was created for.
 
Field Summary
private  MazeCell[][] cells
          A 2-dimensional array that holds/represents all the cells in this maze.
private  MazeCell donutCell
          The donut cell of this maze.
private  int height
          The height of the maze
private  java.util.ArrayList<MazeChangeListener> mazeChangeListeners
          A list of the MazeChangeListeners that will be notified on a visitation state change.
private  MazeCell startCell
          The start cell of this maze.
private  int width
          The width of the maze
 
Constructor Summary
private Maze()
          Create an incomplete Maze.
 
Method Summary
 void addMazeChangeListener(MazeChangeListener listener)
          Adds a new MazeChangeListener to listen to changes in this maze.
 MazeCell getCell(int row, int col)
          Returns the cell located at (row,col).
 java.util.Iterator<MazeCell> getCells()
          Returns an iterator over all cells in this maze.
 MazeCell getDonut()
          Return the maze cell that contains the donut.
 int getHeight()
          Get the height, in number of cells, of the maze.
 java.util.Iterator<MazeCell> getNeighbors(MazeCell cell)
          Returns an iterator over the neighbors of the given cell.
 MazeCell getStart()
          Return the maze's starting cell.
 int getWidth()
          Get the width, in number of cells, of the maze.
private  void setCell(int row, int col, MazeCell cell)
          Change the cell located at (row,col).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startCell

private MazeCell startCell
The start cell of this maze.


donutCell

private MazeCell donutCell
The donut cell of this maze.


cells

private MazeCell[][] cells
A 2-dimensional array that holds/represents all the cells in this maze.


width

private int width
The width of the maze


height

private int height
The height of the maze


mazeChangeListeners

private java.util.ArrayList<MazeChangeListener> mazeChangeListeners
A list of the MazeChangeListeners that will be notified on a visitation state change.

Constructor Detail

Maze

private Maze()
Create an incomplete Maze. This constructor is private because it should be called only by the MazeFactory class.

Method Detail

addMazeChangeListener

public void addMazeChangeListener(MazeChangeListener listener)
Adds a new MazeChangeListener to listen to changes in this maze.

Parameters:
listener - listener to add to the maze's set of change listeners

getStart

public MazeCell getStart()
Return the maze's starting cell.

Returns:
the start cell of this maze.

getDonut

public MazeCell getDonut()
Return the maze cell that contains the donut.

Returns:
the donut cell of this maze.

getCells

public java.util.Iterator<MazeCell> getCells()
Returns an iterator over all cells in this maze.

Returns:
an iterator over all cells in this maze.

getNeighbors

public java.util.Iterator<MazeCell> getNeighbors(MazeCell cell)
Returns an iterator over the neighbors of the given cell.

Parameters:
cell - the cell whose neighbors should be returned.
Returns:
an iterator over the given cell's neighbors.

getCell

public MazeCell getCell(int row,
                        int col)
Returns the cell located at (row,col).

Parameters:
row - The row of the cell to retrieve.
col - The column of the cell to retrieve.
Returns:
the cell located at (row,col).

setCell

private void setCell(int row,
                     int col,
                     MazeCell cell)
Change the cell located at (row,col).

Parameters:
row - The row of the cell to set.
col - The column of the cell to set.

getWidth

public int getWidth()
Get the width, in number of cells, of the maze.

Returns:
the width of the maze in number of cells.

getHeight

public int getHeight()
Get the height, in number of cells, of the maze.

Returns:
the height of the maze in number of cells.