Homework 3: Building Mazes, part 1
Maze Creation
For the purposes of this assignment, we will define a maze
to have the following characteristics:
- It is a rectangular grid of cells.
- Each cell can either be filled or empty.
- One cell, on an edge of the grid, is designated the entrance.
It must be empty. Another cell on the edge is the exit, and it too
must be empty.
Your task is as follows:
- Design a class to represent a maze as described above.
- Implement a method to generate a randomized,
perfect maze.
- A perfect maze cannot contain any loops. Furthermore,
it should have as many open squares as possible given this constraint.
- The randomization should ensure that each call creates a distinct maze.
- Ensure that maze objects can be loaded and saved to disk.
- Design a GUI (using Swing) to create mazes. Ensure a facility
for loading and saving mazes. You may otherwise design the GUI
however you deem appropriate.
Maze Navigation
Add the following features to your user interface:
- Create a way for the user to navigate an explorer through
the maze. The explorer should not be any larger than a grid cell. A simple
square of a different color than the grid cell will suffice.
- The explorer can move from its current square to any adjacent square
that does not contain a wall. For the purposes of this program, "adjacent"
squares cannot be diagonal.
- The explorer should start at the maze entrance.
- Allow the user to select whether the explorer leaves a visible trail as
it moves.
- Give the user a "reset" option to erase the path and return the explorer
to the entrance.
- Display an appropriate congratulatory message when the explorer reaches
the exit.
As part of implementing the above features, create the Path class.
Objects of the Path class are nodes in a singly-linked list.
Each Path object should contain:
- A cell location in the maze
- A reference to the
Path that represents the path from the
entrance up to the current Path object. At the entrance, this
reference should be null.
- The total number of steps from the entrance to the end of the
Path
- Any methods as you see fit. Do not add any other data members.
In particular, you must implement this as a singly-linked
list, not as a doubly-linked list.