aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/esieequest/controller/GameEngine.java2
-rw-r--r--src/esieequest/esieequest.gwt.xml1
-rw-r--r--src/esieequest/model/Player.java39
-rw-r--r--src/esieequest/model/items/Item.java8
-rw-r--r--src/net/pacien/util/IntrinsicMap.java59
-rw-r--r--src/net/pacien/util/Mappable.java7
-rw-r--r--src/net/pacien/util/pacienutils.gwt.xml3
-rw-r--r--src/net/pacien/util/package-info.java8
8 files changed, 96 insertions, 31 deletions
diff --git a/src/esieequest/controller/GameEngine.java b/src/esieequest/controller/GameEngine.java
index fed79d6..c3a8725 100644
--- a/src/esieequest/controller/GameEngine.java
+++ b/src/esieequest/controller/GameEngine.java
@@ -41,7 +41,7 @@ public class GameEngine {
41 * the command String 41 * the command String
42 */ 42 */
43 public void interpret(final String inputString) { 43 public void interpret(final String inputString) {
44 final Input input = new Input(inputString); 44 final Input input = new Input(inputString.toLowerCase());
45 45
46 final Command command = input.getCommand(); 46 final Command command = input.getCommand();
47 if (command == null) { 47 if (command == null) {
diff --git a/src/esieequest/esieequest.gwt.xml b/src/esieequest/esieequest.gwt.xml
index 1a5c10c..b7dbcbf 100644
--- a/src/esieequest/esieequest.gwt.xml
+++ b/src/esieequest/esieequest.gwt.xml
@@ -19,6 +19,7 @@ so that your app can take advantage of the latest GWT module capabilities.
19 19
20 <!-- Other module inherits --> 20 <!-- Other module inherits -->
21 <inherits name="com.google.common.collect.Collect" /> 21 <inherits name="com.google.common.collect.Collect" />
22 <inherits name="net.pacien.util.pacienutils" />
22 23
23 <!-- Specify the app entry point class. --> 24 <!-- Specify the app entry point class. -->
24 <entry-point class='esieequest.view.web.Main' /> 25 <entry-point class='esieequest.view.web.Main' />
diff --git a/src/esieequest/model/Player.java b/src/esieequest/model/Player.java
index 4060367..2ab8190 100644
--- a/src/esieequest/model/Player.java
+++ b/src/esieequest/model/Player.java
@@ -4,6 +4,7 @@ import java.util.ArrayList;
4import java.util.List; 4import java.util.List;
5import java.util.Stack; 5import java.util.Stack;
6 6
7import net.pacien.util.IntrinsicMap;
7import esieequest.controller.Utils; 8import esieequest.controller.Utils;
8import esieequest.model.items.Item; 9import esieequest.model.items.Item;
9import esieequest.model.map.Direction; 10import esieequest.model.map.Direction;
@@ -22,7 +23,7 @@ public class Player {
22 private final Stack<Room> previousRooms; 23 private final Stack<Room> previousRooms;
23 private Direction currentDirection; 24 private Direction currentDirection;
24 25
25 private final List<Item> items; 26 private final IntrinsicMap<String, Item> items;
26 private final int carryWeightLimit; 27 private final int carryWeightLimit;
27 28
28 private int nbSteps; 29 private int nbSteps;
@@ -43,9 +44,9 @@ public class Player {
43 */ 44 */
44 private Player(final Room currentRoom, final Direction currentDirection, final int carryWeightLimit, final int nbStepsLimit) { 45 private Player(final Room currentRoom, final Direction currentDirection, final int carryWeightLimit, final int nbStepsLimit) {
45 this.currentRoom = currentRoom; 46 this.currentRoom = currentRoom;
46 this.previousRooms = new Stack<Room>(); 47 this.previousRooms = new Stack<>();
47 this.currentDirection = currentDirection; 48 this.currentDirection = currentDirection;
48 this.items = new ArrayList<Item>(); 49 this.items = new IntrinsicMap<>();
49 this.carryWeightLimit = carryWeightLimit; 50 this.carryWeightLimit = carryWeightLimit;
50 this.nbSteps = 0; 51 this.nbSteps = 0;
51 this.nbStepsLimit = nbStepsLimit; 52 this.nbStepsLimit = nbStepsLimit;
@@ -166,7 +167,7 @@ public class Player {
166 * @return if the Player have the Item 167 * @return if the Player have the Item
167 */ 168 */
168 public boolean hasItem(final Item item) { 169 public boolean hasItem(final Item item) {
169 return this.items.contains(item); 170 return this.items.containsValue(item);
170 } 171 }
171 172
172 /** 173 /**
@@ -178,7 +179,7 @@ public class Player {
178 * @return if the Player have the Item 179 * @return if the Player have the Item
179 */ 180 */
180 public boolean hasItem(final String itemName) { 181 public boolean hasItem(final String itemName) {
181 return this.getItem(itemName) != null; 182 return this.items.containsKey(itemName);
182 } 183 }
183 184
184 /** 185 /**
@@ -186,7 +187,7 @@ public class Player {
186 */ 187 */
187 public int getItemsWeight() { 188 public int getItemsWeight() {
188 int totalWeight = 0; 189 int totalWeight = 0;
189 for (final Item item : this.items) { 190 for (final Item item : this.items.values()) {
190 totalWeight += item.getWeight(); 191 totalWeight += item.getWeight();
191 } 192 }
192 return totalWeight; 193 return totalWeight;
@@ -199,7 +200,7 @@ public class Player {
199 * the Item to add 200 * the Item to add
200 */ 201 */
201 public void addItem(final Item item) { 202 public void addItem(final Item item) {
202 this.items.add(item); 203 this.items.put(item);
203 } 204 }
204 205
205 /** 206 /**
@@ -223,27 +224,12 @@ public class Player {
223 } 224 }
224 225
225 /** 226 /**
226 * Lists all the Player's Item-s names.
227 *
228 * @return the list of all the names of the Item-s
229 */
230 public List<String> listItemsNames() {
231 final ArrayList<String> itemsNamesList = new ArrayList<String>();
232
233 for (final Item item : this.items) {
234 itemsNamesList.add(item.getName());
235 }
236
237 return itemsNamesList;
238 }
239
240 /**
241 * Lists all the Player's Item-s names in a String. 227 * Lists all the Player's Item-s names in a String.
242 * 228 *
243 * @return the list of the Item-s in a String 229 * @return the list of the Item-s in a String
244 */ 230 */
245 public String listItemsNamesString() { 231 public String listItemsNamesString() {
246 return Utils.listToString(this.listItemsNames(), Text.INVENTORY_PREFIX.getText(), Text.ITEMS_NO_ITEM.getText(), Text.INVENTORY_SUFFIX.getText()); 232 return Utils.listToString(new ArrayList<String>(this.items.keySet()), Text.INVENTORY_PREFIX.getText(), Text.ITEMS_NO_ITEM.getText(), Text.INVENTORY_SUFFIX.getText());
247 } 233 }
248 234
249 /** 235 /**
@@ -262,12 +248,7 @@ public class Player {
262 * @return the Item 248 * @return the Item
263 */ 249 */
264 public Item getItem(final String itemName) { 250 public Item getItem(final String itemName) {
265 for (final Item item : this.items) { 251 return this.items.get(itemName);
266 if (item.getName().toLowerCase().equals(itemName.toLowerCase())) {
267 return item;
268 }
269 }
270 return null;
271 } 252 }
272 253
273 /** 254 /**
diff --git a/src/esieequest/model/items/Item.java b/src/esieequest/model/items/Item.java
index 2a0aa2c..491b3ef 100644
--- a/src/esieequest/model/items/Item.java
+++ b/src/esieequest/model/items/Item.java
@@ -1,9 +1,10 @@
1package esieequest.model.items; 1package esieequest.model.items;
2 2
3import net.pacien.util.Mappable;
3import esieequest.model.Game; 4import esieequest.model.Game;
4import esieequest.view.Viewable; 5import esieequest.view.Viewable;
5 6
6public enum Item { 7public enum Item implements Mappable {
7 8
8 // @formatter:off 9 // @formatter:off
9 10
@@ -64,4 +65,9 @@ public enum Item {
64 this.item.use(game, view); 65 this.item.use(game, view);
65 } 66 }
66 67
68 @Override
69 public Object getKey() {
70 return this.item.getName().toLowerCase();
71 }
72
67} 73}
diff --git a/src/net/pacien/util/IntrinsicMap.java b/src/net/pacien/util/IntrinsicMap.java
new file mode 100644
index 0000000..a68dcbe
--- /dev/null
+++ b/src/net/pacien/util/IntrinsicMap.java
@@ -0,0 +1,59 @@
1/**
2 *
3 */
4package net.pacien.util;
5
6import java.util.HashMap;
7import java.util.Map;
8
9/**
10 * @author pacien
11 *
12 */
13public class IntrinsicMap<K, V extends Mappable> extends HashMap<K, V> {
14
15 /**
16 *
17 */
18 private static final long serialVersionUID = 1L;
19
20 /**
21 *
22 */
23 public IntrinsicMap() {
24 super();
25 }
26
27 /**
28 * @param initialCapacity
29 */
30 public IntrinsicMap(int initialCapacity) {
31 super(initialCapacity);
32 }
33
34 /**
35 * @param m
36