-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom.java
More file actions
115 lines (106 loc) · 2.98 KB
/
Copy pathRoom.java
File metadata and controls
115 lines (106 loc) · 2.98 KB
1
/* * Class Room - a room in an adventure game. * * Author: Michael Kolling/Aronson * Version: 1.1 * Date: August 2000 * * This class is part of Zork. Zork is a simple, text based adventure game. * * "Room" represents one location in the scenery of the game. It is * connected to at most four other rooms via exits. The exits are labelled * north, east, south, west. For each direction, the room stores a reference * to the neighbouring room, or null if there is no exit in that direction. */class Room { private String description; private Room north, south, east, west; String newItem; String roomRoomItems = ""; /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". */ public Room(String description) { this.description = description; } /** * Define the exits of this room. Every direction either leads to * another room or is null (no exit there). */ public void setExits(Room theNorth, Room theEast, Room theSouth, Room theWest) { north = theNorth; east = theEast; south = theSouth; west = theWest; } /** * Return the description of the room (the one that was defined in the * constructor). */ public String shortDescription() { return description; } /** * Return a long description of this room, on the form: * You are in the kitchen. * Exits: north west */ public String longDescription() { return "You are in " + description + ".\n" + exitString(); } /** * Return a string describing the room's exits, for example * "Exits: north west ". */ private String exitString() { String returnString = "Exits:"; if (north != null) returnString += " north"; if (east != null) returnString += " east"; if (south != null) returnString += " south"; if (west != null) returnString += " west"; return returnString; } /** * Return the room that is reached if we go from this room in direction * "direction". If there is no room in that direction, return null. */ public Room nextRoom(String direction) { if (direction.equals("north")) return north; else if (direction.equals("east")) return east; else if (direction.equals("south")) return south; else if (direction.equals("west")) return west; else return null; } public void refreshItems(String newItem) { this.newItem = newItem; roomRoomItems = roomRoomItems + " " + newItem; } public String getItems() { return roomRoomItems; } /** public void updateRoomItems(String roomRoomItems) { this.roomRoomItems = roomRoomItems; } **/}