Help with level called keeping time


#1

This is my code so far

loop:
     enemy = self.findNearestEnemy()
     if enemy and self.distanceTo(enemy) < 10:
         # Move to the left by subtracting 10 from your X coordinate.
         pass
         x = self.pos.x - 10
         y = self.pos.y 
         self.moveXY(x, y)
     else:
         # Move to the right by adding 10 to your X coordinate.
         pass
         x = self.pos.x + 10
         y = self.pos.y 
         self.moveXY(x, y)

One of the guy keeps on dying.


#2

First, when posting code, make sure you help us help you by formatting your code. You can do this by properly indenting and placing 3 tick marks (```) above and below your code.

Looking at your code, you aren’t exactly following the instructions:

  1. For the first 10 secs ( self.now() <= 10 ), you must fight. This means find an enemy and attack it.

  2. After that, you must collect coins until 30 seconds has passed ( self.now() <= 30), Find the nearest item to move to each coin.

  3. After that, you must fight again.

Until you learn to do this, your ally will continue to die.


#3

This is my code:

item = self.findNearestItem()
enemy = self.findNearestEnemy()
itemPos = item.pos
x = itemPos.x
y = itemPos.y
loop:
# If it’s the first 10 seconds, fight.
if self.now() < 10:
self.attack(enemy)
pass
# Else, if it’s the first 30 seconds, collect coins.
elif self.now() < 30:
self.moveXY(x, y)
pass
# After 30 seconds, join the raid!
else:
self.attack(enemy)
pass

My guy fights ogres, but he doesn’t collect any money.


#4

Look at the placement of your loop and when you find items and enemies. Currently you will fight 1 enemy and collect 1 coin.


#5

also, please format your code according to the FAQ


#6

try to hire more troops.


#7

True, that will work. But, please leave topics that are dead, dead.


#8

Use your new skill to choose what to do: hero.now()

enemy = hero.findNearestEnemy()
item = hero.findNearestItem()

while True:
# If it’s the first 10 seconds, fight.
if hero.now() < 10:
hero.attack(enemy)
pass
# Else, if it’s the first 30 seconds, collect coins.
elif hero.now() < 30:
if item:
pos = itemipos
x = pos.x
y = pos.y
hero.moveXY(x, y)
pass

# After 30 seconds, join the raid!
else:
    hero.attack(enemy)
    pass

#9

what is the problem with this code?


#10

i don’t know so yeah dont ask me!


#11

This topic is dead 2 years ago, so please don’t try reviving it.