I have been successfully able to have my character move around the screen but have not been able to automate the attacks on the CPU character. I would really appreciate it if someone could give me some feedback on my code!
loop:
item = self.findNearestItem()
if item:
pos = item.pos
x = pos.x
y = pos.y
self.moveXY(x, y)
continue
enemy = self.findNearestEnemy()
elif self.distanceTo(enemy) < 10:
if self.isReady("cleave"):
self.cleave(enemy)
continue
else:
self.attack(enemy)
Thanks so much! I was able to fix the code and have the intended outcome:)
Now to work through more levels and figure out how to work the coin value into my code so I can optimize the collection process:)
hi I need help with my code. Its keep saying value is not defined and my hero never moves.
Here is my code:
while True:
# Find coins and/or attack the enemy.
# Use flags and your special moves to win!
item = hero.findNearestItem()
if item.type == "coin" and value == 1:
hero.moveXY(item.pos.x, item.pos.y)
if item.type == "coin" and value == 2:
hero.moveXY(item.pos.x, item.pos.y)
if item.type == "coin" and value == 3:
hero.moveXY(item.pos.x, item.pos.y)