zuul2
This commit is contained in:
@@ -158,24 +158,8 @@ public class Game
|
|||||||
|
|
||||||
// Try to leave current room.
|
// Try to leave current room.
|
||||||
Room nextRoom = null;
|
Room nextRoom = null;
|
||||||
if(direction.equals("north")) {
|
|
||||||
nextRoom = currentRoom.northExit;
|
nextRoom = currentRoom.getExits(direction);
|
||||||
}
|
|
||||||
if(direction.equals("east")) {
|
|
||||||
nextRoom = currentRoom.eastExit;
|
|
||||||
}
|
|
||||||
if(direction.equals("south")) {
|
|
||||||
nextRoom = currentRoom.southExit;
|
|
||||||
}
|
|
||||||
if(direction.equals("west")) {
|
|
||||||
nextRoom = currentRoom.westExit;
|
|
||||||
}
|
|
||||||
if(direction.equals("up")) {
|
|
||||||
nextRoom = currentRoom.upExit;
|
|
||||||
}
|
|
||||||
if(direction.equals("down")) {
|
|
||||||
nextRoom = currentRoom.downExit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nextRoom == null) {
|
if (nextRoom == null) {
|
||||||
System.out.println("There is no door!");
|
System.out.println("There is no door!");
|
||||||
@@ -205,24 +189,7 @@ public class Game
|
|||||||
{
|
{
|
||||||
System.out.println("You are " + currentRoom.getDescription());
|
System.out.println("You are " + currentRoom.getDescription());
|
||||||
System.out.print("Exits: ");
|
System.out.print("Exits: ");
|
||||||
if(currentRoom.northExit != null) {
|
System.out.print(currentRoom.exitsToString());
|
||||||
System.out.print("north ");
|
|
||||||
}
|
|
||||||
if(currentRoom.eastExit != null) {
|
|
||||||
System.out.print("east ");
|
|
||||||
}
|
|
||||||
if(currentRoom.southExit != null) {
|
|
||||||
System.out.print("south ");
|
|
||||||
}
|
|
||||||
if(currentRoom.westExit != null) {
|
|
||||||
System.out.print("west ");
|
|
||||||
}
|
|
||||||
if(currentRoom.upExit != null) {
|
|
||||||
System.out.print("up ");
|
|
||||||
}
|
|
||||||
if(currentRoom.downExit != null) {
|
|
||||||
System.out.print("down ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ package de.szut.zuul;
|
|||||||
*/
|
*/
|
||||||
public class Room
|
public class Room
|
||||||
{
|
{
|
||||||
public String description;
|
private String description;
|
||||||
public Room northExit;
|
private Room northExit;
|
||||||
public Room southExit;
|
private Room southExit;
|
||||||
public Room eastExit;
|
private Room eastExit;
|
||||||
public Room westExit;
|
private Room westExit;
|
||||||
public Room upExit;
|
private Room upExit;
|
||||||
public Room downExit;
|
private Room downExit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a room described "description". Initially, it has
|
* Create a room described "description". Initially, it has
|
||||||
@@ -74,5 +74,39 @@ public class Room
|
|||||||
{
|
{
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
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 ");
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user