Skip to content

Instantly share code, notes, and snippets.

@bosky101
Created September 26, 2013 07:14
Show Gist options
  • Save bosky101/6710804 to your computer and use it in GitHub Desktop.
Save bosky101/6710804 to your computer and use it in GitHub Desktop.
jswarrior level5 crossed, with this . more at http://jswarrior.fusioncharts.com
jsWarrior.turn = function(warrior) {
if(warrior.check() == "enemy") {
warrior.enemies=(warrior.enemies)?warrior.enemies+1:1;
if(!warrior.fighting){warrior.fighting++;}else{ warrior.tired++;}
warrior.attack();
}
else {
if(warrior.check() == "diamond") {
warrior.collect();
}else{
var health = warrior.getHealth();
var reqd = (warrior.reqd)? warrior.reqd:8;
if(health<reqd || warrior.tired || warrior.enemies>2){
warrior.enemies--;
if(warrior.fighting){
warrior.fighting--;if(warrior.steps){ warrior.steps--;warrior.walk('backward');}
}else{
warrior.tired--;warrior.rest();warrior.reqd=20;
}
}else{
warrior.walk(); warrior.steps = (warrior.steps)?warrior.steps+1:1;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment