-
Notifications
You must be signed in to change notification settings - Fork 0
/
fiting.html
37 lines (33 loc) · 943 Bytes
/
fiting.html
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
<script>
class Fighter{
constructor(name, power, helth = 100){
this.name = name;
this.power = power;
this.helth = helth;
}
setDamage(damage){
this.helth -= damage;
}
hit(enemy, point = 1){
let damage = point * this.power;
enemy.setDamage(damage);
}
}
class ImprovedFighter extends Fighter{
doubleHit(enemy, point){
super.hit(enemy, 2 * point)
}
}
let fight = (fighter, improvedFighter, ...points) => {
while(fighter.health > 0 && improvedFighter.health > 0){
let p = points.pop();
fighter.hit(improvedFighter, p);
improvedFighter.hit(fighter, p);
}
let winner = (fighter.health > improvedFighter.health) ? fighter : improvedFighter;
console.log(`winner: ${winner.name}`);
}
let f1 = new Fighter("Edik", 1);
let f2 = new ImprovedFighter("Sasha", 1);
fight(f1, f2, 1, 3, 5);
</script>