Backwood Brawl Help (javascript)


#1
    loop {
    var enemy = this.findNearestEnemy();
    if(enemy) {
    var distance = this.distanceTo(enemy);
    if (distance < 20){
    if (this.isReady("power-up")) {
    this.powerUp();
    }
    else {
    this.attack(enemy);
    }
    }
    }
    }

This is my code for backwood brawl; however, something weird happens. the first enemy that I kill, I think after powering up, my character will chase them when they are knocked back (despite already being dead). Is this a coding error, or is it something that’s simply weird.
I use distance < 20 because I can’t find nearest missiles yet. I can beat it if my character stops chasing already dead people. This is also my first run though of it, so it’s at the default difficulty, I guess.


#2

Looks ok to me (although having indentation inside your curly braces would make it easier to read). I gave your code a run through, and didn’t see what you were describing?


#3

When I attack, say the first enemy that shows up after powering up, it knocks the ogre far back, but the ogre should already be dead. My hero chases it. I’ll try to post a screencast of it when I’m out of class.


#4

Well, I successfully beat it with a much simply code (attack everything that’s 30 or nearer), but when I hit submit, it gave me a new seed, so I didn’t get to complete it. Is this as far as I can get on code warrior without spending money? I have no more areas unlocked.

Here’s what was happening, nevertheless: [Backwood Brawl][1]

Edit: I found other levels I haven’t done yet. They were hard to see because of the lack of a flag.
[1]: https://www.youtube.com/watch?v=opyYglquleY


#5

Try simply not to power-up. You can slay the munchkins with one hit.

Alternatively you can only powerup if necessary.

if (enemy.health > attackDamage) { //replace with your damage
    this.powerUp()
    this.attack(enemy)
}

#6

I did not have enemy.health yet, but I’ll try to remember that for when I do. And yes, when I tried to do it without powering up, it worked. I was confused about why the powerup (Only thing that changed was attack speed and the one knockback hit) was doing that; I didn’t know if it’s a bug worth reporting.