Bonjour,
Pouvez-vous m’aider à corriger ce code, j’ai une boucle infinie mais je ne comprends pas pourquoi.
J’utilise comme héro Okar.
def defEnemyAttack():
enemies = hero.findEnemies()
faible = None
moinsSante >= 70
enemyIndex = 0
while enemyIndex < len (enemies):
enemy = enemies [enemyIndex]
if enemy.health < moinsSante:
faible = enemy
moinsSante = enemy.health
hero.attack(enemy)
elif enemy.health > moinsSante:
fort = enemy
if hero.canCast("chain-lightning", fort):
hero.cast("chain-lightning", fort)
elif hero.isReady("bash"):
hero.bash(fort)
elif hero.isReady("throw") and hero.distanceTo(fort.pos) < hero.throwRange:
hero.throw(fort)
elif hero.isReady("stomp"):
hero.stomp(fort)
elif hero.isReady("hurl"):
hero.hurl(fort)
else:
hero.attack(enemy)
enemyIndex += 1
def gold():
presGold = None
minGoldDist = 9001
coinIndex =0
coins = hero.findItems()
for coin in coins:
dist = hero.distanceTo(coin)/coin.value
if minGoldDist > dist:
presGold =coin
minGoldDist = dist
hero.move(presGold.pos)
def point2():
points=[{"x":5, "y":49},{"x":5, "y":20},{"x":76, "y":51},{"x":76, "y":19}]
pointspres = None
minpointdis = 9001
for point in points:
distance2 = hero.distanceTo(point)
if minpointdis > distance2:
pointspres= point
minpointdis= distance2
hero.move(pointspres)
while True:
item = hero.findNearestItem()
enemy = hero.findNearestEnemy()
if item :
gold()
if enemy:
distance = hero.distanceTo(enemy)
if distance<20:
defEnemyAttack()
if hero.health/3:
point2()
gold()
2 Likes
C’est parce que tu as
truffeb:
moinsSante >= 70
ils devrait etre moinsSante = 70
sans le “>”.
J’espère que cela vous aide!
( désolé pour mon mauvais français, je suis en train d’apprendre. )
1 Like
Ton français est bon
Mon personnage ramasse les items puis combat le premier ogre, le deuxième ogre a 7 de vie et le héro ne bouge plus. Le temps est ensuite écoulé.
2 Likes
Ils devrait etre metre
truffeb:
enemyIndex += 1
quatre espaces en arriere. ( pardon pour les accents je ne peux pas les mettre en PC )
1 Like
Merci
Il fini sont combat, il commence à ramasser les pièces puis hésites ou il doit aller. J’ai ajouté coinIndex +=1 mais cela ne change rien
2 Likes
Oh, okeydokey , je crois que il faut metre
truffeb:
if hero.canCast("chain-lightning", fort):
hero.cast("chain-lightning", fort)
elif hero.isReady("bash"):
hero.bash(fort)
elif hero.isReady("throw") and hero.distanceTo(fort.pos) < hero.throwRange:
hero.throw(fort)
elif hero.isReady("stomp"):
hero.stomp(fort)
elif hero.isReady("hurl"):
hero.hurl(fort)
else:
hero.attack(enemy)
et
truffeb:
hero.attack(enemy)
(ligne 13)
comme ca:
def defEnemyAttack():
enemies = hero.findEnemies()
faible = None
moinsSante = 70
enemyIndex = 0
while enemyIndex < len (enemies):
enemy = enemies [enemyIndex]
if enemy.health < moinsSante:
faible = enemy
moinsSante = enemy.health
elif enemy.health > moinsSante:
fort = enemy
enemyIndex += 1
if faible:
hero.attack(faible)
if fort:
if hero.canCast("chain-lightning", fort):
hero.cast("chain-lightning", fort)
elif hero.isReady("bash"):
hero.bash(fort)
elif hero.isReady("throw") and hero.distanceTo(fort.pos) < hero.throwRange:
hero.throw(fort)
elif hero.isReady("stomp"):
hero.stomp(fort)
elif hero.isReady("hurl"):
hero.hurl(fort)
else:
hero.attack(enemy)
def gold():
presGold = None
minGoldDist = 9001
coinIndex =0
coins = hero.findItems()
for coin in coins:
dist = hero.distanceTo(coin)/coin.value
if minGoldDist > dist:
presGold =coin
minGoldDist = dist
hero.move(presGold.pos)
def point2():
points=[{"x":5, "y":49},{"x":5, "y":20},{"x":76, "y":51},{"x":76, "y":19}]
pointspres = None
minpointdis = 9001
for point in points:
distance2 = hero.distanceTo(point)
if minpointdis > distance2:
pointspres= point
minpointdis= distance2
hero.move(pointspres)
while True:
item = hero.findNearestItem()
enemy = hero.findNearestEnemy()
if item :
gold()
if enemy:
distance = hero.distanceTo(enemy)
if distance<20:
defEnemyAttack()
if hero.health/3:
point2()
gold()
Je pense que cela fonctionne.
1 Like
Phew! je suis content que ca fonctionne pour toi, s’il vous plaît pourriez-vous mettre [RESOLU] dans le titre et dans le titre de tous les autres problèmes que vous avez résolus aussi.
Merci!
1 Like