diff options
author | Pacien TRAN-GIRARD | 2014-04-06 13:23:02 +0000 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-04-06 13:23:02 +0000 |
commit | 7cec06bea8172ceb7d819f4d2d4474585200c74d (patch) | |
tree | f1187e4160d8ef8abff7e99fa772656b8179d750 | |
parent | 52b649c665ac9f35b3e4d553bd964442dc5224c1 (diff) | |
parent | 013f9175a9ad8f103d439e1b7e61efd1e2cd43e0 (diff) | |
download | esieequest-7cec06bea8172ceb7d819f4d2d4474585200c74d.tar.gz |
Merge branch 'zuul-with-items' into 'master'
Zuul With Items
29 files changed, 431 insertions, 171 deletions
diff --git a/report/progression.tex b/report/progression.tex index 24c5d7a..94cc5b5 100644 --- a/report/progression.tex +++ b/report/progression.tex | |||
@@ -266,20 +266,48 @@ to win the game. | |||
266 | 266 | ||
267 | \subsection{Player} | 267 | \subsection{Player} |
268 | 268 | ||
269 | The current room and the previous rooms were moved from Game to Player with | ||
270 | commit 92f671b84. | ||
271 | |||
269 | \subsection{take, drop} | 272 | \subsection{take, drop} |
270 | 273 | ||
274 | The take and drop commands were implemented as part of the commit number | ||
275 | 5ddb6df63. An Inventory interface, used by the Room and Player classes, was | ||
276 | added. Items are stored using HashMaps, and a moveItem procedure was added to | ||
277 | the Performer. | ||
278 | |||
271 | \subsection{Carry several items} | 279 | \subsection{Carry several items} |
272 | 280 | ||
281 | Multiple items carrying was already implemented in the commit number 5ddb6df63. | ||
282 | |||
273 | \subsection{ItemList} | 283 | \subsection{ItemList} |
274 | 284 | ||
285 | The ItemList was implemented as the Inventory class in commit number db2c22c9b. | ||
286 | The Inventory is no longer an interface. | ||
287 | |||
275 | \subsection{Maximum weight} | 288 | \subsection{Maximum weight} |
276 | 289 | ||
290 | The maximum carryable weight was implement with the commit number b8771ccb2. | ||
291 | In order to achieve this, a getTotalWeight() function was added to the Inventory | ||
292 | class. | ||
293 | |||
277 | \subsection{Inventory} | 294 | \subsection{Inventory} |
278 | 295 | ||
296 | The player's inventory items listing was implemented with the commit number | ||
297 | a3f6ce16e, using the recently added listing utility class. | ||
298 | |||
279 | \subsection{Magic cookie} | 299 | \subsection{Magic cookie} |
280 | 300 | ||
301 | Since there are already too many commands, the carryable weight | ||
302 | expansion was implemented in a smarter way using a negative weight | ||
303 | item in the commit number 35ee3b1ee. | ||
304 | We could have instead increased the maximum carryable weight with a setter on | ||
305 | the Player class, called by the Performer with the ``eat'' command. | ||
306 | |||
281 | \subsection{Tests} | 307 | \subsection{Tests} |
282 | 308 | ||
309 | The commands test file was updated in the commit number 7b610fc05. | ||
310 | |||
283 | 311 | ||
284 | \section{Zuul with enums} | 312 | \section{Zuul with enums} |
285 | 313 | ||
diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java index 586b329..5c60f6d 100644 --- a/src/esieequest/controller/Interpreter.java +++ b/src/esieequest/controller/Interpreter.java | |||
@@ -1,7 +1,7 @@ | |||
1 | package esieequest.controller; | 1 | package esieequest.controller; |
2 | 2 | ||
3 | import esieequest.model.Game; | 3 | import esieequest.model.Game; |
4 | import esieequest.model.command.Command; | 4 | import esieequest.model.commands.Command; |
5 | import esieequest.view.View; | 5 | import esieequest.view.View; |
6 | 6 | ||
7 | /** | 7 | /** |
@@ -69,8 +69,14 @@ class Interpreter { | |||
69 | case "look": | 69 | case "look": |
70 | this.performer.look(); | 70 | this.performer.look(); |
71 | return; | 71 | return; |
72 | case "eat": | 72 | case "inventory": |
73 | this.performer.eat(); | 73 | this.performer.listItems(); |
74 | return; | ||
75 | case "take": | ||
76 | this.performer.take(command.getOption()); | ||
77 | return; | ||
78 | case "drop": | ||
79 | this.performer.drop(command.getOption()); | ||
74 | return; | 80 | return; |
75 | case "help": | 81 | case "help": |
76 | this.performer.showHelp(); | 82 | this.performer.showHelp(); |
@@ -83,4 +89,5 @@ class Interpreter { | |||
83 | this.performer.echo("Unknown command."); | 89 | this.performer.echo("Unknown command."); |
84 | return; | 90 | return; |
85 | } | 91 | } |
92 | |||
86 | } | 93 | } |
diff --git a/src/esieequest/controller/Parser.java b/src/esieequest/controller/Parser.java index 0f97fd1..452c27c 100644 --- a/src/esieequest/controller/Parser.java +++ b/src/esieequest/controller/Parser.java | |||
@@ -1,6 +1,6 @@ | |||
1 | package esieequest.controller; | 1 | package esieequest.controller; |
2 | 2 | ||
3 | import esieequest.model.command.Command; | 3 | import esieequest.model.commands.Command; |
4 | 4 | ||
5 | /** | 5 | /** |
6 | * The command parser. | 6 | * The command parser. |
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java index 27cbf14..8f8afeb 100644 --- a/src/esieequest/controller/Performer.java +++ b/src/esieequest/controller/Performer.java | |||
@@ -1,7 +1,8 @@ | |||
1 | package esieequest.controller; | 1 | package esieequest.controller; |
2 | 2 | ||
3 | import esieequest.model.Game; | 3 | import esieequest.model.Game; |
4 | import esieequest.model.Room; | 4 | import esieequest.model.items.Inventory; |
5 | import esieequest.model.map.Room; | ||
5 | import esieequest.view.View; | 6 | import esieequest.view.View; |
6 | 7 | ||
7 | /** | 8 | /** |
@@ -99,10 +100,10 @@ class Performer { | |||
99 | * the direction of the new room | 100 | * the direction of the new room |
100 | */ | 101 | */ |
101 | public void goTo(final String direction) { | 102 | public void goTo(final String direction) { |
102 | final Room nextRoom = this.game.getRoomExit(direction); | 103 | final Room nextRoom = this.game.getPlayer().getCurrentRoom().getExit(direction); |
103 | if (nextRoom != null) { | 104 | if (nextRoom != null) { |
104 | this.game.goToRoom(nextRoom); | 105 | this.game.getPlayer().goToRoom(nextRoom); |
105 | this.view.updateRoom(this.game.getCurrentRoom()); | 106 | this.view.updateRoom(this.game.getPlayer().getCurrentRoom()); |
106 | } else { | 107 | } else { |
107 | this.echo(this.game.getNoExitMessage()); | 108 | this.echo(this.game.getNoExitMessage()); |
108 | } | 109 | } |
@@ -112,22 +113,69 @@ class Performer { | |||
112 | * Changes the current room to the previous one. | 113 | * Changes the current room to the previous one. |
113 | */ | 114 | */ |
114 | public void goBack() { | 115 | public void goBack() { |
115 | this.game.goToPreviousRoom(); | 116 | this.game.getPlayer().goToPreviousRoom(); |
116 | this.view.updateRoom(this.game.getCurrentRoom()); | 117 | this.view.updateRoom(this.game.getPlayer().getCurrentRoom()); |
117 | } | 118 | } |
118 | 119 | ||
119 | /** | 120 | /** |
120 | * Displays informations about the current place. | 121 | * Displays informations about the current place. |
121 | */ | 122 | */ |
122 | public void look() { | 123 | public void look() { |
123 | this.echo(this.game.getCurrentRoom().getInformations()); | 124 | this.echo(this.game.getPlayer().getCurrentRoom().getInformations()); |
124 | } | 125 | } |
125 | 126 | ||
126 | /** | 127 | /** |
127 | * Displays a special message. | 128 | * Moves an item from the current Room to the Player's inventory. |
129 | * | ||
130 | * @param itemName | ||
131 | * the item's name | ||
132 | */ | ||
133 | public void take(final String itemName) { | ||
134 | int weight = this.game.getPlayer().getInventory().getTotalWeight(); | ||
135 | weight += this.game.getPlayer().getCurrentRoom().getItems().getItemWeight(itemName); | ||
136 | final int maxWeight = this.game.getPlayer().getMaxCarryWeight(); | ||
137 | |||
138 | if (weight >= maxWeight) { | ||
139 | this.echo("Maximum inventory weight reached. Cannot pick up item."); | ||
140 | return; | ||
141 | } | ||
142 | |||