-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMonster.java
More file actions
executable file
·132 lines (101 loc) · 3.88 KB
/
Copy pathMonster.java
File metadata and controls
executable file
·132 lines (101 loc) · 3.88 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
129
130
131
132
import java.util.Random;
class Monster {
Random r = new Random();
String[] elements = {"fire", "water", "air"};
private String name;
private int strength; // de 0 à 9
private int intelligence; // de 0 à 9
private double life; // 40 ou de 10 à 30
private double initialLife;
private String element; // "fire", "water", "air"
public Monster(String name, double life) {
this.name = name;
this.strength = r.nextInt(9);
this.intelligence = r.nextInt(9);
this.life = life;
this.initialLife = this.getLife();
this.element = elements[r.nextInt(3)];
}
public Monster(String name) {
this.name = name;
this.strength = r.nextInt(9);
this.intelligence = r.nextInt(9);
this.life = (double) r.nextInt(21) + 10 ; // r.nextInt(max - min + 1) + min
this.initialLife = this.getLife();
this.element = elements[r.nextInt(3)];
}
public void setName(String name) {
this.name = name;
}
public void setStrength(int strength) {
this.strength = strength;
}
public void setLife(double life) {
this.life = life;
}
public void setInitialLife(double life) {
this.initialLife = life;
}
public void setIntelligence(int intelligence) {
this.intelligence = intelligence;
}
public void setElement(String element) {
this.element = element;
}
public String getName() {
return this.name;
}
public int getStrength() {
return this.strength;
}
public double getLife() {
return this.life;
}
public double getInitialLife() {
return this.initialLife;
}
public int getIntelligence() {
return this.intelligence;
}
public String getElement() {
return this.element;
}
public void attack(Monster ennemyMonster) {
int attack = getStrength() + 1;
double efficiency = 1.0;
if (this.element == "fire" && ennemyMonster.element == "air"
|| this.element == "water" && ennemyMonster.element == "fire"
|| this.element == "air" && ennemyMonster.element == "water") {
efficiency = 2.0 ;
} else if ( this.element == "air" && ennemyMonster.element == "fire"
|| this.element == "fire" && ennemyMonster.element == "water"
|| this.element == "water" && ennemyMonster.element == "air") {
efficiency = 0.5 ;
}
ennemyMonster.setLife( ennemyMonster.getLife() - attack * efficiency );
if (ennemyMonster.getLife() > 0) {
System.out.println(this.getName() + " attacks " + ennemyMonster.getName() + ".\n" + ennemyMonster.getName() + " has " + ennemyMonster.getLife() + " points remaining.\n");
} else {
System.out.println(this.getName() + " attacks " + ennemyMonster.getName() + ".\n" + ennemyMonster.getName() +" is KO!\n") ;
}
}
public void heal() {
int heal = getIntelligence() + 1;
if (this.getLife() < this.getInitialLife()) {
this.setLife(this.getLife() + heal) ;
if (this.getLife() > this.getInitialLife()) {
this.setLife(this.getInitialLife());
}
System.out.println(this.getName() + " heals. It now has " + this.getLife() + " of life.\n");
} else {
System.out.println(this.getName() + "'s life is at maximum already, so " + this.getName() + " can't heal.\n" );
}
}
public void status() {
System.out.println(this.getName());
System.out.println("Strength: " + this.getStrength());
System.out.println("Intelligence: " + this.getIntelligence());
System.out.println("Life: " + this.getLife());
System.out.println("Element: " + this.getElement() + "\n");
}
}