-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHero.java
122 lines (99 loc) · 2.76 KB
/
Hero.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
public abstract class Hero implements BattleReady{
private int health;
private int level;
private int experience;
private int maxHealth;
private int nextLevelExperience;
private Inventory inventory;
public Hero() {
this.health = 100;
this.level = 1;
this.experience = 0;
this.maxHealth = 100;
this.nextLevelExperience = 100;
this.inventory = new Inventory();
}
public Hero(int health, int level, int experience, int maxHealth, int nextLevelExperience, Inventory inventory) {
this.health = health;
this.level = level;
this.experience = experience;
this.maxHealth = maxHealth;
this.nextLevelExperience = nextLevelExperience;
this.inventory = inventory;
}
public boolean usePotion(int size) {
boolean out = inventory.usePotion(size);
if (out == true) {
if (size == 1) {
health += 10;
} else if (size == 2) {
health += 50;
} else if (size == 3) {
health += 100;
}
if (health > maxHealth) {
health = maxHealth;
}
}
return out;
}
public boolean takeDamage(int amount) {
health -= amount;
if (health < 1) {
return false;
}
return true;
}
public boolean gainExperience(int amount) {
experience += amount;
if (experience > this.nextLevelExperience) {
experience = 0;
incrementLevel();
return true;
}
return false;
}
public void setHealth(int health) {
this.health = health;
}
public void setMaxHealth(int maxHealth) {
this.maxHealth = maxHealth;
}
public void setExperience(int experience) {
this.experience = experience;
}
public void incrementLevel()
{
level += 1;
upgradeStats();
this.nextLevelExperience = this.nextLevelExperience * 2;
}
public void addPotions(Inventory otherInventory){
this.inventory.addPotions(otherInventory);
}
public int getHealth() {
return this.health;
}
public int getLevel() {
return this.level;
}
public int getMaxHealth() {
return this.maxHealth;
}
public int getExperience() {
return this.experience;
}
public Inventory getInventory() {
return this.inventory;
}
public int getNextLevelExperience() {
return nextLevelExperience;
}
public int attack()
{
return (int)(Math.random() * 100 * this.level);
}
public abstract void display();
public abstract void upgradeStats();
public abstract String getName();
}