diff options
Diffstat (limited to 'src/esieequest/engine/commands/DoCommand.java')
-rw-r--r-- | src/esieequest/engine/commands/DoCommand.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/esieequest/engine/commands/DoCommand.java b/src/esieequest/engine/commands/DoCommand.java new file mode 100644 index 0000000..e6b5936 --- /dev/null +++ b/src/esieequest/engine/commands/DoCommand.java | |||
@@ -0,0 +1,40 @@ | |||
1 | package esieequest.engine.commands; | ||
2 | |||
3 | import esieequest.game.Game; | ||
4 | import esieequest.game.Text; | ||
5 | import esieequest.game.map.Side; | ||
6 | import esieequest.ui.Viewable; | ||
7 | |||
8 | /** | ||
9 | * A shortcut Command that executes a TALK or a TAKE Command accordingly to the | ||
10 | * context. | ||
11 | * | ||
12 | * @author Pacien TRAN-GIRARD | ||
13 | */ | ||
14 | public class DoCommand implements Executable { | ||
15 | |||
16 | @Override | ||
17 | public void execute(final String argument, final Game game, final Viewable view) { | ||
18 | |||
19 | if (!argument.isEmpty()) { | ||
20 | view.echo(Text.TOO_MANY_ARGUMENTS.toString()); | ||
21 | return; | ||
22 | } | ||
23 | |||
24 | final Side currentSide = game.getPlayer().getCurrentSide(); | ||
25 | |||
26 | if (currentSide.hasCharacter()) { | ||
27 | Command.TALK.execute(argument, game, view); | ||
28 | return; | ||
29 | } | ||
30 | |||
31 | if (currentSide.getInventory().getSize() == 1) { | ||
32 | Command.TAKE.execute(argument, game, view); | ||
33 | return; | ||
34 | } | ||
35 | |||
36 | view.echo(Text.NOTHING_TO_DO.toString()); | ||
37 | |||
38 | } | ||
39 | |||
40 | } | ||