blob: 6ed2b813b22db2d4d4f22910c681ca7a0ed592a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package esieequest.controller.commands;
import esieequest.model.Game;
import esieequest.model.Text;
import esieequest.model.items.Item;
import esieequest.view.Viewable;
/**
* Allows the user to drop an Item from his inventory (referred by its name) to
* the current Room Side.
*
* @author Pacien TRAN-GIRARD
*/
public class DropCommand implements Executable {
@Override
public void execute(final String argument, final Game game, final Viewable view) {
final String itemName = argument;
if (itemName.isEmpty()) {
view.echo(Text.NO_ITEM_SPECIFIED.toString());
return;
}
if (!game.getPlayer().getInventory().hasItem(itemName)) {
view.echo(Text.NO_SUCH_ITEM.toString());
return;
}
final Item item = game.getPlayer().getInventory().takeItem(itemName);
game.getPlayer().getCurrentSide().getInventory().putItem(item);
view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer()
.getCurrentDirection(), game.getPlayer().getCurrentSide(), game.getPlayer()
.canGoBack());
view.updateInventory(game.getPlayer().getInventory());
}
}
|