-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonster.js
65 lines (56 loc) · 1.73 KB
/
Monster.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
61
62
63
64
65
const { writeFile } = require('./writeFile')
class Monster {
constructor(health, abilities) {
this.health = health
this.abilities = abilities
}
attack(hero) {
let randomAttack = Math.floor(Math.random() * 10) + 1
// First ability
if (randomAttack < 5) {
writeFile(
`${this.constructor.name} dealt ${this.abilities[0].dmg} damage with ${this.abilities[0].nameOfAttack} to the ${hero.constructor.name}\n`
)
console.log(
`${this.constructor.name} dealt ${this.abilities[0].dmg} damage with ${this.abilities[0].nameOfAttack} to the ${hero.constructor.name}`
)
hero.health -= this.abilities[0].dmg
console.log(
`${this.constructor.name} health -- ${this.health} | ${hero.constructor.name} -- ${hero.health}`
)
}
// Second ability
else {
writeFile(
`${this.constructor.name} dealt ${this.abilities[1].dmg} damage with ${this.abilities[1].nameOfAttack} to the ${hero.constructor.name}\n`
)
console.log(
`${this.constructor.name} dealt ${this.abilities[1].dmg} damage with ${this.abilities[1].nameOfAttack} to the ${hero.constructor.name}`
)
hero.health -= this.abilities[1].dmg
console.log(
`${this.constructor.name} health -- ${this.health} | ${hero.constructor.name} -- ${hero.health}`
)
}
}
}
class Dragon extends Monster {
constructor(health) {
super(health, [
{ nameOfAttack: 'Mele', dmg: 5 },
{ nameOfAttack: 'Breath', dmg: 20 },
])
}
}
class Spider extends Monster {
constructor(health) {
super(health, [
{ nameOfAttack: 'Mele', dmg: 5 },
{ nameOfAttack: 'Bite', dmg: 8 },
])
}
}
module.exports = {
Dragon: Dragon,
Spider: Spider,
}