Created
February 21, 2020 06:40
-
-
Save newswim/160b7a011a92ab37a4f4b7054bdbcf00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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