Skip to content

Commit 4b7af52

Browse files
committed
beginner epic
CONGRATULATIONS! You have climbed to the top of the tower. Warrior Score: 74 Time Bonus: 10 Clear Bonus: 17 Level Grade: S Total Score: 511 + 101 = 612 Your average grade for this tower is: A Level 1: S Level 2: A Level 3: S Level 4: S Level 5: A Level 6: A Level 7: S Level 8: S Level 9: S
1 parent 3d557b8 commit 4b7af52

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

xavdid-beginner/Player.js

+35-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ class Player { // eslint-disable-line no-unused-vars
2121
// do nothing, acted already
2222
} else if (this.didHeal(warrior)) {
2323
// do nothing, acted already
24-
} else if (warrior.feel().isCaptive() && this._captives > 0) {
25-
warrior.rescue()
26-
this._captives -= 1
24+
} else if (this.didHelpCaptive(warrior)) {
25+
// do nothing, acted already
26+
// && this._captives > 0
27+
// this._captives -= 1
2728
} else if (warrior.feel().isWall()) {
2829
warrior.pivot()
2930
} else {
@@ -77,6 +78,32 @@ class Player { // eslint-disable-line no-unused-vars
7778
}
7879
}
7980

81+
didHelpCaptive (warrior) {
82+
let dir = false
83+
let acted = false
84+
directions.forEach(d => {
85+
if (warrior.feel(d).isCaptive()) {
86+
warrior.rescue(d)
87+
acted = true
88+
}
89+
})
90+
91+
if (acted) { return true }
92+
93+
directions.forEach(d => {
94+
if (this.captiveIsInSight(warrior, d) && !dir) {
95+
dir = d
96+
}
97+
})
98+
99+
if (dir) {
100+
warrior.walk(dir)
101+
return true
102+
} else {
103+
return false
104+
}
105+
}
106+
80107
// action checks
81108
underAttack (warrior) {
82109
// console.log(`_health: ${this._health} | current health: ${warrior.health()}`)
@@ -89,6 +116,11 @@ class Player { // eslint-disable-line no-unused-vars
89116
return unit && unit.isEnemy()
90117
}
91118

119+
captiveIsInSight (warrior, direction) {
120+
const unit = warrior.look(direction).find(space => !space.isEmpty())
121+
return unit && unit.isCaptive()
122+
}
123+
92124
// returns false or the direction to pivot
93125
adjacentEnemyDirection (warrior) {
94126
let dir = false

0 commit comments

Comments
 (0)