Skip to content

Instantly share code, notes, and snippets.

@newswim

newswim/warrior.js

Created Feb 21, 2020
Embed
What would you like to do?
// 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
You can’t perform that action at this time.