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  import erland.game.GamePlayerInterface;
22  import erland.game.GameEnvironmentInterface;
23  import erland.network.NetworkConnectionInterface;
24  
25  /***
26   * Implementation of control of the user player
27   */
28  public class TileAdventurePlayer implements GamePlayerInterface, ControllerInterface {
29      /*** Connection to client if networked game */
30      private NetworkConnectionInterface connection;
31      /*** Indicates if the user is moving right */
32      private boolean bMoveRight;
33      /*** Indicates if the user is moving  left */
34      private boolean bMoveLeft;
35      /*** Indicates if the user is moving up */
36      private boolean bMoveUp;
37      /*** Indicates if the user is moving down */
38      private boolean bMoveDown;
39      /*** Indicates if the user should jump */
40      private boolean bJump;
41      /*** The object that represents the player */
42      private GameObject playerObject;
43      /*** The object that manages all actions */
44      private ActionHandlerInterface actionHandler;
45  
46      /***
47       * Create player object
48       * @param environment Game environment
49       * @param playerNo Player number (if networked game)
50       */
51      public TileAdventurePlayer(GameEnvironmentInterface environment, int playerNo) {
52      }
53  
54      public void setConnection(NetworkConnectionInterface connection) {
55          this.connection = connection;
56      }
57      public NetworkConnectionInterface getConnection() {
58          return connection;
59      }
60  
61      public void setPlayerObject(GameObject object) {
62          playerObject = object;
63      }
64      public GameObject getPlayerObject() {
65          return playerObject;
66      }
67  
68      public ActionHandlerInterface getActionHandler() {
69          return actionHandler;
70      }
71  
72      public void setActionHandler(ActionHandlerInterface actionHandler) {
73          this.actionHandler = actionHandler;
74      }
75  
76      /*** Start moving right */
77      public void startMoveRight() {
78          bMoveRight = true;
79      }
80      /*** Start moving left */
81      public void startMoveLeft() {
82          bMoveLeft = true;
83      }
84      /*** Start moving up */
85      public void startMoveUp() {
86          bMoveUp = true;
87      }
88      /*** Start moving down */
89      public void startMoveDown() {
90          bMoveDown = true;
91      }
92      /*** Stop moving right */
93      public void stopMoveRight() {
94          bMoveRight = false;
95      }
96      /*** Stop moving left */
97      public void stopMoveLeft() {
98          bMoveLeft = false;
99      }
100     /*** Stop moving up */
101     public void stopMoveUp() {
102         bMoveUp = false;
103     }
104     /*** Stop moving down */
105     public void stopMoveDown() {
106         bMoveDown = false;
107     }
108 
109     /*** Jump */
110     public void jump() {
111         bJump = true;
112     }
113     public void update() {
114         if(playerObject!=null) {
115             if(bMoveLeft) {
116                 actionHandler.register(new MoveAction(this,MoveAction.WEST));
117                 //playerObject.action(Action.MOVE_WEST);
118             }else if(bMoveRight) {
119                 actionHandler.register(new MoveAction(this,MoveAction.EAST));
120                 //playerObject.action(Action.MOVE_EAST);
121             }else if(bMoveDown) {
122                 actionHandler.register(new MoveAction(this,MoveAction.SOUTH));
123                 //playerObject.action(Action.MOVE_SOUTH);
124             }else if(bMoveUp) {
125                 actionHandler.register(new MoveAction(this,MoveAction.NORTH));
126                 //playerObject.action(Action.MOVE_NORTH);
127             }else {
128                 actionHandler.register(new MoveAction(this,MoveAction.NONE));
129             }
130             //if(bJump) {
131                 //playerObject.action(Action.JUMP);
132             //}
133             bJump = false;
134         }
135     }
136     /***
137      * Check if player has completed game
138      * @return true if game is completed
139      */
140     public boolean isCompleted() {
141         return false;
142     }
143 
144     /***
145      * Check if game is over for player
146      * @return true if game is over for player
147      */
148     public boolean isGameOver() {
149         return false;
150     }
151 
152     public GameObject getControlledObject() {
153         return playerObject;
154     }
155 
156     public void stopped(ActionInterface action) {
157         //TODO: Implement
158     }
159 }