aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-05-07 17:09:45 +0200
committerPacien TRAN-GIRARD2014-05-07 17:09:45 +0200
commit2b9c7ce7e2a08464e412be2841f00f6524cef437 (patch)
treede55c712f48636d88b7240e4222e2e2e0274bd22
parent39dd450b8b252cf5231918f6a03d4d9bf9cf4569 (diff)
downloadesieequest-2b9c7ce7e2a08464e412be2841f00f6524cef437.tar.gz
Reimplement Inventory (ItemList)
-rw-r--r--src/esieequest/controller/commands/DoCommand.java2
-rw-r--r--src/esieequest/controller/commands/DropCommand.java11
-rw-r--r--src/esieequest/controller/commands/InventoryCommand.java2
-rw-r--r--src/esieequest/controller/commands/TakeCommand.java8
-rw-r--r--src/esieequest/controller/commands/UseCommand.java4
-rw-r--r--src/esieequest/controller/utils/SerialisableList.java27
-rw-r--r--src/esieequest/model/Game.java2
-rw-r--r--src/esieequest/model/Player.java132
-rw-r--r--src/esieequest/model/doors/LockedDoor.java2
-rw-r--r--src/esieequest/model/items/Inventory.java209
-rw-r--r--src/esieequest/model/items/Item.java4
-rw-r--r--src/esieequest/model/map/Room.java9
-rw-r--r--src/esieequest/model/map/Side.java52
-rw-r--r--src/net/pacien/util/IntrinsicMap.java10
-rw-r--r--src/net/pacien/util/Mappable.java4
15 files changed, 283 insertions, 195 deletions
diff --git a/src/esieequest/controller/commands/DoCommand.java b/src/esieequest/controller/commands/DoCommand.java
index 219dba9..95269de 100644
--- a/src/esieequest/controller/commands/DoCommand.java
+++ b/src/esieequest/controller/commands/DoCommand.java
@@ -23,7 +23,7 @@ public class DoCommand implements Executable {
23 return; 23 return;
24 } 24 }
25 25
26 if (currentSide.hasItem()) { 26 if (currentSide.getInventory().getSize() == 1) {
27 Command.TAKE.execute(argument, game, view); 27 Command.TAKE.execute(argument, game, view);
28 return; 28 return;
29 } 29 }
diff --git a/src/esieequest/controller/commands/DropCommand.java b/src/esieequest/controller/commands/DropCommand.java
index 8d2b820..09b2394 100644
--- a/src/esieequest/controller/commands/DropCommand.java
+++ b/src/esieequest/controller/commands/DropCommand.java
@@ -23,18 +23,13 @@ public class DropCommand implements Executable {
23 return; 23 return;
24 } 24 }
25 25
26 if (!game.getPlayer().hasItem(itemName)) { 26 if (!game.getPlayer().getInventory().hasItem(itemName)) {
27 view.echo(Text.NO_SUCH_ITEM.getText()); 27 view.echo(Text.NO_SUCH_ITEM.getText());
28 return; 28 return;
29 } 29 }
30 30
31 if (game.getPlayer().getCurrentSide().hasItem()) { 31 final Item item = game.getPlayer().getInventory().takeItem(itemName);
32 view.echo(Text.ROOM_INVENTORY_FULL.getText()); 32 game.getPlayer().getCurrentSide().getInventory().putItem(item);
33 return;
34 }
35
36 final Item item = game.getPlayer().takeItem(itemName);
37 game.getPlayer().getCurrentSide().putItem(item);
38 33
39 } 34 }
40 35
diff --git a/src/esieequest/controller/commands/InventoryCommand.java b/src/esieequest/controller/commands/InventoryCommand.java
index 0f95ead..a6ce080 100644
--- a/src/esieequest/controller/commands/InventoryCommand.java
+++ b/src/esieequest/controller/commands/InventoryCommand.java
@@ -13,7 +13,7 @@ public class InventoryCommand implements Executable {
13 @Override 13 @Override
14 public void execute(final String argument, final Game game, final Viewable view) { 14 public void execute(final String argument, final Game game, final Viewable view) {
15 15
16 view.echo(game.getPlayer().listItemsNamesString() + game.getPlayer().getWeightString()); 16 view.echo(game.getPlayer().getInventory().listItemsNamesString() + game.getPlayer().getInventory().getWeightString());
17 17
18 } 18 }
19 19
diff --git a/src/esieequest/controller/commands/TakeCommand.java b/src/esieequest/controller/commands/TakeCommand.java
index 16327e4..8b8a461 100644
--- a/src/esieequest/controller/commands/TakeCommand.java
+++ b/src/esieequest/controller/commands/TakeCommand.java
@@ -29,23 +29,23 @@ public class TakeCommand implements Executable {
29 item = currentRoom.getItem(itemName); 29 item = currentRoom.getItem(itemName);
30 } else { 30 } else {
31 final Side currentSide = game.getPlayer().getCurrentSide(); 31 final Side currentSide = game.getPlayer().getCurrentSide();
32 if (!currentSide.hasItem()) { 32 if (currentSide.getInventory().getSize() != 1) {
33 view.echo(Text.NO_ITEM.getText()); 33 view.echo(Text.NO_ITEM.getText());
34 return; 34 return;
35 } 35 }
36 item = currentSide.getItem(); 36 item = currentSide.getInventory().getItem();
37 } 37 }
38 38
39 // handle inventory weight limit 39 // handle inventory weight limit
40 final int maximumWeight = game.getPlayer().getInventoryWeightLimit(); 40 final int maximumWeight = game.getPlayer().getInventoryWeightLimit();
41 final int futureWeight = game.getPlayer().getItemsWeight() + item.getWeight(); 41 final int futureWeight = game.getPlayer().getInventory().getTotalWeight() + item.getWeight();
42 if (futureWeight > maximumWeight) { 42 if (futureWeight > maximumWeight) {
43 view.echo(Text.INVENTORY_FULL.getText()); 43 view.echo(Text.INVENTORY_FULL.getText());
44 return; 44 return;
45 } 45 }
46 46
47 game.getPlayer().getCurrentRoom().removeItem(item); 47 game.getPlayer().getCurrentRoom().removeItem(item);
48 game.getPlayer().addItem(item); 48 game.getPlayer().getInventory().putItem(item);
49 49
50 } 50 }
51 51
diff --git a/src/esieequest/controller/commands/UseCommand.java b/src/esieequest/controller/commands/UseCommand.java
index 56eaf00..00fc234 100644
--- a/src/esieequest/controller/commands/UseCommand.java
+++ b/src/esieequest/controller/commands/UseCommand.java
@@ -22,12 +22,12 @@ public class UseCommand implements Executable {
22 return; 22 return;
23 } 23 }
24 24
25 if (!game.getPlayer().hasItem(itemName)) { 25 if (!game.getPlayer().getInventory().hasItem(itemName)) {
26 view.echo(Text.NO_SUCH_ITEM.getText()); 26 view.echo(Text.NO_SUCH_ITEM.getText());
27 return; 27 return;
28 } 28 }
29 29
30 final Item item = game.getPlayer().getItem(itemName); 30 final Item item = game.getPlayer().getInventory().getItem(itemName);
31 item.use(game, view); 31 item.use(game, view);
32 32
33 } 33 }
diff --git a/src/esieequest/controller/utils/SerialisableList.java b/src/esieequest/controller/utils/SerialisableList.java
new file mode 100644
index 0000000..8e2cb78
--- /dev/null
+++ b/src/esieequest/controller/utils/SerialisableList.java
@@ -0,0 +1,27 @@
1package esieequest.controller.utils;
2
3import org.json.simple.JSONArray;
4
5/**
6 * Represents an Object that can be serialised and deserialised.
7 *
8 * @author Pacien TRAN-GIRARD
9 */
10public interface SerialisableList {
11
12 /**
13 * Serialises to a JSONObject.
14 *
15 * @return the JSONObject
16 */
17 public JSONArray serialise();
18
19 /**
20 * Deserialises from a JSONObject.
21 *
22 * @param o
23 * the JSONObject
24 */
25 public void deserialise(final JSONArray o);
26
27}
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java
index 05fdcd2..bdcc698 100644
--- a/src/esieequest/model/Game.java
+++ b/src/esieequest/model/Game.java
@@ -178,7 +178,7 @@ public class Game implements SerialisableObject {
178 * the Item 178 * the Item
179 */ 179 */
180 private void i(final Room room, final Direction direction, final Item item) { 180 private void i(final Room room, final Direction direction, final Item item) {
181 room.getSide(direction).setItem(item); 181 room.getSide(direction).getInventory().putItem(item);
182 } 182 }
183 183
184 /** 184 /**
diff --git a/src/esieequest/model/Player.java b/src/esieequest/model/Player.java
index 68930e2..a0066dc 100644
--- a/src/esieequest/model/Player.java
+++ b/src/esieequest/model/Player.java
@@ -1,20 +1,17 @@
1package esieequest.model; 1package esieequest.model;
2 2
3import java.util.ArrayList;
4import java.util.Stack; 3import java.util.Stack;
5 4
6import lombok.Getter; 5import lombok.Getter;
7import lombok.Setter; 6import lombok.Setter;
8import net.pacien.util.CleanJSONObject; 7import net.pacien.util.CleanJSONObject;
9import net.pacien.util.IntrinsicMap;
10 8
11import org.json.simple.JSONArray; 9import org.json.simple.JSONArray;
12import org.json.simple.JSONObject; 10import org.json.simple.JSONObject;
13 11
14import esieequest.controller.utils.EnumUtils; 12import esieequest.controller.utils.EnumUtils;
15import esieequest.controller.utils.ListUtils;
16import esieequest.controller.utils.SerialisableObject; 13import esieequest.controller.utils.SerialisableObject;
17import esieequest.model.items.Item; 14import esieequest.model.items.Inventory;
18import esieequest.model.map.Direction; 15import esieequest.model.map.Direction;
19import esieequest.model.map.Room; 16import esieequest.model.map.Room;
20import esieequest.model.map.Side; 17import esieequest.model.map.Side;
@@ -40,8 +37,9 @@ public class Player implements SerialisableObject {
40 @Setter 37 @Setter
41 private Direction currentDirection; 38 private Direction currentDirection;
42