codecombat zone-of-danger

 
 
var enemies = this.getEnemies();
var nearestEnemy = null;

// TODO: Find the nearest enemy with the distanceTo method.
var nearest = enemies[0];
var shortestDistance = this.distanceTo(nearest);
for (var i = 0; i < enemies.length; i++) { 
    var distance = this.distanceTo(enemies[i]);
    if (distance  <= shortestDistance) {
        nearest = enemies[i];
        shortestDistance = distance;
        } 
    }
nearestEnemy = nearest;
return nearestEnemy;


var x = Math.pow((target.pos.x - this.pos.x), 2);
var y = Math.pow((target.pos.y - this.pos.y), 2);
var distance = Math.sqrt(x + y);
return distance;





你可能感兴趣的:(codecombat zone-of-danger)