blob: a68f5ad86034d843cdabac2e5a9d9078962a7e10 (
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
|
package esieequest.controller.commands;
import esieequest.model.Game;
import esieequest.model.Text;
import esieequest.model.doors.Door;
import esieequest.model.map.Direction;
import esieequest.view.Viewable;
/**
* Allows the user to move from connected Room-s to Room-s by giving the
* Direction.
*
* @author Pacien TRAN-GIRARD
*/
public class GoCommand implements Executable {
@Override
public void execute(final String argument, final Game game, final Viewable view) {
final Direction direction;
try {
direction = Direction.valueOf(argument.toUpperCase());
} catch (final Exception exception) {
view.echo(Text.NO_SUCH_DIRECTION.toString());
return;
}
final Door door = game.getPlayer().getCurrentRoom().getSide(direction).getDoor();
if (door == null) {
view.echo(Text.NO_DOOR.toString());
return;
}
final boolean crossed = door.cross(game, view);
if (!crossed) {
return;
}
view.updateLocation(game.getPlayer().getCurrentRoom(), direction, game.getPlayer()
.getCurrentSide(), game.getPlayer().canGoBack());
// handle challenge mode
if (game.getPlayer().walk()) {
view.echo(Text.CHALLENGE_FAILED.toString());
view.disableInput();
}
}
}
|