-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyPlayer.java
48 lines (47 loc) · 1.37 KB
/
MyPlayer.java
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
package Game_Tank_multiplayer;
public class MyPlayer implements Player {
private Game_Tank_multiplayer.Map map;
private Game_Tank_multiplayer.Position playerPosition;
private int x;
private int y;
public MyPlayer(Game_Tank_multiplayer.Map map){
this.map = map;
playerPosition = map.getStartPosition();
}
public MyPlayer(){
}
public void setMap(Map map){
this.map = map;
}
public void moveRight(){
this.x = playerPosition.getX();
this.y = playerPosition.getY();
if(x + 1 < map.getSize() && map.getValueAt(x + 1, y) != 1){
playerPosition.setX(++x);
}
}
public void moveLeft(){
this.x = playerPosition.getX();
this.y = playerPosition.getY();
if(x > 0 && map.getValueAt(x - 1, y) != 1){
playerPosition.setX(--x);
}
}
public void moveUp(){
this.x = playerPosition.getX();
this.y = playerPosition.getY();
if(y > 0 && map.getValueAt(x, y - 1) != 1){
playerPosition.setY(--y);
}
}
public void moveDown(){
this.x = playerPosition.getX();
this.y = playerPosition.getY();
if(y + 1 < map.getSize() && map.getValueAt(x, y + 1) != 1){
playerPosition.setY(++y);
}
}
public Position getPosition(){
return playerPosition;
}
}