-
Notifications
You must be signed in to change notification settings - Fork 0
/
warrior_lvl6.js
46 lines (38 loc) · 1.21 KB
/
warrior_lvl6.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
class Player {
constructor () {
this._health = 20
this._direction = 'backward'
this.go = (warrior) => {
if (warrior.feel(this._direction).isCaptive()) {
warrior.rescue(this._direction)
this._health = warrior.health()
return
}
if (!warrior.feel(this._direction).isEmpty() && !warrior.feel(this._direction).isWall()) {
warrior.attack(this._direction)
this._health = warrior.health()
return
}
if (warrior.health() < this._health && warrior.feel().isEmpty() && warrior.health() < 13) {
warrior.walk((this._direction === 'backward') ? 'forward' : 'backward')
this._health = warrior.health()
return
}
if (warrior.health() < 17 && warrior.health() >= this._health) {
warrior.rest()
this._health = warrior.health()
return
}
warrior.walk(this._direction)
this._health = warrior.health()
}
}
playTurn (warrior) {
if (warrior.feel().isWall()) {
warrior.pivot(this._direction)
this._direction = (this._direction === 'backward') ? 'forward' : 'backward'
return
}
this.go(warrior)
}
}