-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeroTeam.java
More file actions
128 lines (110 loc) · 2.67 KB
/
Copy pathHeroTeam.java
File metadata and controls
128 lines (110 loc) · 2.67 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
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
123
124
125
126
127
128
import java.util.Arrays;
public class HeroTeam {
private Hero[] heroes;
// current position
private int i, j;
public HeroTeam(int numHeroes) {
heroes = new Hero[numHeroes];
i = 0;
j = 0;
}
public Hero getHero(int idx) {
return heroes[idx];
}
public void setHero(int idx, Hero hero) {
heroes[idx] = hero;
}
public void showTeamInventory() {
for (Hero hero : heroes) {
hero.showInventory();
}
}
public int getHighestLevel() {
int hLevel = 0;
for (Hero hero : heroes) {
if (hero.getLevel() > hLevel) {
hLevel = hero.getLevel();
}
}
return hLevel;
}
public void win() {
for (Hero hero : heroes) {
if (!hero.isDead()) {
hero.setExp(hero.getExp() + 2);
hero.setCoins(hero.getCoins() + getHighestLevel() * 100);
hero.setHp((int) (hero.getHp() * 1.1));
hero.setMana((int) (hero.getMana() * 1.1));
}
}
}
public void levelUp() {
for (Hero hero : heroes) {
if (hero.isLevelUp()) {
hero.levelUp();
}
}
}
public void revive() { // get half hp back
for (Hero hero : heroes) {
if (hero.isDead()) {
hero.setHp(hero.getLevel() * 50);
}
}
}
public int numSurvive() {
int number = 0;
for (Hero hero : heroes) {
if (!hero.isDead()) {
number++;
}
}
return number;
}
public int[] surviveIdx() {
int[] surviveIdx = new int[numSurvive()];
int idx = 0;
for (int i = 0; i < heroes.length; i++) {
if (!heroes[i].isDead()) {
surviveIdx[idx] = i;
idx++;
}
}
return surviveIdx;
}
public boolean isAllDead() {
boolean flag = true;
for (Hero hero : heroes) {
if (!hero.isDead()) {
flag = false;
break;
}
}
return flag;
}
public void moveTeam(int i, int j) {
this.i = i;
this.j = j;
}
@Override
public String toString() {
return "HeroTeam{" +
"heroes=" + Arrays.toString(heroes) +
'}';
}
public int numHeroes() {
return heroes.length;
}
public int getI() {
return i;
}
public int getJ() {
return j;
}
public void setI(int i) {
this.i = i;
}
public void setJ(int j) {
this.j = j;
}
}