Due: Friday, November 12th, 2010 9:40am
Although you implement this assignment in Java with Eclipse, handin your work using DrRacket.
Start with Maze2.java, and add Locked as sketched in the November 5 slides 12-15 (pages 10-11).
For example, given
IDoor blueToPlanets = new Locked(planetsRoom, "blue");
then
bluetoPlanets.escapePath(new Person("mars", 50.0, "blue"))
should produce a non-failure path, since the person has the blue key that is required by the locked door.
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.
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.
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 5th, 2010mflatt@cs.utah.edu |