I’m having a problem. I’m pretty sure my code is right. The instructions are to take out the throwers THEN take on the rest. The other way round would be easy using cleave, but I find that I can get to one thrower after which the 30- odd munchkins have me pressed up against a wall and I can’t get out. Are all of the ogres supposed to be there at the start and be able to prevent you attacking the throwers?
Sorry, should have posted the code. i’ve tried a few things but it’s all the same - the hero is swept against a wall and pinned before being able to kill the throwers
# First, loop through all enemies... enemies = hero.findEnemies() enemyIndex = 0 # ... but only attack "thrower" type enemies. enemy = enemies[enemyIndex] while enemyIndex < len(enemies) and enemy.health > 0: enemy = enemies[enemyIndex] if enemy.type == "thrower" and enemy.health > 0: hero.attack(enemy) enemyIndex += 1 # Then loop through all the enemies again... enemies = hero.findEnemies() enemyIndex = 0 # ... and defeat everyone who's still standing. while enemyIndex < len(enemies) and enemy.health > 0: enemy = enemies[enemyIndex] hero.attack(enemy) enemyIndex += 1
Sorry again, please note that first increment counter i.e.
enemyIndex += 1
appears under the if, not the while in the above code due to a transcribing mistake. It is actually under the while (i.e. four spaces to the left).
SOLVED. Dumb mistake in the code.