CS 160, Spring 2015
Programming Assignment P6
Maze Program

Programming due Monday, Mar. 9 at 6:00pm; late deadline Mar. 9 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

This assignment features Chihiro from the Miyazaki film Spirited Away, the best animated film 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 10 you should have started on P6.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 getSize();

// 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();

// Returns true when Chihiro finds Haku, false otherwise
public boolean isDone()

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 to 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 size, which is both the number of rows and columns, since the maze is square. This 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
--Y---
-Y----
----C-
----Y-
-H-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).

© 2015 CS160 Colorado State University. All Rights Reserved.