From ca65af2e2be2e10347fe9ca057fec231d25d404d Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 23 Feb 2014 16:08:45 +0100 Subject: Implement getExitString() --- src/esieequest/Game.java | 16 +--------------- src/esieequest/Room.java | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index 95eaa4a..a00d901 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java @@ -145,21 +145,7 @@ public class Game { private void printLocationInfo() { System.out.println("You are now " + this.aCurrentRoom.getDescription() + "."); - - System.out.print("Available exits:"); - if (this.aCurrentRoom.aNorthExit != null) { - System.out.print(" North"); - } - if (this.aCurrentRoom.aSouthExit != null) { - System.out.print(" South"); - } - if (this.aCurrentRoom.aEastExit != null) { - System.out.print(" East"); - } - if (this.aCurrentRoom.aWestExit != null) { - System.out.print(" West"); - } - System.out.println("."); + System.out.println(this.aCurrentRoom.getExitString()); } private void printWelcome() { diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java index d9235cf..5b4dcfa 100644 --- a/src/esieequest/Room.java +++ b/src/esieequest/Room.java @@ -47,4 +47,28 @@ public class Room { } return null; } + + /** + * Return a description of the room’s exits, for example, + * "Exits: north west". + * + * @return A description of the available exits. + */ + public String getExitString() { + String vExitsString = "Available exits:"; + if (this.aNorthExit != null) { + vExitsString += " North"; + } + if (this.aSouthExit != null) { + vExitsString += " South"; + } + if (this.aEastExit != null) { + vExitsString += " East"; + } + if (this.aWestExit != null) { + vExitsString += " West"; + } + vExitsString += "."; + return vExitsString; + } } -- cgit v1.2.3