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 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
118 }else if(bMoveRight) {
119 actionHandler.register(new MoveAction(this,MoveAction.EAST));
120
121 }else if(bMoveDown) {
122 actionHandler.register(new MoveAction(this,MoveAction.SOUTH));
123
124 }else if(bMoveUp) {
125 actionHandler.register(new MoveAction(this,MoveAction.NORTH));
126
127 }else {
128 actionHandler.register(new MoveAction(this,MoveAction.NONE));
129 }
130
131
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
158 }
159 }