-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
54 lines (46 loc) · 1.16 KB
/
Player.java
File metadata and controls
54 lines (46 loc) · 1.16 KB
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
public class Player {
// Default attributes
private String username;
private int exp;
private int level;
private int coins;
// Constructor
public Player(String username) {
this.username = username;
this.exp = 0;
this.level = 1; // default level
this.coins = 100; // Starting coins
}
public String getUsername() {
return username;
}
public int getCoins() {
return coins;
}
public int getLevel() {
return level;
}
public int getExp() {
return exp;
}
public void setCoins(int coins) {
this.coins = coins;
}
public void setUsername(String username) {
this.username = username;
}
public void reward(int expReward, int coinReward) {
this.exp += expReward;
this.coins += coinReward;
levelUp();
}
private void levelUp() {
if (this.exp >= 100) {
this.level++;
this.exp = 0; // Reset experience for next level
}
}
public void deductCoins(int amount) {
this.coins -= amount;
}
}