Crossroads problem

I can’t pass but I finished the goal.Help me !

code:

Use fire-traps to defeat the ogres attacking the trading post.

loop:
enemy = self.findNearestEnemy()

if enemy:
    if enemy.pos.x < self.pos.x:
        # If the enemy is to the left, build a fire-trap to the left.
        hero.shield()
        
        hero.buildXY("fence", 40-19, 34)
        hero.buildXY("fence", 40-19, 34+2)
        hero.buildXY("fence", 40-19, 34-2)
        pass
    elif enemy.pos.x > self.pos.x:
        # If the enemy is to the right, build a fire-trap to the right.
        hero.buildXY("fence", 40+19, 34)
        hero.buildXY("fence", 40+19, 34+2)
        hero.buildXY("fence", 40+19, 34-2)
        pass
    elif enemy.pos.y < self.pos.y:
        # If the enemy is below the hero, build a fire-trap below.
        hero.buildXY("fence", 40, 34-19)
        hero.buildXY("fence", 40+2, 34-19)
        hero.buildXY("fence", 40-2, 34-19)
        pass
    elif enemy.pos.y > self.pos.y:
        # If the enemy is above the hero, build a fire-trap above.
        hero.buildXY("fence", 40, 53)
        hero.buildXY("fence", 40-2, 53)
        hero.buildXY("fence", 40+2, 53)
        pass
self.moveXY(40, 34)

Looks like you’re building fences when the sample code suggests you build fire-traps.

Thank you! :smile: :smile:

(Solution removed)

Mod edit: We do not post solutions on this board. The purpose of this board is to help people learn and simply providing solutions is counterproductive towards that goal. Thank you.

Please try not to revive dead topics.

There are no “dead” topics on this board. It’s probably best to start a new topic but there are no rules against reviving an old one. Thanks.

1 Like