-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.java
700 lines (623 loc) · 23.5 KB
/
Game.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
import java.util.*;
public class Game{
private static final int WIDTH = 80;
private static final int HEIGHT = 30;
private static final int BORDER_COLOR = Text.WHITE;
private static final int BORDER_BACKGROUND = Text.BLACK + Text.BACKGROUND;
private static final ArrayList<String> history = new ArrayList<>();
private static int recentAction = 0;
public static void main(String[] args) {
run();
}
//Display the borders of your screen that will not change.
//Do not write over the blank areas where text will appear or parties will appear.
public static void drawBackground(){
System.out.print("\033[;" + BORDER_COLOR + ";" + BORDER_BACKGROUND + "m");
// Top Outer Corners
Text.go(1,0);
System.out.print("\u250F");
Text.go(1,80);
System.out.print("\u2513");
/* Fills in empty space -- blocks new text in center box for some reason
for (int i = 2; i < 80; i++) {
for (int x = 2; x < 29; x++) {
if (x!= 5 && x!= 21 && x!= 25) {
Text.go(x,i);
System.out.print(" ");
}
}
} */
// Inner Vertical Borders (top)
for(int x = 2; x < 6; x++) {
Text.go(x,28);
System.out.print("\u2503");
Text.go(x,54);
System.out.print("\u2503");
}
// Inner Vertical Borders (bottom)
for(int x = 21; x < 26; x++) {
Text.go(x,28);
System.out.print("\u2503");
Text.go(x,54);
System.out.print("\u2503");
}
// Left and Right Outer Borders
for(int x = 2; x < 29; x++) {
Text.go(x,0);
if(x != 5 && x!= 21 && x!=25) {
System.out.print("\u2503");
}
else {
System.out.print("\u2523");
}
Text.go(x,80);
if(x != 5 && x!= 21 && x!=25) {
System.out.print("\u2503");
}
else {
System.out.print("\u252B");
}
}
// All Horizontal Border Lines
for(int x = 2; x < 80; x++) {
Text.go(1,x);
if(x != 28 && x != 54) {
System.out.print("\u2501");
}
else {
System.out.print("\u2533");
}
Text.go(29,x);
System.out.print("\u2501");
Text.go(5,x);
if(x != 28 && x != 54) {
System.out.print("\u2501");
}
else {
System.out.print("\u253B");
}
Text.go(21,x);
if(x != 28 && x != 54) {
System.out.print("\u2501");
}
else {
System.out.print("\u2533");
}
Text.go(25,x);
if(x != 28 && x != 54) {
System.out.print("\u2501");
}
else {
System.out.print("\u253B");
}
}
// Bottom Outer Corners
Text.go(29,0);
System.out.print("\u2517");
Text.go(29,80);
System.out.print("\u251B");
}
//Display a line of text starting at
//(columns and rows start at 1 (not zero) in the terminal)
//use this method in your other text drawing methods to make things simpler.
public static void drawText(String s,int startRow, int startCol){
Text.go(startRow, startCol);
System.out.print(s);
}
public static void addHistory(String text) {
int maxWidth = WIDTH - 3;
ArrayList<String> wrapped = new ArrayList<>();
String[] lines = text.split("\n");
for (String line : lines) {
String[] words = line.split(" ");
String current = "";
for (String word : words) {
if (current.length() + word.length() + 1 > maxWidth) {
wrapped.add(current);
current = word;
} else {
if (!current.isEmpty()) {
current += " ";
}
current += word;
}
}
if (!current.isEmpty()) {
wrapped.add(current);
}
}
recentAction = wrapped.size();
for (int i = wrapped.size() - 1; i >= 0; i--) {
history.add(0, wrapped.get(i));
}
while (history.size() > 14) {
history.remove(history.size() - 1);
}
}
public static void displayHistory(int row, int col, int width, int height) {
TextBox(row, col, width, height, "");
int index = Math.max(0, history.size() - height);
for (int i = index; i < history.size(); i++) {
String line = history.get(i);
String styled;
if (i < recentAction) {
styled = Text.colorize(line, Text.BOLD);
} else {
styled = Text.colorize(line, 90);
}
drawText(styled, row++, col);
}
recentAction = Math.max(0, recentAction - (history.size() - index));
}
/*Use this method to place text on the screen at a particular location.
*When the length of the text exceeds width, continue on the next line
*for up to height lines.
*All remaining locations in the text box should be written with spaces to
*clear previously written text.
*@param row the row to start the top left corner of the text box.
*@param col the column to start the top left corner of the text box.
*@param width the number of characters per row
*@param height the number of rows
*/
public static void TextBox(int row, int col, int width, int height, String text){
if (text.contains("\n")) {
String[] texts = text.split("\n");
for (String t : texts) {
TextBox(row,col,width,height,t);
row = row + 1 + t.length()/width;
}
}
else {
String temp = "";
String temp2 = "";
if(text.length() > width - 2) {
int split = text.lastIndexOf(" ", width - 2);
if (split == -1) {
split = width - 2;
}
temp = text.substring(split + 1);
text = text.substring(0, split);
}
drawText(text, row, col);
height--;
if (temp.length() > 0) {
TextBox(row+1,col,width,height,temp);
}
else {
for (int x = 0; x < width-2 && height > 0; x++) {
temp = temp + " ";
}
for (int x = 0; x < width-2-text.length(); x++) {
temp2 = temp2 + " ";
}
drawText(temp2,row,col+text.length());
while (height > 0) {
height--;
row = row+1;
drawText(temp, row, col);
}
}
Text.go(29,0);
System.out.print("\u2517");
Text.go(29,80);
System.out.print("\u251B");
}
}
//return a random adventurer (choose between all available subclasses)
//feel free to overload this method to allow specific names/stats.
public static Adventurer createRandomAdventurer(){
int num = (int) (Math.random() * 2);
if (num == 0) {
// we can change or remove names/stats later
return new Enemy_BarbGoblin("Barbarian Goblin"+(int)(Math.random()*100));
} else {
return new Enemy_DrunkGoblin("Drunk Goblin"+(int)(Math.random()*100));
}
}
/*Display a List of 2-4 adventurers on the rows row through row+3 (4 rows max)
*Should include Name HP and Special on 3 separate lines.
*Note there is one blank row reserved for your use if you choose.
*Format:
*Bob Amy Jun
*HP: 10 HP: 15 HP:19
*Caffeine: 20 Mana: 10 Snark: 1
* ***THIS ROW INTENTIONALLY LEFT BLANK***
*/
public static void drawParty(ArrayList<Adventurer> party, int startRow) {
int colWidth = (WIDTH - 2) / 3;
for (int i = 0; i < party.size(); i++) {
Adventurer member = party.get(i);
int startCol = (i * colWidth) + 2;
String name = member.getName();
if (party.size() == 1) {
drawText(name, startRow, (WIDTH - name.length()) / 2);
} else {
drawText(name, startRow, startCol + (colWidth - name.length()) / 2);
}
String hp = "HP: " + colorByPercent(member.getHP(), member.getmaxHP());
String special = member.getSpecialName() + ": " + colorByPercent(member.getSpecial(), member.getSpecialMax());
if (party.size() == 1) {
drawText(hp, startRow + 1, (WIDTH / 2) - (colWidth / 2) + 3);
drawText(special, startRow + 2, (WIDTH / 2) - (colWidth / 2) + 3);
} else {
drawText(hp, startRow + 1, startCol + 1 + i);
drawText(special, startRow + 2, startCol + 1 + i);
}
}
}
//Use this to create a colorized number string based on the % compared to the max value.
public static String colorByPercent(int hp, int maxHP){
String output = String.format("%2s", hp+"")+"/"+String.format("%2s", maxHP+"");
//COLORIZE THE OUTPUT IF HIGH/LOW:
// under 25% : red
// under 75% : yellow
// otherwise : white
double percent = (double) hp / maxHP;
if (percent < 0.25) {
return Text.colorize(output, Text.RED);
} else if (percent < 0.75) {
return Text.colorize(output, Text.YELLOW);
} else {
return Text.colorize(output, Text.WHITE);
}
}
//Display the party and enemies
//Do not write over the blank areas where text will appear.
//Place the cursor at the place where the user will by typing their input at the end of this method.
public static void drawScreen(ArrayList<Adventurer> party, ArrayList<Adventurer> enemies){
drawBackground();
//draw player party
drawParty(party, 22);
//draw enemy party
drawParty(enemies, 2);
displayHistory(7, 2, WIDTH - 2, 14);
}
public static String userInput(Scanner in){
//Move cursor to prompt location
Text.go(28,2);
System.out.print("> ");
Text.go(28,4);
//show cursor
Text.showCursor();
String input = in.nextLine();
//clear the text that was written
TextBox(26,2,80,3," ");
return input;
}
public static void quit(){
Text.reset();
Text.showCursor();
Text.go(32,1);
}
public static void run(){
//Clear and initialize
Text.hideCursor();
Text.clear();
boolean partyTurn = true;
boolean firstEntry = true;
boolean hasWon = false;
boolean hasLost = false;
int deadEnemies = 0;
int deadParty = 0;
int whichPlayer = 0;
int whichOpponent = 0;
int target = 0;
int turn = 0;
String input = "";//blank to get into the main loop.
String action = "";
Scanner in = new Scanner(System.in);
drawBackground();
String prepreprompt = "How many enemies do you wish to fight: one(o) / two(t) / three(th)";
while ((! (input.equalsIgnoreCase("o") || input.equalsIgnoreCase("one"))) &&
(! (input.equalsIgnoreCase("t") || input.equalsIgnoreCase("two"))) &&
(! (input.equalsIgnoreCase("th") || input.equalsIgnoreCase("three")))) {
if (firstEntry) {
TextBox(26,2,WIDTH,1,prepreprompt);
}
else {
TextBox(26,2,WIDTH,1,"Invalid entry, please try again: one(o) / two(t) / three(th)");
}
input = userInput(in);
firstEntry = false;
}
firstEntry = true;
//Things to attack:
//Make an ArrayList of Adventurers and add 1-3 enemies to it.
//If only 1 enemy is added it should be the boss class.
//start with 1 boss and modify the code to allow 2-3 adventurers later.
ArrayList<Adventurer>enemies = new ArrayList<Adventurer>();
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
if (input.equalsIgnoreCase("th") || input.equalsIgnoreCase("three")) {
enemies.add(createRandomAdventurer());
enemies.add(createRandomAdventurer());
enemies.add(createRandomAdventurer());
} else if (input.equalsIgnoreCase("t") || input.equalsIgnoreCase("two")) {
enemies.add(new Enemy_Yin("Yin"));
enemies.add(new Enemy_Yang("Yang"));
} else {
enemies.add(new Boss1("Little Cheese"));
}
addAllies(enemies);
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
//Adventurers you control:
//Make an ArrayList of Adventurers and add 2-4 Adventurers to it.
ArrayList<Adventurer> party = new ArrayList<>();
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
party.add(new ElvenGuardian("Thalindor Aegisheart"));
party.add(new Sorcerer("Veca Anouk"));
party.add(new Priest("Léopoldine Goyathlay"));
addAllies(party);
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
// Adding enemies
addEnemies(party,enemies);
addEnemies(enemies,party);
//Draw the window border
//You can add parameters to draw screen!
drawScreen(party, enemies);//initial state.
//Main loop
//display this prompt at the start of the game.
String preprompt = "Enter command for "+party.get(whichPlayer)+": attack(a)/special(sp)/support(su #)/quit(q)";
TextBox(26,2,WIDTH,1,preprompt);
while (!(input.equalsIgnoreCase("q") || input.equalsIgnoreCase("quit")) && !hasWon && !hasLost) {
//Read user input
input = userInput(in).toLowerCase();
while ((! (input.equals("a") || input.equals("attack"))) &&
(! (input.equals("sp") || input.equals("special"))) &&
(! (input.startsWith("su ") || input.startsWith("support "))) &&
(! (input.startsWith("q") || input.startsWith("quit"))) &&
partyTurn) {
TextBox(26,2,WIDTH,1,"Invalid entry, please try again: attack(a)/special(sp)/support(su #)/quit(q)");
input = userInput(in).toLowerCase();
}
if (!(input.equalsIgnoreCase("q") || input.equalsIgnoreCase("quit")) && partyTurn) {
Adventurer currentPlayer = party.get(whichPlayer);
if (input.startsWith("su ") || input.startsWith("support ")) {
String[] parts = input.split(" ");
if (parts.length < 2 || parts[1].isEmpty() || !parts[1].chars().allMatch(Character::isDigit)) {
TextBox(26, 2, WIDTH, 3, "Invalid command. Please properly specify who to support: support # (su #)");
continue;
}
target = Integer.parseInt(parts[1]);
if (target < 0 || target >= party.size()) {
TextBox(26, 2, WIDTH, 3, "Invalid target. Choose a valid party member index to support 0-" + (party.size() - 1) + ": support # (su #)");
continue;
}
if (party.get(target).isDead() && !(currentPlayer instanceof Priest)) {
TextBox(26, 2, WIDTH, 3, "The selected target is dead, " + currentPlayer.getName() + " is unable to support them: support # (su #).");
continue;
}
if (target == whichPlayer) {
action = currentPlayer.support();
} else {
action = currentPlayer.support(party.get(target));
}
} else if (currentPlayer.isAoe(input) && partyTurn && (input.equals("a") || input.equals("attack") || input.equals("sp") || input.equals("special"))) {
if (input.equals("attack") || input.equals("a")) {
action = currentPlayer.attack(enemies) + checkForDead(enemies, -1);
} else if (input.equals("special") || input.equals("sp")) {
action = currentPlayer.specialAttack(enemies, party) + checkForDead(enemies, -1);
}
} else if (input.equals("a") || input.equals("attack") || input.equals("sp") || input.equals("special")) {
TextBox(26,2,WIDTH,1,"Please select a target using a valid integer index");
String input2 = userInput(in);
while (input2.length() > 0 && (input2.charAt(0) < 48 || input2.charAt(0) > 57)) {
TextBox(26, 2, WIDTH, 3, "Invalid command. Please properly specify target");
input2 = userInput(in);
}
target = Integer.parseInt(input2);
while (target >= enemies.size() || target < 0 || enemies.get(target).isDead()) {
if (target >= enemies.size() || target < 0) {
TextBox(26,2,WIDTH,1,"Invalid target. Choose a valid party member index.");
}
else {
TextBox(26,2,WIDTH,1,"The selected target is dead, please reselect a target.");
}
input2 = userInput(in);
while (input2.length() > 0 && (input2.charAt(0) < 48 || input2.charAt(0) > 57)) {
TextBox(26, 2, WIDTH, 3, "Invalid command. Please properly specify target");
input2 = userInput(in);
}
target = Integer.parseInt(input2);
}
//Process user input for the last Adventurer:
if(input.equals("attack") || input.equals("a")){
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
action = party.get(whichPlayer).attack(enemies.get(target)) + checkForDead(enemies,target);
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
}
else if(input.equals("special") || input.equals("sp")){
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
action = party.get(whichPlayer).specialAttack(enemies.get(target)) + checkForDead(enemies,target);
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
}
}
}
//example debug statment
TextBox(6,2,80,78,"input: "+input+" partyTurn:"+partyTurn+ " whichPlayer="+whichPlayer+ " whichOpp="+whichOpponent );
//display event based on last turn's input
if(partyTurn){
addHistory(action);
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
if (enemies.get(target).isDead()) {
if (enemies.get(target).hasSecondPhase == true) {
enemies.remove(0);
enemies.add(new Boss2("Big Cheese, DoW"));
for (Adventurer a : party) {
a.setPoisoned2(false);
}
}
else if (!enemies.get(target).deathCounted) {
deadEnemies++;
if (deadEnemies == enemies.size()) {
hasWon = true;
}
}
}
//You should decide when you want to re-ask for user input
//If no errors:
whichPlayer++;
if(whichPlayer < party.size()){
//This is a player turn.
//Decide where to draw the following prompt:
String prompt = "Enter command for "+party.get(whichPlayer)+": attack(a)/special(sp)/support(su #)/quit(q)";
TextBox(26,2,WIDTH,1,prompt);
}else{
//This is after the player's turn, and allows the user to see the enemy turn
//Decide where to draw the following prompt:
String prompt = "Press Enter to see enemy's turn: ";
TextBox(26,2,WIDTH,1,prompt);
partyTurn = false;
whichPlayer = 0;
}
//done with one party member
}else if(!partyTurn && whichOpponent < enemies.size()) {
//not the party turn!
//enemy attacks a randomly chosen person with a randomly chosen attack.z`
//Enemy action choices go here!
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
Adventurer currentEnemy = enemies.get(whichOpponent);
if (currentEnemy.isDead()) {
addHistory(currentEnemy.getName() + " has been defeated and cannot act.");
} else if (currentEnemy.isStunned()) {
addHistory(currentEnemy.getName() + " is stunned and cannot act this turn.");
currentEnemy.setStunned(false);
} else {
int move = (int)(Math.random() * 3);
if (move == 0 || move == 1) {
Adventurer randParty = getValidTarget(party);
if (move == 0) {
action = currentEnemy.attack(randParty)+checkForDead(party,party.indexOf(randParty));
} else {
action = currentEnemy.specialAttack(randParty)+checkForDead(party,party.indexOf(randParty));
}
if (randParty.isDead()) {
deadParty++;
if (deadParty == party.size()) {
hasLost = true;
}
}
} else if (move == 2) {
Adventurer randEnemy = getValidTarget(enemies);
if (randEnemy == currentEnemy) {
action = currentEnemy.support();
} else {
action = currentEnemy.support(randEnemy);
}
}
addHistory(action);
}
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
//Decide where to draw the following prompt:
if (whichOpponent + 1 != enemies.size()) {
String prompt = "Press Enter to see next enemy's turn: ";
TextBox(26,2,WIDTH,1,prompt);
}
else {
String prompt = "Press Enter to complete the turn: ";
TextBox(26,2,WIDTH,1,prompt);
}
whichOpponent++;
}//end of one enemy.
//modify this if statement.
else {
//THIS BLOCK IS TO END THE ENEMY TURN
//It only triggers after the last enemy goes.
whichOpponent = 0;
turn++;
partyTurn=true;
//display this prompt before player's turn
String result = "";
for (int x = 0; x < enemies.size(); x++) {
Adventurer a = enemies.get(x);
result += a.applyStatusEffects();
if (!checkForDead(enemies, x).isEmpty()) {
deadEnemies++;
} else {
a.restoreSpecial(1);
}
result += checkForDead(enemies, x);
}
if (deadEnemies == enemies.size()) {
hasWon = true;
}
for (int x = 0; x < party.size(); x++) {
Adventurer a = party.get(x);
result += a.applyStatusEffects();
if (!checkForDead(party, x).isEmpty()) {
deadParty++;
} else {
a.restoreSpecial(1);
}
result += checkForDead(party, x);
}
if (deadParty == party.size()) {
hasLost = true;
}
result += "\nAll players gain 1 special.";
addHistory(result);
String prompt = "Enter command for "+party.get(whichPlayer)+": attack(a)/special(sp)/support(su #)/quit(q)";
TextBox(26, 2, WIDTH, 1, prompt);
}
//display the updated screen after input has been processed.
drawScreen(party, enemies);
}//end of main game loop
if (hasWon == true) {
screens.win();
Text.wait(1000);
}
else if (hasLost == true) {
screens.lose();
Text.wait(1000);
}
//After quit reset things:
quit();
}
public static void addAllies(ArrayList<Adventurer> team) {
for (int x = 0; x < team.size(); x++) {
for (int i = 0; i < team.size(); i++) {
if (i != x) {
(team.get(x)).allies.add(team.get(i));
}
}
}
}
public static void addEnemies(ArrayList<Adventurer> team1, ArrayList<Adventurer> team2) {
for (int x = 0; x < team1.size(); x++) {
for (int i = 0; i < team2.size(); i++) {
team1.get(x).enemies.add(team2.get(i));
}
}
}
private static Adventurer getValidTarget(ArrayList<Adventurer> team) {
int randIndex = (int)(Math.random() * team.size());
while (team.get(randIndex).isDead()) {
randIndex = (int)(Math.random() * team.size());
}
return team.get(randIndex);
}
public static String checkForDead (ArrayList<Adventurer> team, int target) {
String result = "";
if (target == -1) {
for (Adventurer member : team) {
if (member.isDead() && !member.deathCounted) {
member.deathCounted = true;
if (member.hasSecondPhase) {
result += "\n" + member.getName() + " has been defeated, entering Phase 2!\nLittle Cheese's poison effects have been lifted.";
} else {
result += "\n" + member.getName() + " has been defeated.";
}
}
}
return result;
}
Adventurer current = team.get(target);
if (current.isDead() && !current.deathCounted) {
current.deathCounted = true;
if (current.hasSecondPhase) {
return "\n" + current.getName() + " has been defeated, entering Phase 2!\nLittle Cheese's poison effects have been lifted.";
}
return "\n" + current.getName() + " has been defeated.";
}
return result;
}
}