aboutsummaryrefslogtreecommitdiff
path: root/src/esieequest/game/items/Item.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/esieequest/game/items/Item.java')
-rw-r--r--src/esieequest/game/items/Item.java107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/esieequest/game/items/Item.java b/src/esieequest/game/items/Item.java
new file mode 100644
index 0000000..9a20f10
--- /dev/null
+++ b/src/esieequest/game/items/Item.java
@@ -0,0 +1,107 @@
1package esieequest.game.items;
2
3import lombok.Getter;
4import net.pacien.util.Mappable;
5
6import org.json.simple.JSONArray;
7import org.json.simple.JSONObject;
8
9import esieequest.engine.utils.EnumUtils;
10import esieequest.engine.utils.SerialisableObject;
11import esieequest.game.Game;
12import esieequest.game.Text;
13import esieequest.ui.Viewable;
14
15public enum Item implements Mappable<String>, SerialisableObject {
16
17 // @formatter:off
18
19 // secret corridor
20 STORAGE_CUBE(new SimpleItem("Weighted Storage Cube", 5, true)),
21 SAFETY_CUBE(new SimpleItem("Edgeless Safety Cube", 5, true)),
22 BLACK_HOLE(new SimpleItem("Portable black-hole", -10, false)),
23
24 KEYCARD(new SimpleItem("KeyCard", 0, false)),
25
26 BEAMER(new Beamer("Beamer")),
27
28 // scenario
29 NOTE(new Note("Note", Text.NOTE_ATHANASE.toString())),
30 BANANA(new Banana()),
31 PORTABLE_CONSOLE(new PortableConsole()),
32 DISK(new Disk()),
33
34 ;
35
36 // @formatter:on
37
38 @Getter
39 private final SimpleItem item;
40
41 Item(final SimpleItem item) {
42 this.item = item;
43 }
44
45 /**
46 * Returns the description of the item.
47 *
48 * @return the description
49 */
50 public String getName() {
51 return this.item.getName();
52 }
53
54 /**
55 * Returns the weight of the item.
56 *
57 * @return the weight
58 */
59 public int getWeight() {
60 return this.item.getWeight();
61 }
62
63 /**
64 * Tells whether the item is droppable.
65 *
66 * @return the droppability of the item.
67 */
68 public boolean isDroppable() {
69 return this.item.isDroppable();
70 }
71
72 /**
73 * Performs actions when the player uses the Item.
74 *
75 * @param game
76 * the Game model
77 * @param view
78 * the View
79 */
80 public void use(final Game game, final Viewable view) {
81 this.item.use(game, view);
82 }
83
84 @Override
85 public String getKey() {
86 return this.item.getName().toLowerCase();
87 }
88
89 @Override
90 public JSONObject serialise() {
91 return this.item.serialise();
92 }
93
94 @Override
95 public void deserialise(final JSONObject o) {
96 this.item.deserialise(o);
97 }
98
99 public static JSONArray serialiseAll() {
100 return EnumUtils.serialiseEnumObjects(Item.values());
101 }
102
103 public static void deserialiseAll(final JSONArray a) {
104 EnumUtils.deserialiseEnumObjects(Item.class, a);
105 }
106
107}