-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorldConfig.java
More file actions
234 lines (187 loc) · 6.81 KB
/
WorldConfig.java
File metadata and controls
234 lines (187 loc) · 6.81 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package myclasses;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* A configuration class that specifies the names of the files that make up locations
* and items in the virtual world. For location images, the configuration class also
* specifies the exits that are in each image file (if any).
*
* @author Brian Mukeswe
* @contact b.mukeswe@ed.ac.uk
*
*/
public class WorldConfig {
// A record containing the names of all locations
private static List<String> locationNames = new ArrayList<>();
// Variables to store information about the images that make up each location
private static HashMap <String, String> bedroom = new HashMap<>();
private static HashMap <String, String> livingroom = new HashMap<>();
private static HashMap <String, String> kitchen = new HashMap<>();
private static HashMap <String, String> washroom = new HashMap<>();
private static HashMap <String, String> corridor = new HashMap<>();
// A map between location names and their corresponding images
private static HashMap <String, HashMap<String, String>> locationImages = new HashMap<>();
// A record of the exits contained in each image
private static HashMap <String, String> exits = new HashMap<>();
// A record of the items initially contained in each location
private static HashMap <String, String>itemImages = new HashMap<>();
// The entry location
private static String startLocation;
/**
* Specify the names of the locations in the world
*/
private static void setLocationNames() {
locationNames.add("bedroom");
locationNames.add("kitchen");
locationNames.add("corridor");
locationNames.add("livingroom");
locationNames.add("washroom");
}
/**
* Retrieve an image corresponding to the view at a location in a specific direction
*
* @param locationName, the name of the location where the image is located
* @param direction, the direction corresponding to the image to be retrieved
*
* @return The file name of the requested image
*/
public static String getViewImage(String locationName, String direction) {
// Set up location information
configLocations();
setLocationImages();
// Retrieve the appropriate image
HashMap <String, String> images = locationImages.get(locationName);
return images.get(direction);
}
/**
* Retrieve a map of all exits between locations in the world
*
* @return A HashMap containing image filenames and corresponding exits
*/
public static HashMap <String, String> getExits(){
// Set up exit information
setExits();
if (exits.isEmpty() == false) {
// Retrieve exit map
return exits;
}
else {
return null;
}
}
/**
* Retrieve the names of all locations in the virtual world
*
* @return A list of all names in the virtual world
*/
public static List<String> getLocationNames(){
// Set up location information
setLocationNames();
if (locationNames.isEmpty() == false) {
// Retrieve location names
return locationNames;
}
else {
return null;
}
}
/**
* Retrieve the items that are initially present at a location
*
* @param LocationName, The name of the locations where the items are located
*
* @return a comma separated list of items at the specified location
*/
public static String getItemImages(String LocationName){
// Update item information
setItemImages();
// Retrieve the items at the specified location
return itemImages.get(LocationName);
}
/**
* Retrieve the name of the entry location into the virtual world
*
* @return The name of the entry location
*/
public static String getStartLocation() {
setStartLocation();
return startLocation;
}
/**
* Specify the entry location into the virtual world
*/
private static void setStartLocation() {
startLocation = "corridor";
}
/**
* Specify the group of images corresponding to each location
*/
private static void setLocationImages() {
locationImages.put("bedroom", bedroom);
locationImages.put("livingroom", livingroom);
locationImages.put("kitchen", kitchen);
locationImages.put("washroom", washroom);
locationImages.put("corridor", corridor);
}
/**
* Specify the items that are initially at each location
*/
private static void setItemImages() {
itemImages.put("bedroom", "book.png"); //book photo from https://www.wikihow.com/Dedicate-a-Book
itemImages.put("livingroom", "none");
itemImages.put("kitchen", "spoon.png, fork.png, plate.png");
itemImages.put("washroom", "soap.png");
itemImages.put("corridor", "clock.png");
}
/**
* Specify the group of image files that make up each location
*/
private static void configLocations() {
bedroom.put("north","bedroom-north.jpeg");
bedroom.put("south", "bedroom-south.jpeg");
bedroom.put("east", "bedroom-east.jpeg");
bedroom.put("west", "bedroom-west.jpeg");
livingroom.put("north","livingroom-north.jpeg");
livingroom.put("south", "livingroom-south.jpeg");
livingroom.put("east", "livingroom-east.jpeg");
livingroom.put("west", "livingroom-west.jpeg");
kitchen.put("north", "kitchen-north.jpeg");
kitchen.put("south", "kitchen-south.jpeg");
kitchen.put("east", "kitchen-east.jpeg");
kitchen.put("west", "kitchen-west.jpeg");
washroom.put("north","bathroom-north.jpeg");
washroom.put("south", "bathroom-south.jpeg");
washroom.put("east", "bathroom-east.jpeg");
washroom.put("west", "bathroom-west.jpeg");
corridor.put("north","corridor-north.jpeg");
corridor.put("south", "corridor-south.jpeg");
corridor.put("east", "corridor-east.jpeg");
corridor.put("west", "corridor-west.jpeg");
}
/**
* Specify the exits in each image if any
*/
private static void setExits() {
exits.put("bedroom-north.jpeg", "none");
exits.put("bedroom-south.jpeg", "none");
exits.put("bedroom-east.jpeg", "corridor");
exits.put("bedroom-west.jpeg", "none");
exits.put("livingroom-north.jpeg", "none");
exits.put("livingroom-south.jpeg", "none");
exits.put("livingroom-east.jpeg", "corridor");
exits.put("livingroom-west.jpeg", "none");
exits.put("kitchen-north.jpeg", "none");
exits.put("kitchen-south.jpeg", "corridor");
exits.put("kitchen-east.jpeg", "none");
exits.put("kitchen-west.jpeg", "none");
exits.put("bathroom-north.jpeg", "corridor");
exits.put("bathroom-south.jpeg", "none");
exits.put("bathroom-east.jpeg", "none");
exits.put("bathroom-west.jpeg", "none");
exits.put("corridor-north.jpeg", "kitchen");
exits.put("corridor-south.jpeg", "washroom");
exits.put("corridor-east.jpeg", "none");
exits.put("corridor-west.jpeg", "bedroom, livingroom");
}
}