I’m blocked in this level
My character just stand, do nothing else.
# Use while loops to pick out the ogre
loop:
enemies = self.findEnemies()
enemyIndex = 0
# Wrap this logic in a while loop to attack all 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:
self.attack(enemy)
enemyIndex += 1
break
# Between waves, move back to the center.
self.moveXY(39, 32)
Are you sure about the position of the line enemyIndex += 1?
With this code, you are increasing enemyIndex after each attack to enemy if it is not a sand-yak. Just after enemy is dead, break makes you exit the while loop.
If you find a sand-yak, again, you break the first while loop and in any case you do not check all the enemies.
You don’t need to use a double if, you can use the and operator to connect
if enemy and enemy.type != "sand-yak":
In this way if there is an enemy, you check if the type is correct.
Then, you have just to remove the break and move enemyIndex += 1:
if enemy.type != "sand-yak":
# While the enemy's health is greater than 0, attack it!
while enemy.health > 0:
self.attack(enemy)
enemyIndex += 1
In this way, if you find a sand-yak nothing happens, but if you find an ogre you attack until it’s died and then you go the following element of enemies.
In the game, we don’t really learn these thing, we just have a level we they are showed, and after, we have to use it directly.
I hope some others chapter won’t be learned that way, because it’s pretty hard.
Next school years, i’ll be in a formation about web programming.
So i’ll ear a lot of HTML/CSS, a little part of Java/Javascript, and some server based langage.
(I know Python have nothing to do with, but i planned to learned some others like Python (and i like Python because it’s not really hard)
# Wrap this logic in a while loop to attack all 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:
self.attack(enemy)
enemyIndex += 1
# Between waves, move back to the center.
self.moveXY(39, 32)
The code above has been corrected, but I would suggest you think about a couple of things as it is not a great answer unless you are over geared for the level.
Is there a better order in which to attack the mobs?
Currently, you could end up zigzagging all over the field. Do you have access to findNearest(), the health property and/or distanceTo() for example?
When your targets are outside of your current range, in which direction should you move or use moveXY?
If you do not have access to .move, think about what this does:
You might also look into Vector math in terms of deciding where to go next. I will admit to that maybe being overkill for this level, but it will come in handy later.
Apologies on formatting above, on )$&&@: tablet device. Sigh … also just realized how old this thread was. Apology for the necromancy.