aboutsummaryrefslogtreecommitdiff
path: root/src/esieequest/Room.java
blob: 32adc900a287811bb105a93890bd7e184de95dff (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
83
84
85
86
87
88
package esieequest;

import java.util.HashMap;
import java.util.Set;

/**
 * A room.
 * 
 * A "Room" represents one location in the scenery of the game. It is connected
 * to other rooms via exits. The exits are labelled north, east, south, west.
 * For each direction, the room stores a reference to the neighboring room, or
 * null if there is no exit in that direction.
 * 
 * @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 court yard".
	 * 
	 * @param description
	 *            The room's description.
	 */
	public Room(final String pDescription) {
		this.aDescription = pDescription;
		this.aExits = new HashMap<String, Room>();

	}

	/**
	 * Return a long description of this room, of the form:
	 * 
	 * You are in the kitchen.
	 * 
	 * Exits: north west
	 * 
	 * @return A description of the room, including exits.
	 */
	public String getLongDescription() {
		String vLongDescription = "You are now " + this.aDescription + ".\n";
		vLongDescription += getExitString();
		return vLongDescription;
	}

	/**
	 * 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 vExitString = "Available exits:";
		Set<String> keys = this.aExits.keySet();
		for (String exit : keys) {
			vExitString += " " + exit;
		}
		vExitString += ".";
		return vExitString;
	}

}