CS 1410-20 Homework 9

Due: Friday, November 4th, 2011 10:45am

Start with Maze2.java or maze2.zip.

Although you implement this assignment in Java with Eclipse, you can handin your work using DrRacket. Alternatively, you can handin through a web browser using the handin status server. The latter is better if you work with multiple files, in which case you can submit a .zip file containing your work.

Part 1 – Color-Detecting Doors

Add a new kind of door, ColorDetector, though which only players holding color keys (i.e., any key that is not "black" or "white") can pass. A color-detector door goes into a room.

For example, given

  IDoor monoDoor = new ColorDetector(northRoom);

then

  monoDoor.escapePath(new Person("Alaska", 5.0, "blue"))

should produce a non-failure path, since the person has a color key.

Part 2 – Multiple Keys

Generalize Person to hold a list of keys. Although Java has some built-in classes for holding collections of values, for now define an IKeyList type and use it for the list of keys.

Part 3 – Preparing for Kinds of Rooms

So far, we have only one kind of room. To support more kinds of rooms, change the maze code by switching uses of the Room type to IRoom, and make the existing Room class implement IRoom.

For this step, Room will be the only kind of IRoom.

Part 4 – Accumulating Keys

Add a new kind of IRoom called KeyRoom that has only one door (unlike Room) plus a key of a given color. When a player passes through the room, the player also picks up the key.

For example, given the door

  new Into(new KeyRoom(new Into(new Room(blueToPlanets, new Escape("Provo"))),
                       "blue"))

then a player who starts with no keys will be able to reach "mars", because the key room lets the player pick up a blue key before reaching the blue-keyed door. In contrast, the door

  new Locked(new KeyRoom(planets, "blue"), "blue")

is impassable to a player who doesn’t start with a blue key, since the key is supplied on the wrong side of the door.

With this change, the Person argument to escapePath serves as an accumulator that gathers keys from KeyRooms while looking for an escape.


Last update: Friday, November 4th, 2011
mflatt@cs.utah.edu