Skip to content

Instantly share code, notes, and snippets.

@dlangh
Created March 18, 2014 21:01
Show Gist options
  • Save dlangh/9629528 to your computer and use it in GitHub Desktop.
Save dlangh/9629528 to your computer and use it in GitHub Desktop.
JSWarrior Level 5
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