-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFighter.java
More file actions
77 lines (60 loc) · 1.73 KB
/
Copy pathFighter.java
File metadata and controls
77 lines (60 loc) · 1.73 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
package boxingMatch;
public class Fighter {
private String name;
private int health;
private int weight;
private int damage;
private double dodge;
public Fighter(String name, int damage, int health, int weight, double dodge) {
this.name = name;
this.damage = damage;
this.health = health;
this.weight = weight;
this.dodge = dodge;
}
public int hit(Fighter foe) {
System.out.println("---------------------------");
System.out.println(this.name + " deals " + this.damage + " damage to " + " => " + foe.name);
if (foe.dodge()) {
System.out.println(foe.name + " dodges incoming damage.");
return foe.health;
}
if (foe.health - this.damage < 0)
return 0;
return foe.health - this.damage;
}
public boolean dodge() {
double randomValue = Math.random() * 100; // 0.0 to 99.9
return randomValue <= this.dodge;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public int getHealth() {
return this.health;
}
public void setHealth(int health) {
this.health = health;
}
public int getWeight() {
return this.weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public int getDamage() {
return this.damage;
}
public void setDamage(int damage) {
this.damage = damage;
}
public double getDodge() {
return this.dodge;
}
public void setDodge(double dodge) {
this.dodge = dodge;
}
}