Forest Miners - Javascript

My hero keeps on attacking a enemy on the side:

Screenshot 2023-02-06 6.19.29 PM

My code:

// Check if the mines are safe for the workers.
function checkEnemyOrSafe(target) {
    // If `target` (the parameter) exists:
    if (target) {
    } else {
        hero.say("All Clear!");
    }    // Then attack target.
         // Otherwise:
         // Use say() to call the peasants.
while (true) {
    // Move to, and check the top right X mark.
    hero.moveXY(64, 54);
    var enemy1 = hero.findNearestEnemy();
    // Move to the bottom left X mark.
    hero.moveXY(16, 14);
    // Save the result of findNearestEnemy() in a variable.
    var enemy2 = hero.findNearestEnemy();
    // Call checkEnemyOrSafe, and pass the
    // result of findNearestEnemy as the argument.

You have to check distance

Try using glasses that don’t let you see through walls. If your hero can’t see the enemies on the other side of the trees, he won’t try to attack them.


This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.