-
Notifications
You must be signed in to change notification settings - Fork 0
/
villain.ts
41 lines (37 loc) · 1.11 KB
/
villain.ts
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
export class Villain implements IProduct{
private name: string;
private health: number;
private maxHealth: number = 100;
constructor(name: string, health: number = 100) {
this.name = name;
if (health < this.maxHealth) {
this.health = health;
} else {
this.health = this.maxHealth;
}
}
rampage() {
if (this.health <= 10) {
this.health = this.maxHealth * 0.90
console.log(`${this.name} restored health to ${this.health}`);
} else {
console.log(`${this.name} is not weak enough`);
}
}
attacked(attackValue) {
if (attackValue > this.health) {
console.log(`${this.name} is no more.`);
} else {
this.health -= attackValue;
console.log(`Villain attacked: ${attackValue} -- ${this.health}`);
}
}
heal(healValue) {
if (this.health + healValue > this.maxHealth) {
console.log(`${this.name} has max health of ${this.maxHealth}`);
} else {
this.health += healValue;
console.log(`${this.name} healed to ${this.health}`);
}
}
}