My hero just passes the x-mark before the coin comes. I’m getting frustrated.
# Patrol and place traps ONLY if you see a coin.
# Write this function.
def maybeBuildTrap(x, y):
# Move to the given x,y postion
hero.moveXY(x, y)
# Search a coin and if you see it, build a "fire-trap"
item = hero.findNearestItem()
if item:
hero.buildXY("fire-trap", x, y)
pass
while True:
# Call maybeBuildTrap for the top left passage.
maybeBuildTrap(12, 56)
# Now for the top right passage.
hero.moveXY(68, 56)
# Now for the bottom right passage.
hero.moveXY(68, 12)
# Now for the bottom left passage.
hero.moveXY(12, 12)
# Patrol and place traps ONLY if you see a coin.
# Write this function.
def maybeBuildTrap(x, y):
# Move to the given x,y postion
hero.moveXY(x, y)
# Search a coin and if you see it, build a "fire-trap"
item = hero.findNearestItem()
if item and item.type == "coin":
hero.buildXY("fire-trap", x, y)
pass
while True:
# Call maybeBuildTrap for the top left passage.
maybeBuildTrap(12, 56)
# Now for the top right passage.
hero.moveXY(68, 56)
# Now for the bottom right passage.
hero.moveXY(68, 12)
# Now for the bottom left passage.
hero.moveXY(12, 12)