Skip to content

Instantly share code, notes, and snippets.

@newswim
Created February 21, 2020 06:40
Show Gist options
  • Save newswim/160b7a011a92ab37a4f4b7054bdbcf00 to your computer and use it in GitHub Desktop.
Save newswim/160b7a011a92ab37a4f4b7054bdbcf00 to your computer and use it in GitHub Desktop.
// http://jswarrior.fusioncharts.com/level/6
// Level 6
jsWarrior.turn = function(warrior) {
console.log('warrior.check()', warrior.check())
const isEnemy = warrior.check() == "enemy"
const diamond = warrior.check() == "diamond"
const behindW = warrior.check('backward')
const health = warrior.getHealth()
warrior.prevHealth = warrior.currHealth
warrior.currHealth = warrior.getHealth()
console.log('behindW', behindW)
const isAttacked = warrior.currHealth < warrior.prevHealth
const isJavaLiner = isAttacked // &&
if (diamond) {
warrior.collect()
}
else if (!isEnemy && health < 20 && !isAttacked) {
warrior.rest()
}
else if(isEnemy) {
warrior.attack();
}
else if (isAttacked) {
warrior.walk('backward')
}
else {
warrior.walk()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment