Use “fire traps” to deafeat ogres.

``````while true:
enemy = hero.findNearestEnemy()
if enemy:
#if the enemy is to the left of the hero:
if enemy.pos.x < hero.pos.x:
#buildXY "fire trap" on the left X.
hero.buildXY("fire trap fence", 25, 34 )
pass
#if the enemy is to the right of the hero:
elif enemy.pos.x > hero.pos.x:
#buildXY a "fire trap" on the right X.
hero.buildXY(fire trap fence", 55, 34)
pass
if the enemy is below the hero:
elif enemy.pos.y < hero.pos.y:
#buildXY a "fire trap" on the bottom X.
hero.buildXY(fire trap fence", 40, 19)
pass
#if the enemy is above the hero":
elif enemy.pos.y > hero.pos.y:
#buildXY a "fire trap" on the top X.
I am doing python.
hero.buildXY("fire trap fence", 40, 19)
pass
#Move back to the center.
hero.moveXY(40, 34)
``````

@alinaqighulam can you format your code as it is described below so we will be able to help you solve the level?

Andrei

1 Like

Hi alinaqighulam,

The thing you want to build each time is a “fire-trap”.

Jenny

but it is not working

Can you post your new code, formatted as described here?

Jenny

``````#Use "fire traps" to deafeat ogres.

while true:
enemy = hero.findNearestEnemy()
if enemy:
#if the enemy is to the left of the hero:
if enemy.pos.x < hero.pos.x:
#buildXY “fire trap” on the left X.
hero.buildXY(“fire trap fence”, 25, 34 )
pass
#if the enemy is to the right of the hero:
elif enemy.pos.x > hero.pos.x:
#buildXY a “fire trap” on the right X.
hero.buildXY(fire trap fence", 55, 34)
pass
if the enemy is below the hero:
elif enemy.pos.y < hero.pos.y:
#buildXY a “fire trap” on the bottom X.
hero.buildXY(fire trap fence", 40, 19)
pass
#if the enemy is above the hero":
elif enemy.pos.y > hero.pos.y:
#buildXY a “fire trap” on the top X.
I am doing python.
hero.buildXY(“fire trap fence”, 40, 19)
pass
#Move back to the center.
hero.moveXY(40, 34)
``````

@Jake_Doggy I’m confused. Is that @alinaqighulam’s code that you’ve put inside quote marks? That’s nice of you to try to help, but what we need is to see where he’s put indents, which don’t come out in the code above.

Thanks,

Jenny

he didn’t put indents

this is his exact code

@jka2706 as @Jake_Doggy stated, alinaqighulam didn’t include any indentations so we can’t really see what the code indentations were.

hello

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!