aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-04-15 20:50:06 +0200
committerPacien TRAN-GIRARD2014-04-15 20:50:06 +0200
commit6a154d2feb6722cb0395bb1e69af2be5a76cdacc (patch)
tree7f58218131f1e1c5d19eed63f61d75212d93009a /src
parent35d771f9f0e96304fd37a046dffe480a26795e44 (diff)
downloadesieequest-6a154d2feb6722cb0395bb1e69af2be5a76cdacc.tar.gz
Implement the Beamer
Diffstat (limited to 'src')
-rw-r--r--src/esieequest/controller/Interpreter.java24
-rw-r--r--src/esieequest/controller/Parser.java2
-rw-r--r--src/esieequest/controller/Performer.java27
-rw-r--r--src/esieequest/model/Game.java17
-rw-r--r--src/esieequest/model/items/Beamer.java41
-rw-r--r--src/esieequest/model/items/Inventory.java12
6 files changed, 105 insertions, 18 deletions
diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java
index 32adeda..e09ad91 100644
--- a/src/esieequest/controller/Interpreter.java
+++ b/src/esieequest/controller/Interpreter.java
@@ -48,6 +48,8 @@ class Interpreter {
48 public void dispatch(final Command command) { 48 public void dispatch(final Command command) {
49 if (command.getAction() != null) { 49 if (command.getAction() != null) {
50 switch (command.getAction()) { 50 switch (command.getAction()) {
51
52 // game related:
51 case NEW: 53 case NEW:
52 this.performer.newGame(); 54 this.performer.newGame();
53 return; 55 return;
@@ -57,9 +59,17 @@ class Interpreter {
57 case SAVE: 59 case SAVE:
58 this.performer.saveGame(); 60 this.performer.saveGame();
59 return; 61 return;
62 case QUIT:
63 this.performer.quitGame();
64 return;
60 case SOUND: 65 case SOUND:
61 this.performer.toggleSound(); 66 this.performer.toggleSound();
62 return; 67 return;
68 case HELP:
69 this.performer.showHelp();
70 return;
71
72 // map related:
63 case GO: 73 case GO:
64 this.performer.goTo(command.getOption()); 74 this.performer.goTo(command.getOption());
65 return; 75 return;
@@ -69,25 +79,23 @@ class Interpreter {
69 case LOOK: 79 case LOOK:
70 this.performer.look(); 80 this.performer.look();
71 return; 81 return;
82
83 // items related:
72 case INVENTORY: 84 case INVENTORY:
73 this.performer.listItems(); 85 this.performer.listItems();
74 return; 86 return;
75 case TAKE: 87 case TAKE:
76 this.performer.take(command.getOption()); 88 this.performer.takeItem(command.getOption());
77 return; 89 return;
78 case DROP: 90 case DROP:
79 this.performer.drop(command.getOption()); 91 this.performer.dropItem(command.getOption());
80 return; 92 return;
81 case HELP: 93 case USE:
82 this.performer.showHelp(); 94 this.performer.useItem(command.getOption());
83 return;
84 case QUIT:
85 this.performer.quitGame();
86 return; 95 return;
87 } 96 }
88 } 97 }
89 this.performer.echo("Unknown command."); 98 this.performer.echo("Unknown command.");
90 return; 99 return;
91 } 100 }
92
93} 101}
diff --git a/src/esieequest/controller/Parser.java b/src/esieequest/controller/Parser.java
index 7b07efb..d13f940 100644
--- a/src/esieequest/controller/Parser.java
+++ b/src/esieequest/controller/Parser.java
@@ -25,7 +25,7 @@ class Parser {
25 * @return the command 25 * @return the command
26 */ 26 */
27 public Command getCommand(final String commandString) { 27 public Command getCommand(final String commandString) {
28 final String[] elements = commandString.split(" "); 28 final String[] elements = commandString.split(" ", 2);
29 29
30 CommandWord action = null; 30 CommandWord action = null;
31 String option = null; 31 String option = null;
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java
index b5c32ba..add3fe5 100644
--- a/src/esieequest/controller/Performer.java
+++ b/src/esieequest/controller/Performer.java
@@ -5,7 +5,9 @@ import java.util.Set;
5 5
6import esieequest.model.Game; 6import esieequest.model.Game;
7import esieequest.model.commands.CommandWord; 7import esieequest.model.commands.CommandWord;
8import esieequest.model.items.Beamer;
8import esieequest.model.items.Inventory; 9import esieequest.model.items.Inventory;
10import esieequest.model.items.Item;
9import esieequest.model.map.Door; 11import esieequest.model.map.Door;
10import esieequest.model.map.Room; 12import esieequest.model.map.Room;
11import esieequest.model.map.TrapDoor; 13import esieequest.model.map.TrapDoor;
@@ -152,7 +154,12 @@ class Performer {
152 * @param itemName 154 * @param itemName
153 * the item's name 155 * the item's name
154 */ 156 */
155 public void take(final String itemName) { 157 public void takeItem(final String itemName) {
158 if (!this.game.getPlayer().getCurrentRoom().getItems().hasItem(itemName)) {
159 this.echo("No such item in this room.");
160 return;
161 }
162
156 int weight = this.game.getPlayer().getInventory().getTotalWeight(); 163 int weight = this.game.getPlayer().getInventory().getTotalWeight();
157 weight += this.game.getPlayer().getCurrentRoom().getItems().getItemWeight(itemName); 164 weight += this.game.getPlayer().getCurrentRoom().getItems().getItemWeight(itemName);
158 final int maxWeight = this.game.getPlayer().getMaxCarryWeight(); 165 final int maxWeight = this.game.getPlayer().getMaxCarryWeight();
@@ -171,7 +178,7 @@ class Performer {
171 * @param itemName 178 * @param itemName
172 * the item's name 179 * the item's name
173 */ 180 */
174 public void drop(final String itemName) { 181 public void dropItem(final String itemName) {
175 this.moveItem(this.game.getPlayer().getInventory(), this.game.getPlayer().getCurrentRoom().getItems(), itemName); 182 this.moveItem(this.game.getPlayer().getInventory(), this.game.getPlayer().getCurrentRoom().getItems(), itemName);
176 } 183 }
177 184
@@ -200,4 +207,20 @@ class Performer {
200 this.echo(Utils.list(this.game.getPlayer().getInventory().getItemList(), "Items:", "No item in your inventory.")); 207 this.echo(Utils.list(this.game.getPlayer().getInventory().getItemList(), "Items:", "No item in your inventory."));
201 } 208 }
202 209
210 public void useItem(final String itemName) {
211 final Item item = this.game.getPlayer().getInventory().getItem(itemName);
212 if (item == null) {
213 this.echo("You don't have such item.");
214 return;
215 }
216 if (item.getClass() == Beamer.class) {
217 final Beamer beamer = (Beamer) item;
218 if (beamer.getRoom() == null) {
219 beamer.setRoom(this.game.getPlayer().getCurrentRoom());
220 } else {
221 this.game.getPlayer().goToRoom(beamer.getRoom());
222 }
223 }
224 }
225
203} 226}
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java
index 83fa143..6e6b191 100644
--- a/src/esieequest/model/Game.java
+++ b/src/esieequest/model/Game.java
@@ -3,6 +3,7 @@ package esieequest.model;
3import java.util.HashMap; 3import java.util.HashMap;
4 4
5import esieequest.model.entities.Player; 5import esieequest.model.entities.Player;
6import esieequest.model.items.Beamer;
6import esieequest.model.items.Item; 7import esieequest.model.items.Item;
7import esieequest.model.map.Door; 8import esieequest.model.map.Door;
8import esieequest.model.map.Room; 9import esieequest.model.map.Room;
@@ -90,7 +91,7 @@ public class Game {
90 this.createRoom("OffscriptItems", "somewhere implementing weight"); 91 this.createRoom("OffscriptItems", "somewhere implementing weight");
91 this.createRoom("OffscriptItemsStorageroom", "in a storage room"); 92 this.createRoom("OffscriptItemsStorageroom", "in a storage room");
92 this.createRoom("OffscriptTeleportation", "somewhere implementing teleportation"); 93 this.createRoom("OffscriptTeleportation", "somewhere implementing teleportation");
93 this.createRoom("OffscriptTeleportationAnchorroom", "on a checkpoint"); 94 this.createRoom("OffscriptTeleportationBeamerroom", "on a checkpoint");
94 this.createRoom("OffscriptAlea", "somewhere implementing alea"); 95 this.createRoom("OffscriptAlea", "somewhere implementing alea");
95 this.createRoom("OffscriptAleaRandomizingroom", "in a weird room that will transport you somewhere else"); 96 this.createRoom("OffscriptAleaRandomizingroom", "in a weird room that will transport you somewhere else");
96 this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character"); 97 this.createRoom("OffscriptMovingcharacter", "somewhere implementing a moving character");
@@ -171,10 +172,10 @@ public class Game {
171 this.setRoomExit("OffscriptItems", "north", "OffscriptItemsStorageroom"); 172 this.setRoomExit("OffscriptItems", "north", "OffscriptItemsStorageroom");
172 this.setRoomExit("OffscriptItems", "east", "OffscriptTeleportation"); 173 this.setRoomExit("OffscriptItems", "east", "OffscriptTeleportation");
173 this.setRoomExit("OffscriptItemsStorageroom", "south", "OffscriptItems"); 174 this.setRoomExit("OffscriptItemsStorageroom", "south", "OffscriptItems");
174 this.setRoomExit("OffscriptTeleportation", "north", "OffscriptTeleportationAnchorroom"); 175 this.setRoomExit("OffscriptTeleportation", "north", "OffscriptTeleportationBeamerroom");
175 this.setRoomExit("OffscriptTeleportation", "west", "OffscriptTime"); 176 this.setRoomExit("OffscriptTeleportation", "west", "OffscriptItems");
176 this.setRoomExit("OffscriptTeleportation", "east", "OffscriptAlea"); 177 this.setRoomExit("OffscriptTeleportation", "east", "OffscriptAlea");
177 this.setRoomExit("OffscriptTeleportationAnchorroom", "south", "OffscriptTeleportation"); 178 this.setRoomExit("OffscriptTeleportationBeamerroom", "south", "OffscriptTeleportation");
178 this.setRoomExit("OffscriptAlea", "north", "OffscriptAleaRandomizingroom"); 179 this.setRoomExit("OffscriptAlea", "north", "OffscriptAleaRandomizingroom");
179 this.setRoomExit("OffscriptAlea", "west", "OffscriptTeleportation"); 180 this.setRoomExit("OffscriptAlea", "west", "OffscriptTeleportation");
180 this.setRoomExit("OffscriptAlea", "east", "OffscriptMovingcharacter"); 181 this.setRoomExit("OffscriptAlea", "east", "OffscriptMovingcharacter");
@@ -188,9 +189,11 @@ public class Game {
188 * Creates and adds items into rooms. 189 * Creates and adds items into rooms.
189 */ 190 */
190 private void createItems() { 191 private void createItems() {
191 this.rooms.get("Cafeteria").getItems().putItem("banana", new Item("A yellow banana", 5)); 192 this.rooms.get("OffscriptItemsStorageroom").getItems().putItem("Weighted Storage Cube", new Item("A Weighted Storage Cube.", 5));
192 this.rooms.get("Cafeteria").getItems().putItem("orange", new Item("An orange orange", 6)); 193 this.rooms.get("OffscriptItemsStorageroom").getItems().putItem("Edgeless Safety Cube", new Item("An Edgeless Safety Cube.", 5));
193 this.rooms.get("Cafeteria").getItems().putItem("anti-matter", new Item("A block of anti-matter with a negative