// You are trapped. Don't move, it'll be painful.
// This function checks if the enemy is in your attack range.
function inAttackRange(enemy) {
var distance = hero.distanceTo(enemy);
// Almost all swords have attack range of 3.
if (distance <= 3) {
return true;
} else {
return false;
}
}
while (true) {
var enemy = hero.findNearestEnemy();
var canAttack = inAttackRange(enemy);
if (enemy) {
var result = true;
hero.attack(enemy);
}
}
Я ошиблась в коде?