-
Notifications
You must be signed in to change notification settings - Fork 1
/
troll.js
60 lines (50 loc) · 1.12 KB
/
troll.js
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
function Troll(maxHP, attackPower) {
this._maxHP = maxHP;
this._hp = maxHP;
this._attackPower = attackPower;
this._mode = 0;
};
Troll.prototype.getHP = function () {
return this._hp;
};
Troll.prototype.setHP = function(hp) {
if (hp > this._mapHP) {
this._hp = this._mapHP;
} else {
this._hp = hp;
}
}
Troll.prototype.getAttackPower = function() {
console.log("Mode is: " + this._mode);
if (this._mode == 2) {
return Math.floor(this._attackPower / 2);
} else {
return this._attackPower;
}
}
Troll.prototype.getAttackCount = function() {
if (this._mode == 1) {
return 2;
} else {
return 1;
}
}
Troll.prototype.getAttackMode = function () {
return this._mode;
}
Troll.prototype.setAttackMode = function(mode) {
this._mode = mode;
}
Troll.prototype.takeDamage = function(damage) {
if (this._mode == 2) {
damage = Math.floor(damage / 2);
}
this._hp -= damage;
}
Troll.prototype.isDead = function() {
return this._hp <= 0;
};
Troll.prototype.toString = function() {
return `HP = ${this._hp}/${this._maxHP}, Attack = ${this._attackPower}`;
}
module.exports = Troll;