blob: e09ad916699b0d0c7c7e06a2240f7dbb8fdcb3f8 (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
package esieequest.controller;
import esieequest.model.Game;
import esieequest.model.commands.Command;
import esieequest.view.View;
/**
* The command interpreter.
*
* @author Pacien TRAN-GIRARD
* @author Benoît LUBRANO DI SBARAGLIONE
*/
class Interpreter {
private final Performer performer;
private final Parser parser;
/**
* Instantiates the Interpreter.
*
* @param game
* the Game model
* @param view
* the View
*/
public Interpreter(final Game game, final View view) {
this.performer = new Performer(game, view);
this.parser = new Parser();
}
/**
* Interprets a command.
*
* @param commandString
* the command String
*/
public void interpret(final String commandString) {
final Command command = this.parser.getCommand(commandString);
this.dispatch(command);
}
/**
* Dispatches to the method associated with the command's action.
*
* @param command
* the command
*/
public void dispatch(final Command command) {
if (command.getAction() != null) {
switch (command.getAction()) {
// game related:
case NEW:
this.performer.newGame();
return;
case LOAD:
this.performer.loadGame();
return;
case SAVE:
this.performer.saveGame();
return;
case QUIT:
this.performer.quitGame();
return;
case SOUND:
this.performer.toggleSound();
return;
case HELP:
this.performer.showHelp();
return;
// map related:
case GO:
this.performer.goTo(command.getOption());
return;
case BACK:
this.performer.goBack();
return;
case LOOK:
this.performer.look();
return;
// items related:
case INVENTORY:
this.performer.listItems();
return;
case TAKE:
this.performer.takeItem(command.getOption());
return;
case DROP:
this.performer.dropItem(command.getOption());
return;
case USE:
this.performer.useItem(command.getOption());
return;
}
}
this.performer.echo("Unknown command.");
return;
}
}
|