-
Notifications
You must be signed in to change notification settings - Fork 0
/
Headquarter.java
168 lines (148 loc) · 5.63 KB
/
Headquarter.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package WOW;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Headquarter {
static int wowTime = 0;
static int numCity;
static int loyaltyDecrease;
int life;// 生命元
boolean stop = false;// 是否停止造武士
String army;// 阵营
int[] heroOrder;// 制造英雄的顺序
int[] heroLife;
int[] heroForce;
ArrayList<Hero> heroList = new ArrayList<Hero>();// 制造的英雄
Headquarter(int life_, String army_, int[] heroOrder_, int[] herolife_, int[] heroForce_) {
life = life_;
army = army_;
heroOrder = heroOrder_;
heroLife = herolife_;
heroForce = heroForce_;
}
void createHero() {
int det = heroOrder[wowTime % 5];
if (stop || life < heroLife[det]) {
stop = true;
return;
}
life -= heroLife[det];
Hero tmp;
if (det == 0)
tmp = new Dragon(heroLife[det], heroForce[det], wowTime + 1, army);
else if (det == 1)
tmp = new Ninja(heroLife[det], heroForce[det], wowTime + 1, army);
else if (det == 2)
tmp = new Iceman(heroLife[det], heroForce[det], wowTime + 1, army);
else if (det == 3)
tmp = new Lion(heroLife[det], heroForce[det], wowTime + 1, army, life, loyaltyDecrease);
else
tmp = new Wolf(heroLife[det], heroForce[det], wowTime + 1, army);
if (army == "red")
tmp.setMarchParam(0, 1, numCity + 1);
else
tmp.setMarchParam(numCity + 1, -1, 0);
heroList.add(tmp);
}
void checkLion() {
for (int i = 0; i < heroList.size(); i++) {
if (heroList.get(i).heroType == "lion")
((Lion) heroList.get(i)).runAway();
}
checkHero();
}
void checkHero() {
ArrayList<Hero> tmpList = new ArrayList<Hero>();
for (Hero h : heroList)
if (h.life > 0)
tmpList.add(h);
heroList = tmpList;
}
void marchHero() {
for (Hero h : heroList)
h.step();
}
void printLife() {
if (wowTime < 10)
System.out.print("00" + wowTime + ":");
else if (wowTime < 100)
System.out.print("0" + wowTime + ":");
else
System.out.print(wowTime + ":");
System.out.println("50 " + life + " elements in " + army + " headquarter");
}
public static void main(String[] args) {
int[] redHeroOrder = { 2, 3, 4, 1, 0 };
int[] blueHeroOrder = { 3, 0, 1, 2, 4 };
int[] heroLife = new int[5];
int[] heroForce = new int[5];
Scanner stdin = new Scanner(System.in);
int initLife = stdin.nextInt();
numCity = stdin.nextInt();
loyaltyDecrease = stdin.nextInt();
int maxWowTime = stdin.nextInt();
for(int i=0;i<5;i++)
heroLife[i] = stdin.nextInt();
for(int i=0;i<5;i++)
heroForce[i] = stdin.nextInt();
stdin.close();
Headquarter redHead = new Headquarter(initLife, "red", redHeroOrder, heroLife, heroForce);
Headquarter blueHead = new Headquarter(initLife, "blue", blueHeroOrder, heroLife, heroForce);
while (Headquarter.wowTime * 60 <= maxWowTime) {
redHead.createHero();
blueHead.createHero();
if (Headquarter.wowTime * 60 + 5 > maxWowTime)
break;
redHead.checkLion();
blueHead.checkLion();
if (Headquarter.wowTime * 60 + 10 > maxWowTime)
break;
redHead.marchHero();
blueHead.marchHero();
ArrayList<Hero> tmpList = new ArrayList<Hero>();
tmpList.addAll(redHead.heroList);
tmpList.addAll(blueHead.heroList);
Collections.sort(tmpList);
for (Hero h : tmpList)
h.printStep();
if (Hero.wowEnd)
break;
if (Headquarter.wowTime * 60 + 35 > maxWowTime)
break;
for (int i = redHead.heroList.size() - 1; i >= 0; i--) {
for (int j = 0; j < blueHead.heroList.size(); j++) {
if (redHead.heroList.get(i).heroType == "wolf")
((Wolf) redHead.heroList.get(i)).stoleWeapon(blueHead.heroList.get(j));
if (blueHead.heroList.get(j).heroType == "wolf")
((Wolf) blueHead.heroList.get(j)).stoleWeapon(redHead.heroList.get(i));
}
}
if (Headquarter.wowTime * 60 + 40 > maxWowTime)
break;
for (int i = redHead.heroList.size() - 1; i >= 0; i--) {
for (int j = blueHead.heroList.size() - 1; j >= 0; j--) {
if (redHead.heroList.get(i).city % 2 == 1)
redHead.heroList.get(i).fightWith(blueHead.heroList.get(j));
else
blueHead.heroList.get(j).fightWith(redHead.heroList.get(i));
}
}
redHead.checkHero();
blueHead.checkHero();
if (Headquarter.wowTime * 60 + 50 > maxWowTime)
break;
redHead.printLife();
blueHead.printLife();
if (Headquarter.wowTime * 60 + 55 > maxWowTime)
break;
tmpList.clear();
tmpList.addAll(redHead.heroList);
tmpList.addAll(blueHead.heroList);
Collections.sort(tmpList);
for (Hero h : tmpList)
h.printWeapon();
Headquarter.wowTime++;
// if(Headquarter.wowTime>5) break;
}
}
}