-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorld.java
More file actions
75 lines (59 loc) · 1.74 KB
/
World.java
File metadata and controls
75 lines (59 loc) · 1.74 KB
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
package myclasses;
import java.util.HashMap;
import myclasses.WorldConfig;
/**
* A virtual world that contains various locations.
*
* @author Brian Mukeswe
* @contact b.mukeswe@ed.ac.uk
*
*/
public class World {
// A record of the initial state of all locations in the virtual worlds
private static HashMap<String, Location> locations = new HashMap<>();
/**
* Specify the locations contained in the virtual world.
* Location information is retrieved from the configuration class
*/
private static void setLocations() {
// Retrieve location information from the configuration class
for (String locationName : WorldConfig.getLocationNames()) {
locations.put(locationName, new Location(locationName));
}
}
/**
* Retrieve the entry location for the virtual world
*
* @return location, The location where one can enter the virtual world
*/
public static Location getStartLocation() {
// Update location records
setLocations();
if (locations.isEmpty() == false) {
// Identify the start location.
// The name of the start location is retrieved from the configuration class
Location startLocation = locations.get(WorldConfig.getStartLocation());
return startLocation;
}
else {
return null;
}
}
/**
* Retrieve a location from the virtual world
*
* @param locationName name of the location to retrieve
* @return a location object
*/
public static Location getLocation(String locationName) {
// Update location records
setLocations();
if (locations.isEmpty() == false) {
// Retrieve the specified location
return locations.get(locationName);
}
else {
return null;
}
}
}