CSCI 162 - Lab 1: Maze

Objectives

Due: Wednesday January 30th at 11:59pm

The objectives of this lab are to reinforce and help teach:

Overview

In this lab you will finish the development of a program that reads a maze from a file into a two-dimensional character array. The maze is defined by a 30 x 12 grid with each square of the maze holding one of the following characters:

        # - A maze wall

        <space> - The space character indicating nothing at
                  in that space thus the person may walk there.

        ^ > v < - The person, represented by one of these characters
                  indicating the person is facing north, east, south,
                  or west, respectively.

        X - This marks the spot of the exit of the maze.

The purpose of this program is to read the maze and then prompt for input from the user in the form of a single character command that when processed moves the person through the maze until they make it to the exit. When the user makes it to the exit the program terminates with a congratulations message.

The single-character inputs that the program accepts to move the person through the maze are:

        L - Rotate the person left 90 degrees

        R - Rotate the person right 90 degrees

        F - Move the person one space forward

        B - Move the person once space backwards

        Q - Quit (exits the program)

If you attempt to move the person forward or backward into a space occupied by a wall the program should warn the user and keep the person's position unchanged.

The maze will be such that you cannot move outside of the maze boundaries. In other words, there will be maze walls around the outside perimeter of the maze.

The maze file is found in the current directory and is named "maze.txt", and it has 12 lines in the file with each line having 30 characters that describe what is contained in each square of that row of the maze.

Instructions

Following are the instructions and you should follow them carefully:

  1. Using Eclipse create a new Java Project and name it: Maze
  2. As with all your labs, add a class of the same name, Maze, and include in that class a main method.
  3. You DO NOT have to write the entire program. Instead, most of the program has been given to you here and you need only complete it, looking for incomplete methods with "To-Do:" comments within. Cut and paste the contents of the program into the Maze.java file you have created and finish the incomplete methods one at a time, testing as you go.
  4. Only make changes to incomplete methods with the "To-Do:" comment includes. Other methods and the rest of the program should be used as-is.
  5. Your program should be properly commented, indented and use whitespace appropriately.
  6. Your program should output according to the "Output Specification" below.
  7. Your program should loop and ask for a command again if the user enters an unknown command.
  8. All commands are single-character, upper case (you may want to put on the capslock when testing).
  9. When processing the user supplied command, your program should rotate the person, move the person or quit the program, depending on the command. If the command would move the person into a wall then a message indicating such such be output (see the "Output Specification" for the text to display in that situation.)
  10. If you wish, you can make your program "animated" by clearing the screen before redrawing the maze and its contents, and then sleep briefly after displaying the contents. This works especially well when redirecting input from the command line in order to watch your program in action. Helpful methods for clearing the screen and sleeping are here.. These methods are included in the partial program supplied.
  11. Your program should loop indifinitely prompting for commands and processing them until the person makes it out of the maze (moves to the space marked X) or the user enters Q to quit.
  12. Your program must work with redirected input as well as input from the user. Test both.
  13. Note that your program will be graded according to the following rubric.
  14. When the lab is complete and working submit it as Maze

Input Specification

Your program must read from the maze.txt file in the current directory with that file containing 12 lines of 30 characters each as described in the "Overview" section above.

The maze.txt file that your program will be automatically run against when graded contains the following characters:


##############################
#>  ###############       ####
### ###             ##### ####
### ### ########### ##### ####
### ### ###   #####     #   ##
###     ##### ##### ####### ##
##### ####### ##### ####### ##
##### ####### ##### ####### ##
#####                 ##### ##
########## ##########    ## ##
##########           #####   X
##############################

As you develop and test your program, you can use any maze.txt file you wish as long as it adheres to the following rules

  1. Contains 12 lines of 30 characters in each line.
  2. Has only one person (^, >, v, <) character.
  3. Has only one exit (X) character.
  4. Is solvable in that the person can move from starting square to exit along blank spaces.
  5. Has a perimeter wall (# characters) along the outside edges (top, bottom, left, right) so that the person cannot move off the edge (making your program logic a little easier).

In addition, your program will prompt the user to enter a single character command (L, R, F, B or Q for Left-rotate, Right-rotate, Forward, Back and Quit, respectively) to control the person in the maze or to quit the program. Your program will be run automatically, with a commands.txt input file redirected as user input, with the contents of said file the commands required for moving the person from the starting position to the exit square of the maze defined above.

Remember, the syntax for running your program with redirected input is:


java Maze < commands.txt

Lastly, the contents of commands.txt that solve the maze provided are as follows:


F
F
R
F
F
F
F
L
F
F
F
F
L
F
F
F
R
F
F
F
F
F
F
F
F
F
F
F
F
L
F
F
R
F
F
F
F
F
F
R
F
F
F
L
F
F
R
F
F
F
F
F
F
L
F
F

Output Specification

Following is the desired output format:

 
##############################
#>  ###############       ####
### ###             ##### ####
### ### ########### ##### ####
### ### ###   #####     #   ## 
###     ##### ##### ####### ##
##### ####### ##### ####### ##
##### ####### ##### ####### ##
#####                 ##### ##
########## ##########    ## ##
##########           #####   X
##############################

Next command (L, R, F, B or Q): F

##############################
# > ###############       ####
### ###             ##### ####
### ### ########### ##### ####
### ### ###   #####     #   ## 
###     ##### ##### ####### ##
##### ####### ##### ####### ##
##### ####### ##### ####### ##
#####                 ##### ##
########## ##########    ## ##
##########           #####   X
##############################

Next command (L, R, F, B or Q): F

##############################
#  >###############       ####
### ###             ##### ####
### ### ########### ##### ####
### ### ###   #####     #   ## 
###     ##### ##### ####### ##
##### ####### ##### ####### ##
##### ####### ##### ####### ##
#####                 ##### ##
########## ##########    ## ##
##########           #####   X
##############################

Next command (L, R, F, B or Q): F

You are blocked by a wall in that direction.

##############################
#  >###############       ####
### ###             ##### ####
### ### ########### ##### ####
### ### ###   #####     #   ## 
###     ##### ##### ####### ##
##### ####### ##### ####### ##
##### ####### ##### ####### ##
#####                 ##### ##
########## ##########    ## ##
##########           #####   X
##############################

Next command (L, R, F, B or Q): R

##############################
#  v###############       ####
### ###             ##### ####
### ### ########### ##### ####
### ### ###   #####     #   ## 
###     ##### ##### ####### ##
##### ####### ##### ####### ##
##### ####### ##### ####### ##
#####                 ##### ##
########## ##########    ## ##
##########           #####   X
##############################

Next command (L, R, F, B or Q): F

##############################
#   ###############       ####
###v###             ##### ####
### ### ########### ##### ####
### ### ###   #####     #   ## 
###     ##### ##### ####### ##
##### ####### ##### ####### ##
##### ####### ##### ####### ##
#####                 ##### ##
########## ##########    ## ##
##########           #####   X
##############################

Next command (L, R, F, B or Q):          
    

. . .


##############################
#   ###############       ####
### ###             ##### ####
### ### ########### ##### ####
### ### ###   #####     #   ## 
###     ##### ##### ####### ##
##### ####### ##### ####### ##
##### ####### ##### ####### ##
#####                 ##### ##
########## ##########    ## ##
##########           ##### > X
##############################

Next command (L, R, F, B or Q): F

##############################
#   ###############       ####
### ###             ##### ####
### ### ########### ##### ####
### ### ###   #####     #   ## 
###     ##### ##### ####### ##
##### ####### ##### ####### ##
##### ####### ##### ####### ##
#####                 ##### ##
########## ##########    ## ##
##########           #####  >X
##############################

Next command (L, R, F, B or Q): F

##############################
#   ###############       ####
### ###             ##### ####
### ### ########### ##### ####
### ### ###   #####     #   ## 
###     ##### ##### ####### ##
##### ####### ##### ####### ##
##### ####### ##### ####### ##
#####                 ##### ##
########## ##########    ## ##
##########           #####   >
##############################

Way to go! You made it out of the maze!    
    

Deadline

This lab must be submitted to the instructor by Wednesday, January 30th.