Dust Help please

Hey guys,
I’m trying to beat the level Dust since couple days already, but die every time before I can kill 10 Orcs.

I tired already a couple of different codes, but not sure what I´m doing wrong, it would be nice if you could help me.

my current code is:

// Always take an action inside a while loop, or it’ll go on forever!
// Use while to loop until you have enough hits to kill 10 munchkins.
var attacks = 0;

while (attacks < 10) {
var enemy = this.findNearestEnemy();
// Attack the nearest enemy!
if (enemy){
this.attack(enemy);
//this.attack(enemy);
attacks += 1;
this.say(attacks);
}

// Incrementing means to increase by 1.
// Increment the number of hits.
//

}
// When you’re done, retreat to the ambush point.
this.say(“I should retreat!”); //∆ Don’t just stand there blabbering!
this.moveXY(79, 33);

I’m dying at Orc 9, and I have not enough Gems to buy me new gear.(Using the Runesword and the painted steel armor right now).

Thanks in advance :slight_smile:

Perhaps you should try shielding in between attacks. This is a touch-and-go tactic, but with such a long cooldown on the Runesword, it might make the difference.

1 Like

ah didn’t think of the cooldown, tryed with shield too died at Orc 8, and long sword Orc 9, so did the long sword and cleav after hit 5. Not realy clean but it works.
Thanks for the Help :slight_smile:

// Always take an action inside a while loop, or it’ll go on forever!
// Use while to loop until you have enough hits to kill 10 munchkins.
var attacks = 0;

while (attacks < 10) {
var enemy = this.findNearestEnemy();
// Attack the nearest enemy!
if (enemy){
this.attack(enemy);
this.attack(enemy);
attacks += 1;
this.say(attacks);
if (attacks >= 5){
this.cleave(enemy);
}
}
else {
this.shield();
}

// Incrementing means to increase by 1.
// Increment the number of hits.
//

}
// When you’re done, retreat to the ambush point.
this.say(“I should retreat!”); //∆ Don’t just stand there blabbering!
this.moveXY(79, 33);

PS: is there a way to count the actual Kill Ratio not just the hits?

After each hit check if you have killed the enemy:

if (enemy){
    this.attack(enemy);
    if(enemy.health<0)
        this.say("Oops, my bad");
}
2 Likes

Nice solution Adrian, but I believe you should check for enemy.health <= 0 — note the <= instead of <. Otherwise, you would not count enemies when your killing blow deals exactly the same damage as the enemy’s remaining health.

1 Like

yep, 0 is still counted to be alive i think.

As far as I can see, having zero health = having no health = dead.

well the array of enemies doesn’t decrease.
It’s a bit like monopoly; if you have 0 money, that’s ok. Else, you are in debt, and that’s trouble.

Array of enemies? I thought we were talking about units’ health.
Well, in virtually every single RPG/Action/Fight game, reaching 0 HP means you are dead. I’m pretty sure CodeCombat is no different.

1 Like

Guess so. :neutral_face: