# \[solved\] Distracting Dungeon Help!

**URL:** <https://discourse.codecombat.com/t/solved-distracting-dungeon-help/13467>\
**Category:** Level Help\
**Created:** [January 7, 2018, 6:29pm UTC](https://discourse.codecombat.com/t/solved-distracting-dungeon-help/13467 "2018-01-07T18:29:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![I\_can\_rob\_you](https://avatars.discourse-cdn.com/v4/letter/i/ed655f/32.png) [@I\_can\_rob\_you](https://discourse.codecombat.com/u/I_can_rob_you)\
**Post date:** [January 7, 2018, 6:29pm UTC](https://discourse.codecombat.com/t/solved-distracting-dungeon-help/13467/1 "2018-01-07T18:29:43Z")

</div>

I need help, and I have been stuck on it for so long. @kinasharma01  
This is my code:

```python
peasant = hero.findNearest(hero.findFriends())
while True:
    # Command your friend to build a decoy towards x + 1:
    hero.command(peasant, "buildXY", "decoy", hero.pos.x+1, hero.pos.y)
    tDest = {"x": hero.pos.x, "y": hero.pos.y + 28};
    while hero.distanceTo(tDest) > 1:
        hero.move(tDest)
        hero.command(peasant, "move", tDest)
    # Create a new x/y dict +28 units away in the x dir:
    tDest = {"x": hero.pos.x + 28, "y": hero.pos.y};
    # Find the nearest enemy:
    enemy = hero.findNearest(hero.findEnemies())
    while enemy:
        while enemy.health > 0: 
            if enemy.type == "brawler": 
                hero.attack(enemy)
            else:
                if hero.canCast("chain-lightning", enemy): 
                    hero.cast("chain-lightning", enemy)
                else: 
                    hero.attack(enemy)
        else: 
            hero.attack(enemy)
        
        enemy = hero.findNearest(hero.findEnemies())
    while peasant.distanceTo(tDest) > 1:
        hero.move(tDest)
        hero.command(peasant, "move", tDest)

```

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/1/10a539afe89549f03afd9252ae8c21eaacb4fb4a.jpg)

---

<div class="post-metadata">

**Author:** ![kinasharma01](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/kinasharma01/32/10862_2.png) [@kinasharma01](https://discourse.codecombat.com/u/kinasharma01)\
**Post date:** [January 7, 2018, 6:30pm UTC](https://discourse.codecombat.com/t/solved-distracting-dungeon-help/13467/2 "2018-01-07T18:30:55Z")

</div>

I messaged you on some pointers on how to complete it. Hope that helps out!

---

<div class="post-metadata">

**Author:** ![SuperSmacker](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/supersmacker/32/8385_2.png) [@SuperSmacker](https://discourse.codecombat.com/u/SuperSmacker)\
**Post date:** [January 7, 2018, 8:32pm UTC](https://discourse.codecombat.com/t/solved-distracting-dungeon-help/13467/3 "2018-01-07T20:32:25Z")

</div>

Don’t attack brawlers. Your little peasant friend might get killed ☹  
Try using the decoys to draw away the brawlers, as the level instructs you to do, or you can summon some soldiers to stall the brawlers, and kill the scouts yourself.

---

<div class="post-metadata">

**Author:** ![I\_can\_rob\_you](https://avatars.discourse-cdn.com/v4/letter/i/ed655f/32.png) [@I\_can\_rob\_you](https://discourse.codecombat.com/u/I_can_rob_you)\
**Post date:** [January 7, 2018, 9:04pm UTC](https://discourse.codecombat.com/t/solved-distracting-dungeon-help/13467/4 "2018-01-07T21:04:46Z")

</div>

I attacked the brawlers and still won.

---

<div class="post-metadata">

**Author:** ![SuperSmacker](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/supersmacker/32/8385_2.png) [@SuperSmacker](https://discourse.codecombat.com/u/SuperSmacker)\
**Post date:** [January 7, 2018, 9:35pm UTC](https://discourse.codecombat.com/t/solved-distracting-dungeon-help/13467/5 "2018-01-07T21:35:50Z")

</div>

… okay then… xd

---

<div class="post-metadata">

**Author:** ![jaden\_the\_best](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@jaden\_the\_best](https://discourse.codecombat.com/u/jaden_the_best)\
**Post date:** [June 30, 2020, 12:21am UTC](https://discourse.codecombat.com/t/solved-distracting-dungeon-help/13467/6 "2020-06-30T00:21:20Z")

</div>

Please help me on this. here is my code.

# Navigate the mountain maze with a peasant pal.

# Advanced while-loop usage is required!

peasant = hero.findNearest(hero.findFriends())  
while hero.pos.x\<96:  
# Command your friend to build a decoy towards x + 1:  
hero.command(peasant, ‘buildXY’, ‘decoy’, hero.pos.x+1, hero.pos.y)  
tDest = {“x”: hero.pos.x, “y”: hero.pos.y + 28};  
while hero.distanceTo(tDest) \> 1:  
hero.move(tDest)  
hero.command(peasant, “move”, tDest)  
# Create a new x/y object +28 units away in the x dir:  
tDest = {“x”: hero.pos.x+28, “y”: hero.pos.y};  
# Find the nearest enemy:  
enemy = hero.findNearestEnemy()  
# While there is an enemy:  
while enemy:  
# While the enemy’s health is \> 0:  
while enemy.health\>0:  
# Attack the enemy:  
hero.attack(enemy)  
# Update the variable to the next nearest enemy:  
enemy = hero.findNearestEnemy()  
# While friend’s distance to the new x/y object \> 1:  
hero.say(peasant.distanceTo(tDest))  
while peasant.distanceTo(tDest)\>1:  
# Move the hero and peasant towards the x/y dict:  
hero.command(peasant, ‘move’, tDest)  
hero.wait(3)

---

<div class="post-metadata">

**Author:** ![Anna](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/anna/32/8378_2.png) [@Anna](https://discourse.codecombat.com/u/Anna)\
**Post date:** [June 30, 2020, 12:43am UTC](https://discourse.codecombat.com/t/solved-distracting-dungeon-help/13467/7 "2020-06-30T00:43:25Z")

</div>

can you please format your code using three backticks (is that what they’re called?) and then pasting your code inside so we can read it better?

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [June 30, 2020, 4:43pm UTC](https://discourse.codecombat.com/t/solved-distracting-dungeon-help/13467/8 "2020-06-30T16:43:46Z")

</div>

This article will help with that: [[Essentials] How To Post/Format Your Code Correctly](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521)
