package AdventureGameModel; import java.io.Serializable; import java.util.ArrayList; import java.util.StringJoiner; /** * This class contains the information about a * room in the Adventure Game */ public class Room implements Serializable { private final String adventureName; private int roomNumber; // the number of the room private String roomName; // the name of the room private String roomDescription; // the description of the room private PassageTable motionTable = new PassageTable(); // the passage table for the room public ArrayList objectsInRoom = new ArrayList(); // the list of objects in the room private boolean isVisited; // check if room has been visited or not /** * 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() { StringJoiner joiner = new StringJoiner(", "); for (int i = 0; i < this.objectsInRoom.size(); i++) { joiner.add(this.objectsInRoom.get(i).getDescription()); } String want = joiner.toString(); return want; } /** * 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() { StringJoiner joiner = new StringJoiner(", ") ; ArrayList all_duplicate_directions = new ArrayList<>(); for (int i = 0; i < this.motionTable.passageTable.size(); i++) { if (!all_duplicate_directions.contains(this.motionTable.passageTable.get(i).getDirection())) { all_duplicate_directions.add(this.motionTable.passageTable.get(i).getDirection()); joiner.add(this.motionTable.passageTable.get(i).getDirection()); } } String want = joiner.toString(); return want; } /** * 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