1   package erland.game.tileadventure;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  public class Action implements ActionInterface {
22      private ControllerInterface controller;
23      private boolean isRunning;
24  
25      protected Action() {}
26      public final static Action NONE = new Action();
27      public final static Action MOVE_WEST = new Action();
28      public final static Action MOVE_EAST = new Action();
29      public final static Action MOVE_NORTH = new Action();
30      public final static Action MOVE_SOUTH = new Action();
31      public final static Action MOVE_DOWN = new Action();
32  
33      public final static Action PUSH_WEST = new Action();
34      public final static Action PUSH_EAST = new Action();
35      public final static Action PUSH_NORTH = new Action();
36      public final static Action PUSH_SOUTH = new Action();
37  
38      public final static Action JUMP = new Action();
39  
40      public final static ActionInterface DROP = new Action();
41  
42      public boolean isMove() {
43          return this==MOVE_WEST || this==MOVE_EAST || this==MOVE_NORTH || this==MOVE_SOUTH || this==MOVE_DOWN;
44      }
45      public boolean isPush() {
46          return this==PUSH_WEST || this==PUSH_EAST || this==PUSH_NORTH || this==PUSH_SOUTH;
47      }
48      public Direction getDirection() {
49          if(this==MOVE_WEST||this==PUSH_WEST) {
50              return Direction.WEST;
51          }else if(this==MOVE_EAST||this==PUSH_EAST) {
52              return Direction.EAST;
53          }else if(this==MOVE_NORTH||this==PUSH_NORTH) {
54              return Direction.NORTH;
55          }else if(this==MOVE_SOUTH||this==PUSH_SOUTH) {
56              return Direction.SOUTH;
57          }else if(this==MOVE_DOWN) {
58              return Direction.DOWN;
59          }else {
60              return null;
61          }
62      }
63  
64      public void setController(ControllerInterface controller) {
65          this.controller = controller;
66      }
67      public ControllerInterface getController() {
68          return controller;
69      }
70      public void start() {
71          isRunning = true;
72      }
73      public void stop() {
74          isRunning = false;
75          getController().stopped(this);
76      }
77      public boolean perform() {
78          
79          return true;
80      }
81  }