zuul3
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package de.szut.zuul;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Class Room - a room in an adventure game.
|
||||
*
|
||||
@@ -17,12 +19,7 @@ package de.szut.zuul;
|
||||
public class Room
|
||||
{
|
||||
private String description;
|
||||
private Room northExit;
|
||||
private Room southExit;
|
||||
private Room eastExit;
|
||||
private Room westExit;
|
||||
private Room upExit;
|
||||
private Room downExit;
|
||||
private HashMap<String, Room> roomExits;
|
||||
|
||||
/**
|
||||
* Create a room described "description". Initially, it has
|
||||
@@ -33,38 +30,15 @@ public class Room
|
||||
public Room(String description)
|
||||
{
|
||||
this.description = description;
|
||||
this.roomExits = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the exits of this room. Every direction either leads
|
||||
* to another room or is null (no exit there).
|
||||
* @param north The north exit.
|
||||
* @param east The east east.
|
||||
* @param south The south exit.
|
||||
* @param west The west exit.
|
||||
* @param up The up exit.
|
||||
* @param down The down exit.
|
||||
*/
|
||||
public void setExits(Room north, Room east, Room south, Room west, Room up, Room down)
|
||||
{
|
||||
if(north != null) {
|
||||
northExit = north;
|
||||
}
|
||||
if(east != null) {
|
||||
eastExit = east;
|
||||
}
|
||||
if(south != null) {
|
||||
southExit = south;
|
||||
}
|
||||
if(west != null) {
|
||||
westExit = west;
|
||||
}
|
||||
if(up != null) {
|
||||
upExit = up;
|
||||
}
|
||||
if(down != null) {
|
||||
downExit = down;
|
||||
}
|
||||
public void setExit(String direction, Room neighbor) {
|
||||
roomExits.put(direction, neighbor);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,36 +51,13 @@ public class Room
|
||||
public String exitsToString() {
|
||||
StringBuilder exitsInString = new StringBuilder();
|
||||
|
||||
if (northExit != null) {
|
||||
exitsInString.append("north ");
|
||||
}
|
||||
if (eastExit != null) {
|
||||
exitsInString.append("east ");
|
||||
}
|
||||
if (southExit != null) {
|
||||
exitsInString.append("south ");
|
||||
}
|
||||
if (westExit != null) {
|
||||
exitsInString.append("west ");
|
||||
}
|
||||
if (upExit != null) {
|
||||
exitsInString.append("up ");
|
||||
}
|
||||
if (downExit != null) {
|
||||
exitsInString.append("down ");
|
||||
for (String direction : roomExits.keySet()) {
|
||||
exitsInString.append(direction).append(" ");
|
||||
}
|
||||
|
||||
return exitsInString.toString().trim();
|
||||
}
|
||||
public Room getExits(String direction) {
|
||||
return switch (direction) {
|
||||
case "north" -> northExit;
|
||||
case "east" -> eastExit;
|
||||
case "south" -> southExit;
|
||||
case "west" -> westExit;
|
||||
case "up" -> upExit;
|
||||
case "down" -> downExit;
|
||||
default -> null;
|
||||
};
|
||||
return roomExits.get(direction);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user