public class Doorway {
    
    //The rooms that are connected to this doorway
    private final Room room1;
    private final Room room2;
    
    public Doorway(Room room1, Room room2) {
        this.room1 = room1;
        this.room2 = room2;
        
        room1.addDoorway(this);
        room2.addDoorway(this);
    }
    
    //let a person go through
    public void goThrough(Person person) {
        Room target = getOppositeRoom(person.getRoom());
        
        //if there's a room on the other side, let the person go to it
        if (target != null) {
            person.setRoom(target);
        }else{
            System.out.println("This person is not near this doorway");
        }
    }
    
    //return the room on the otherside of the doorway
    public Room getOppositeRoom(Room room) {
        if (room.equals(room1)) {
            return room2;
        }else if(room.equals(room2)) {
            return room1;
        }else{
            return null;
        }
    }
    
    //get the label for a specific room using this doorway
    public String getLabel(Room room) {
        return room.getName();
    }
    
}