Class Maze

java.lang.Object
  extended by Maze

public class Maze
extends java.lang.Object

The Maze Java application illustrates the use of the traverseMaze method that uses recursion to guide a user into a maze and back out again.

Java Source Code for this class:
http://www.cs.colorado.edu/~main/applications/Maze.java


Constructor Summary
Maze()
           
 
Method Summary
static boolean deadend()
          Determines whether the person traversing the maze has reached a dead end.
static boolean inquire(java.lang.String query)
          Asks a yes/no question and reads the answer.
static void main(java.lang.String[] args)
          The main method activates traverseMaze and prints a message indicating whether the tapestry was found.
static boolean traverseMaze()
          Provides interactive help to guide a user through a maze and back out.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Maze

public Maze()
Method Detail

main

public static void main(java.lang.String[] args)
The main method activates traverseMaze and prints a message indicating whether the tapestry was found. The String argument (args) is not used in this implementation.


deadend

public static boolean deadend()
Determines whether the person traversing the maze has reached a dead end.

Parameters:
- - none
Postcondition:
The return value is true if the direction directly in front of the user is a dead end (that is, a direction that cannot contain the tapestry).

inquire

public static boolean inquire(java.lang.String query)
Asks a yes/no question and reads the answer.

Parameters:
query - a question to ask
Postcondition:
The query has been printed to System.out, and a one-character response read from System.in (skipping any whitespace characters. The method returns true if the user’s response was ‘Y’ or ‘y’, and returns false if the user’s response was ‘N’ or ‘n’. (If the response is some other character, then the query is repeated and a new answer is read.)

traverseMaze

public static boolean traverseMaze()
Provides interactive help to guide a user through a maze and back out.

Parameters:
- - none
Precondition:
The user of the program is facing an unblocked spot in the maze, and this spot has not previously been visited by the user.
Postcondition:
The method has asked a series of queries, and provided various directions to the user. The queries and directions have led the user through the maze and back to the exact same position where the user started. If there was a magic tapestry that could be reached in the maze, then the user has picked up this tapestry and the method returns true; otherwise the method returns false.