blob: 1b23afae4f508b8d061960d8046634f016cc0668 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
package esieequest;
import java.util.HashMap;
/**
* A room.
*
* @author Pacien TRAN-GIRARD
* @author Benoit LUBRANO DI SBARAGLIONE
*
* @version February 2014
*/
public class Room {
private String aDescription;
private HashMap<String, Room> aExits;
/**
* Create a room described "description "Initially, it has no exits.
* "description" is something like "a kitchen" or "an open courtyard".
*/
public Room(final String pDescription) {
this.aDescription = pDescription;
this.aExits = new HashMap<String, Room>();
}
public String getDescription() {
return this.aDescription;
}
/**
* Define an exit from this room.
*
* @param direction
* The direction of the exit.
* @param neighbor
* The room in the given direction.
*/
public void setExit(String direction, Room neighbor) {
this.aExits.put(direction, neighbor);
}
/**
* Return the room that is reached if we go from this room in direction
* "direction". If there is no room in that direction, return null.
*/
public Room getExit(String pDirection) {
return this.aExits.get(pDirection);
}
/**
* 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.aExits.get("north") != null) {
vExitsString += " north";
}
if (this.aExits.get("south") != null) {
vExitsString += " south";
}
if (this.aExits.get("east") != null) {
vExitsString += " east";
}
if (this.aExits.get("west") != null) {
vExitsString += " west";
}
if (this.aExits.get("up") != null) {
vExitsString += " up";
}
if (this.aExits.get("down") != null) {
vExitsString += " down";
}
vExitsString += ".";
return vExitsString;
}
}
|