diff options
author | Pacien TRAN-GIRARD | 2014-02-23 17:52:57 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-02-23 17:52:57 +0100 |
commit | e510b08d0925629dba304177099ccd3a81585ba9 (patch) | |
tree | 3de63bc2676f76ae9324bd02e51f8b147ca093cf | |
parent | 9a4983c745c99f5e0e97f2056bc2332cb7e5d803 (diff) | |
download | esieequest-e510b08d0925629dba304177099ccd3a81585ba9.tar.gz |
Make getExitString() more flexible and add getLongDescription()
-rw-r--r-- | src/esieequest/Game.java | 3 | ||||
-rw-r--r-- | src/esieequest/Room.java | 44 |
2 files changed, 22 insertions, 25 deletions
diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index 1be4d15..bad0106 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java | |||
@@ -180,8 +180,7 @@ public class Game { | |||
180 | } | 180 | } |
181 | 181 | ||
182 | private void printLocationInfo() { | 182 | private void printLocationInfo() { |
183 | System.out.println("You are now " + this.aCurrentRoom.getDescription() + "."); | 183 | System.out.println(this.aCurrentRoom.getLongDescription()); |
184 | System.out.println(this.aCurrentRoom.getExitString()); | ||
185 | } | 184 | } |
186 | 185 | ||
187 | private void printWelcome() { | 186 | private void printWelcome() { |
diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java index 1b23afa..9d7f071 100644 --- a/src/esieequest/Room.java +++ b/src/esieequest/Room.java | |||
@@ -1,6 +1,7 @@ | |||
1 | package esieequest; | 1 | package esieequest; |
2 | 2 | ||
3 | import java.util.HashMap; | 3 | import java.util.HashMap; |
4 | import java.util.Set; | ||
4 | 5 | ||
5 | /** | 6 | /** |
6 | * A room. | 7 | * A room. |
@@ -25,8 +26,19 @@ public class Room { | |||
25 | 26 | ||
26 | } | 27 | } |
27 | 28 | ||
28 | public String getDescription() { | 29 | /** |
29 | return this.aDescription; | 30 | * Return a long description of this room, of the form: |
31 | * | ||
32 | * You are in the kitchen. | ||
33 | * | ||
34 | * Exits: north west | ||
35 | * | ||
36 | * @return A description of the room, including exits. | ||
37 | */ | ||
38 | public String getLongDescription() { | ||
39 | String vLongDescription = "You are now " + this.aDescription + ".\n"; | ||
40 | vLongDescription += getExitString(); | ||
41 | return vLongDescription; | ||
30 | } | 42 | } |
31 | 43 | ||
32 | /** | 44 | /** |
@@ -50,33 +62,19 @@ public class Room { | |||
50 | } | 62 | } |
51 | 63 | ||
52 | /** | 64 | /** |
53 | * Return a description of the room’s exits, for example, | 65 | * Return a description of the room’s exits, for example |
54 | * "Exits: north west". | 66 | * "Exits: north west". |
55 | * | 67 | * |
56 | * @return A description of the available exits. | 68 | * @return A description of the available exits. |
57 | */ | 69 | */ |
58 | public String getExitString() { | 70 | public String getExitString() { |
59 | String vExitsString = "Available exits:"; | 71 | String vExitString = "Available exits:"; |
60 | if (this.aExits.get("north") != null) { | 72 | Set<String> keys = this.aExits.keySet(); |
61 | vExitsString += " north"; | 73 | for (String exit : keys) { |
62 | } | 74 | vExitString += " " + exit; |
63 | if (this.aExits.get("south") != null) { | ||
64 | vExitsString += " south"; | ||
65 | } | ||
66 | if (this.aExits.get("east") != null) { | ||
67 | vExitsString += " east"; | ||
68 | } | ||
69 | if (this.aExits.get("west") != null) { | ||
70 | vExitsString += " west"; | ||
71 | } | ||
72 | if (this.aExits.get("up") != null) { | ||
73 | vExitsString += " up"; | ||
74 | } | ||
75 | if (this.aExits.get("down") != null) { | ||
76 | vExitsString += " down"; | ||
77 | } | 75 | } |
78 | vExitsString += "."; | 76 | vExitString += "."; |
79 | return vExitsString; | 77 | return vExitString; |
80 | } | 78 | } |
81 | 79 | ||
82 | } | 80 | } |