Mountain-mercenaries _in javascript,


#1

why !!!

why the blue orges are so powerful!

why my soldiers all died !!!

is there a problem with my code ?

···’‘’

loop {

var coin=this.findNearest(this.findItems());
if (coin) {   
    this.move(coin.pos);       }

if (this.gold > this.costOf("soldier")) {
   this.summon("soldier");
}

var enemy = this.findNearest(this.findEnemies());
if (enemy) {

    var soldiers = this.findFriends();
    var soldierIndex = 0;
    while (soldierIndex<soldiers.length) {
         var soldier = soldiers[soldierIndex];
        this.command(soldier, "attack", enemy);
         soldierIndex++;
    }
}

}

···‘’‘

Merged Doublepost

i added "this.attack(enemy) "in the while-loop,

though i passed the level;

but i don’t think i made it right…


#3

You might want to make the soldiers attack their nearest enemy, i.e.

var enemy = soldier.findNearestEnemy()
if (enemy) this.command(soldier, 'attack', enemy)

(Also, this.gold >= this.costOf('soldier') also works (note the >=)


#4

Can’t figure this level out, my soldiers won’t move at all. Can someone please help?


#5

Please post your code( formatted properly ) onto your post and explain what you’ve already tried what’s happening in more detail and any other things that happened when you ran the program e.g. errors or freezing so that people can help you.
Thank you


#6

I already figured it out, but Thanks! :slight_smile: @Deadpool198