-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
44 lines (35 loc) · 766 Bytes
/
Player.java
File metadata and controls
44 lines (35 loc) · 766 Bytes
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
import javax.swing.ImageIcon;
public class Player extends GameObject {
private boolean key;
public Player(Level level) {
super(level, null);
setIcon(new ImageIcon(getClass().getResource("Player.png")));
key = false;
}
@Override
public void process(Player p) {
return;
}
public void move(int direction) {
Location loc = getLocation().getAdjacentLocation(direction);
Level level = getLevel();
if (!level.isValid(loc))
return;
GameObject obj = level.get(loc);
if (obj == null) {
level.remove(getLocation());
level.set(loc, this);
} else
obj.process(this);
level.changeVisibility();
}
public boolean hasKey() {
return key;
}
public void giveKey() {
key = true;
}
public void takeKey() {
key = false;
}
}