Created
March 18, 2014 21:01
-
-
Save dlangh/9629528 to your computer and use it in GitHub Desktop.
JSWarrior Level 5
This file contains hidden or 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
jsWarrior.turn = function(warrior) { | |
if (!warrior.previousHealth) { warrior.previousHealth = 20 }; | |
if(warrior.check() == "enemy") { | |
warrior.attack(); | |
} | |
else if (warrior.check() == 'diamond') { | |
warrior.collect(); | |
} | |
else { | |
if (warrior.getHealth() < 19) { | |
if (warrior.getHealth() < warrior.previousHealth) { | |
warrior.walk(); | |
} | |
else { | |
warrior.rest(); | |
warrior.previousHealth = warrior.getHealth(); | |
} | |
} | |
else { | |
warrior.walk(); | |
} | |
} | |
warrior.previousHealth = warrior.getHealth(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment