-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArena.java
More file actions
executable file
·87 lines (64 loc) · 2.43 KB
/
Copy pathArena.java
File metadata and controls
executable file
·87 lines (64 loc) · 2.43 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
import java.util.Scanner;
class Arena {
public static Scanner input = new Scanner(System.in);
public static void counterAttack(Monster ennemy, Monster champion) {
if (ennemy.getLife() > 0 ) {
ennemy.attack(champion);
}
}
public static void fight(Monster champion, Monster ennemy) {
String answer = "";
boolean stop = false;
while (answer != "a" || answer != "h") {
if (champion.getLife() > 0 && ennemy.getLife() > 0) {
System.out.println("What is your next action? Type 'a' for attacking, 'h' for healing.");
answer = input.nextLine();
if (answer.equals("a")) {
champion.attack(ennemy);
answer = "";
counterAttack(ennemy, champion);
} else if (answer.equals("h")) {
champion.heal();
answer = "";
counterAttack(ennemy, champion);
} else {
System.out.println( "Invalid answer!");
}
} else {
if (champion.getLife()<= 0 && !stop) {
System.out.println("GAME OVER!");
stop = true;
break;
} else {
System.out.println(champion.getName() + " wins! ");
break;
}
}
}
}
private static int round(Monster champion, Monster opponent, int round) {
if (champion.getLife() > 0) {
System.out.println("\nROUND " + round + "\n");
champion.status();
opponent.status();
while (opponent.getLife() > 0 && champion.getLife() > 0) {
fight(champion, opponent);
}
}
if (champion.getLife() > 0) {
return 1;
}
return 0;
}
public static void main (String[] args) {
Monster champion = new Monster("Champion", 40.0);
Monster ennemy1 = new Monster("Ennemy 1");
Monster ennemy2 = new Monster("Ennemy 2");
Monster ennemy3 = new Monster("Ennemy 3");
int nbVictories = 0;
nbVictories += round(champion, ennemy1, 1);
nbVictories += round(champion, ennemy2, 2);
nbVictories += round(champion, ennemy3, 3);
System.out.println("Victorious rounds: " + nbVictories);
}
}