CS 160, Summer 2016
Programming Assignment P5
Maze Program

Programming due Monday, July 4th at 6:00pm; late deadline at 11:59pm.


This lab has the goal of teaching you how to:
  1. Instantiate a Maze object and call its methods.
  2. See your code controlling a graphical user interface.
  3. Use control loops to manage movement in the Maze.

Description

For a visual aid, click here

This assignment features Chihiro from the Miyazaki film Spirited Away, one of the best animated films ever made. Chihiro is having trouble in the spirit world, and needs the help of Haku. While looking for Haku in the maze, Chihiro needs to stay away from the witch Yubaba. The goal of this program is to move Chihiro around the maze according to a precise set of rules. If you follow the rules, Chihiro will find Haku, and will never meet Yubaba. Note: You must follow the exact path we specify to receive full credit on this program, finding Haku is not enough!

Instructions

In Recitation 4 you should have started on P5.java. If not, follow the directions here. Leave in the code you wrote that instantiates the Maze object and retrieves the dimensions. Remove any code from the recitation that moves Chihiro around in the maze. Then add code to implement the algorithm shown below. This will require multiple control loops, which can be either while or for statements. Here is a complete specification of the Maze methods you can call:
// Constructor, parameter is name of maze file
public Maze(String fileName);

// Get width and height of maze
public int getWidth();
public int getHeight();

// Get location of Chihiro
public int getColumn();
public int getRow();

// Commands to move Chihiro
public void moveRight();
public void moveLeft();
public void moveDown();
public void moveUp();

// Check if Haku found
public boolean foundHaku();
To solve the assignment, you may want to implement the following method:
public static boolean onEdge(); // returns true if Chihiro is on any edge, false otherwise

Algorithm

The Maze is programmed to wait 0.5 seconds each time you move Chihiro, so you can issue move calls back to back, and Chihiro will move at a reasonable speed that allows you to see the moves. In addition to checking visually, the move methods will print the row and column of Chihiro, and you can use this to debug your code. For example, here is the output of Chihiro moving up the leftmost column:

Maze name: maze.txt
Maze width: 6
Maze height: 6
Moved to row 2, column 3
Moved to row 2, column 2
Moved to row 2, column 1
Moved to row 2, column 0

Testing

You should test your code with the five Mazes provided, and you can also make your own mazes. The format of a maze file is shown below. The first line is an integer specifying the maze width, followed by an integer with the maze height. These values is followed by one line for each row of the maze, with one character per column. The value 'C' is Chihiro, 'H' is Haku, and 'Y' is Yubaba.
6
6
------
-Y---H
----C-
----Y-
-Y-Y--
------

Specifications

Your program must meet the following specifications:

Grading Criteria

Submit your program to the Checkin tab on the course website, as you were shown in the recitation, and read the syllabus for the late policy (if necessary).

© 2016 CS160 Colorado State University. All Rights Reserved.