-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
70 lines (59 loc) · 1.7 KB
/
Player.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.awt.*;
/** Contains information about the player */
public class Player extends Unit {
int xp;
int surges;
Player(int row, int col, Map map, Info info) {
super(0, row, col, map, info);
surges = 0;
}
/** Player is super fast for testing */
public int getSpeed() {
return 1000;
}
/** This still needs to account for items and other bonuses */
public int getMaxHealth() {
return 1000 + 300 * level;
}
/** Returns the character that should be used to represent the player */
public char getChar() {
return '@';
}
/** Returns the character colour that should be used to represent the player */
public CharCol getCharCol() {
return new CharCol(Color.RED);
}
public void giveXp(int xp) {
if(level < 100) {
this.xp += xp;
if(this.xp >= Player.xpLevel(getLevel())) {
this.xp -= Player.xpLevel(getLevel());
setLevel(getLevel() + 1);
info.g.postMessage("Level up! You are now level " + getLevel(), new CharCol(Color.GREEN));
}
} else {
xp = 0;
}
}
public int getXp() {
return xp;
}
public void spendSurge() {
if(surges > 0) {
if(getHealth() < getMaxHealth()) {
heal(getMaxHealth() - getHealth());
surges--;
info.g.postMessage("Healed to full health.", new CharCol(Color.GREEN));
} else
info.g.postMessage("You're already at full health.", new CharCol(Color.GREEN));
} else {
info.g.postMessage("You're out of health surges.", new CharCol(Color.RED));
}
}
public void setSurges(int s) {
surges = s;
}
public static int xpLevel(int lev) {
return (int)Math.round(100 * Math.pow(2, lev / 20.0));
}
}