aboutsummaryrefslogtreecommitdiff
path: root/src/esieequest/controller/commands/UseCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/esieequest/controller/commands/UseCommand.java')
-rw-r--r--src/esieequest/controller/commands/UseCommand.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/esieequest/controller/commands/UseCommand.java b/src/esieequest/controller/commands/UseCommand.java
new file mode 100644
index 0000000..d8b8416
--- /dev/null
+++ b/src/esieequest/controller/commands/UseCommand.java
@@ -0,0 +1,35 @@
1package esieequest.controller.commands;
2
3import esieequest.model.Game;
4import esieequest.model.Text;
5import esieequest.model.items.Item;
6import esieequest.view.View;
7
8/**
9 * Allows the player to use an item located in his inventory.
10 *
11 * @author Pacien TRAN-GIRARD
12 */
13public class UseCommand implements CommandInterface {
14
15 @Override
16 public void execute(final String argument, final Game game, final View view) {
17
18 final String itemName = argument;
19
20 if (itemName == null) {
21 view.echo(Text.NO_ITEM_SPECIFIED.getText());
22 return;
23 }
24
25 if (!game.getPlayer().hasItem(itemName)) {
26 view.echo(Text.NO_SUCH_ITEM.getText());
27 return;
28 }
29
30 final Item item = game.getPlayer().getItem(itemName);
31 item.use(game, view);
32
33 }
34
35}