Can someone please help me!
Please note that if I start the enemyIndex = 0 as provided by the pre-written code the hero never attacks any enemies. When I change the enemyIndex = 1 the hero attacks the first wave of enemies and then returns to center, but when the next wave of yaks and ogres come the hero never seems to find the next wave of ogres (i.e. enemies). When I watch the game run you can see the hero is not finding the enemy for the second wave. First of all in theory the code should work even if enemyIndex = 0. In fact in python list always start with position zero not one. Since the hero is not finding enemies after he returns that implies that once the hero moves back to center the program ceases at that point, but since the else statement is nested within the while True loop I would think it would loop back up to the top restart from the while True: portion of the code, but clearly that is not happening. Any help, suggestions, corrections would be greatly appreciated. This has been driving me crazy! lol
enemies = hero.findEnemies()
enemyIndex = 1
Wrap this logic in a while loop to attack all enemies.
# Find the array's length with: len(enemies) while enemyIndex < len(enemies): enemy = enemies[enemyIndex] # "!=" means "not equal to." if enemy.type != "sand-yak": # While the enemy's health is greater than 0, attack it! while enemy.health > 0: hero.attack(enemy) enemyIndex += 1 pass # Between waves, move back to the center. else: hero.moveXY(40,32)