View Javadoc

1   package erland.game.tileadventure;
2   /*
3    * Copyright (C) 2004 Erland Isaksson (erland_i@hotmail.com)
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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          //TODO: abstract ?
79          return true;
80      }
81  }