Hi i recently had problemes with this level…Heres my code
# We need to build guard towers around the village.
# Each peasant can build one tower.
# Show them the place to build.
# These towers are automatic and will attack ALL units outside the town.
# First move along the north border (y=60) from x=40 to x=80 with the step 20.
# `range` doesn't include the second edge.
for x in range(40, 81, 20):
# Move at each point and say anything.
hero.moveXY(x, 60)
hero.say("Here")
# Next move along the east border (x=80) from y=40 to y=20 with the negative step -20.
for y in range(40, 19, -20):
hero.moveXY(80, y)
hero.say("Here")
# Continue for the two remaining borders.
# Next the south border (y=20) from x=60 to x=20 with the negative step -20.
for x in range (60, 20, -20):
hero.moveXY(x, 20)
hero.say("Here")
# Next the west border (x=20) from y=40 to y=60 with the step 20.
for y in range (40, 60, 20):
hero.moveXY(20, y)
hero.say("Here")
# Don't forget hide inside the village.
hero.moveXY(50, 40)
Take a closer look at the first two, particularly the stop portion of the range.
range(start, stop, step)
The key detail is the stop number won’t ever run, but every number up to that stop number will. If you want to include that number, you have to go one above or below that number depending on which step you are taking.
# We need to build guard towers around the village.
# Each peasant can build one tower.
# Show them the place to build.
# These towers are automatic and will attack ALL units outside the town.
# First move along the north border (y=60) from x=40 to x=80 with the step 20.
# `range` doesn't include the second edge.
for x in range(41, 81, 20):
# Move at each point and say anything.
hero.moveXY(x, 60)
hero.say("Here")
# Next move along the east border (x=80) from y=40 to y=20 with the negative step -20.
for y in range(39, 19, -20):
hero.moveXY(80, y)
hero.say("Here")
# Continue for the two remaining borders.
# Next the south border (y=20) from x=60 to x=20 with the negative step -20.
for x in range (59, 19, -20):
hero.moveXY(x, 20)
hero.say("Here")
# Next the west border (x=20) from y=40 to y=60 with the step 20.
for y in range (41, 61, 20):
hero.moveXY(20, y)
hero.say("Here")
# Don't forget hide inside the village.
hero.moveXY(50, 40)