public class Room{ private String description; private LockablePassageway north = null; private LockablePassageway south = null; private LockablePassageway west = null; private LockablePassageway east = null; private boolean currentRoom; private boolean exit; private Denizen creature = null; /** Constructor: creates a room with a description of the room, true/false * value if it is the starting room, and a true/false value if it's * the exit to the maze*/ public Room(String rDescription, boolean current, boolean escape){ description = rDescription; currentRoom = current; exit = escape; } /** Constructor (overloaded): creates a room with a description of the room, a * true/false value if it is the starting room, a true/false value if it is the * exit to the maze, and a Denizen (that must be passed to it) to inhabit the * room*/ public Room(String rDescription, boolean current, boolean escape, Denizen inhabit){ description = rDescription; currentRoom = current; creature = inhabit; } /** Query: returns true if the room is the room the explorer is in, and false * otherwise*/ public boolean occupied(){ return currentRoom; } /** Query: returns the description of the room */ public String roomDescription(){ return description; } /** Mutator: Takes 2 rooms and make the first one the room to the North * and makes the second room the room to the South. *
* Makes it so that roomSouth.north and roomNorth.south points to a * new passageway that links the 2 rooms together. */ public static void connectNorthSouth(Room roomNorth, Room roomSouth){ roomSouth.north = new LockablePassageway(roomSouth, roomNorth); roomNorth.south = roomSouth.north; } /** Mutator: Takes 2 rooms and make the first one the room to the West * and makes the second room the room to the East. *
* Makes it so that roomWest.east and roomEast.west points to a * new passageway that links the 2 rooms together. */ public static void connectEastWest(Room roomWest, Room roomEast){ roomEast.west = new LockablePassageway(roomEast, roomWest); roomWest.east = roomEast.west; } /** Query: reutrns the passageway to the north */ public LockablePassageway pNorth(){ return north; } /** Query: returns the passageway to the south */ public LockablePassageway pSouth(){ return south; } /*Query: returns the passageway to the east */ public LockablePassageway pEast(){ return east; } /** Query: returns the passageway to the west */ public LockablePassageway pWest(){ return west; } /** Mutator: sets the occupied flag to show the explorer is in the room */ public void enter(){ currentRoom = true; } /** Mutator: removes the occupied flag to show the explorer has left the room */ public void exit(){ currentRoom = false; } /** Query: returns the Denizen, inhabiting the room */ public Denizen monster(){ return creature; } /** Query: returns true if the room is the exit to the maze, false otherwise */ public boolean escape(){ return exit; } }