package AdventureModel; import java.io.Serializable; import java.util.ArrayList; /** * This class contains the information about a * room in the Adventure Game. */ public class Room implements Serializable { private final String adventureName; /** * The number of the room. */ private int roomNumber; /** * The name of the room. */ private String roomName; /** * The description of the room. */ private String roomDescription; /** * The passage table for the room. */ private PassageTable motionTable = new PassageTable(); /** * The list of objects in the room. */ public ArrayList objectsInRoom = new ArrayList(); /** * A boolean to store if the room has been visited or not */ private boolean isVisited; /** * AdvGameRoom constructor. * * @param roomName: The name of the room. * @param roomNumber: The number of the room. * @param roomDescription: The description of the room. */ public Room(String roomName, int roomNumber, String roomDescription, String adventureName){ this.roomName = roomName; this.roomNumber = roomNumber; this.roomDescription = roomDescription; this.adventureName = adventureName; this.isVisited = false; } /** * Returns a comma delimited list of every * object's description that is in the given room, * e.g. "a can of tuna, a beagle, a lamp". * * @return delimited string of object descriptions */ public String getObjectString() { //return null; //replace this! String objects = ""; if (objectsInRoom.isEmpty()){ return ""; } for (int i = 0; i < objectsInRoom.size(); i++){ objects = objects + objectsInRoom.get(i).getDescription() + ", "; } objects = objects.substring(0, objects.length()-2); return objects; } /** * Returns a comma delimited list of every * move that is possible from the given room, * e.g. "DOWN, UP, NORTH, SOUTH". * * @return delimited string of possible moves */ public String getCommands() { //return null; //replace this! //what if there are no passages? String commands = ""; if (getMotionTable().getDirection().isEmpty()){ return commands; } for (int i = 0; i < getMotionTable().getDirection().size(); i ++){ commands = commands + getMotionTable().getDirection().get(i).getDirection() + ", "; } commands = commands.substring(0, commands.length()-2); return commands; } /** * This method adds a game object to the room. * * @param object to be added to the room. */ public void addGameObject(AdventureObject object){ this.objectsInRoom.add(object); } /** * This method removes a game object from the room. * * @param object to be removed from the room. */ public void removeGameObject(AdventureObject object){ this.objectsInRoom.remove(object); } /** * This method checks if an object is in the room. * * @param objectName Name of the object to be checked. * @return true if the object is present in the room, false otherwise. */ public boolean checkIfObjectInRoom(String objectName){ for(int i = 0; i