CodeCombat - Coding games to learn Python and JavaScript?
after the resurrection of the dead ( hero.cast(‘raise-dead’); )
, the pet begins to attack the hero
function shouldRun() {
if (hero.health < hero.maxHealth / 2) {
return true;
} else {
return false;
}
}
function ataka() {
if (enemy) {
var distEnemy = hero.distanceTo(enemy);
if (hero.canCast(“drain-life”, enemy) && distEnemy < 15) {
hero.cast(“drain-life”, enemy);
} else {
if (hero.canCast(‘raise-dead’)) {
hero.cast(‘raise-dead’);
} else {
hero.attack(enemy);
}
}
}
}
while (true) {
var enemy = hero.findNearestEnemy();
var heroHealth = hero.health;
// Беги к отметке Х только тогда, когда shouldRun() возвращается true
if (shouldRun()) {
hero.moveXY(57, 37);
ataka(); // Или сражайся!
} else
ataka();
}