Skip to content

Instantly share code, notes, and snippets.

@kuatsure kuatsure/warrior-lvl-4.js
Last active Aug 29, 2015

Embed
What would you like to do?
jswarrior
jsWarrior.turn = function(warrior) {
if ( warrior.check() == "empty" ) {
if ( warrior.curr == 20 ) {
warrior.walk()
} else {
if ( warrior.getHealth() < warrior.curr ) {
warrior.walk()
} else {
warrior.rest()
}
}
} else if( warrior.check() == "enemy" ) {
warrior.attack();
} else {
warrior.walk()
}
warrior.curr = warrior.getHealth()
}
jsWarrior.turn = function(warrior) {
if ( warrior.check() == "empty" ) {
if ( warrior.curr == 20 ) {
warrior.walk()
} else {
if ( warrior.getHealth() < warrior.curr ) {
warrior.walk()
} else {
warrior.rest()
}
}
} else if( warrior.check() == "enemy" ) {
warrior.attack();
} else if( warrior.check() == "diamond" ) {
warrior.collect();
} else {
warrior.walk()
}
warrior.curr = warrior.getHealth()
}
jsWarrior.turn = function(warrior) {
if ( warrior.direction !== 'forward' ) {
warrior.direction = 'backward'
}
if ( warrior.check( warrior.direction ) === 'empty' ) {
if ( warrior.curr == 20 ) {
warrior.walk( warrior.direction )
} else {
if ( warrior.getHealth() < warrior.curr ) {
warrior.direction = 'backward'
warrior.walk( warrior.direction )
} else {
warrior.rest()
}
}
} else if( warrior.check( warrior.direction ) == "enemy" ) {
warrior.attack( warrior.direction );
} else if( warrior.check( warrior.direction ) == "diamond" ) {
warrior.collect( warrior.direction );
} else if( warrior.check( warrior.direction ) == "wall" ) {
warrior.direction = 'forward'
} else {
warrior.walk( warrior.direction )
}
warrior.curr = warrior.getHealth()
}
// Pivot-less
jsWarrior.turn = function(warrior) {
if ( warrior.direction !== 'forward' ) {
warrior.direction = 'backward'
}
if ( warrior.check( warrior.direction ) === 'empty' ) {
if ( warrior.curr == 20 ) {
warrior.walk( warrior.direction )
} else {
if ( warrior.getHealth() < warrior.curr ) {
warrior.direction = 'backward'
warrior.walk( warrior.direction )
} else {
warrior.rest()
}
}
} else if( warrior.check( warrior.direction ) == "enemy" ) {
warrior.attack( warrior.direction );
} else if( warrior.check( warrior.direction ) == "diamond" ) {
warrior.collect( warrior.direction );
} else if( warrior.check( warrior.direction ) == "wall" ) {
warrior.direction = 'forward'
} else {
warrior.walk( warrior.direction )
}
warrior.curr = warrior.getHealth()
}
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.