Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

I cannot get past The Final Kithmaze

Hi there,

I can’t get past The Final Kithmaze and I have tried multiple ways and tried to use the hints.
I am currently using JavaScript, and my guy can navigate, but when he attempts to kill an enemy. it steers him off course then he runs into a wall and spikes kill him.

Any suggestions, please?

Thank you.

can you please send your code or pictures so we can help you further

It’s strange O_o
I play Python, but it was quite easy to wright JavaScript cycle.
Maybe some troubles with your equipment.
Show us your code, please. Dont’ forget to format it with </> button)

This is my code so far…

while(true) {
    var enemy = hero.findNearestEnemy();
if (enemy) {
    var distance = hero.distanceTo(enemy);
    if (distance < 10) {
        hero.attack(enemy);
        hero.attack(enemy);
}
}
    hero.moveRight();
    hero.moveUp();
    hero.moveRight();
    hero.moveDown();
    hero.moveDown();
    hero.moveUp();
    
}

But when run, he defeats an enemy and runs into a wall…

Thanks. With this code my hero don’t die, but also doesn’t complete the level.
I would advice to simplify code. Try to get rid of everything connected with “distance”, and only one cycle to repeat. Move to have enemy in sight of view-define him-kill him-take gem. Repeat)

1 Like

What would this look like?

I tried this with same result.

while(true) {
    var enemy = hero.findNearestEnemy();
if (enemy) {
    if (enemy) {
        hero.attack(enemy);
        hero.attack(enemy);
}
}
    hero.moveRight();
    hero.moveUp();
    hero.moveRight();
    hero.moveDown();
    hero.moveDown();
    hero.moveUp();
    
}

A little bit closer) The point is in structure. Try something like this:

That’s the structure. Don’t define enemy at the start, i mean.

1 Like

Thank you so much! This worked for me.

You’re welcome) Good luck)

1 Like