public class Maze
extends java.lang.Object
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 and Description |
---|
Maze() |
Modifier and Type | Method and Description |
---|---|
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.
|
public static void main(java.lang.String[] args)
traverseMaze
and prints a message
indicating whether the tapestry was found.args
- not used in this implementationpublic static boolean deadend()
true
if the direction directly in front of the user
is a dead end (that is, a direction that cannot contain the tapestry).public static boolean inquire(java.lang.String query)
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.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.)public static boolean traverseMaze()
true
; otherwise the method returns
false
.