# Finally solved Thunderhooves!

**URL:** <https://discourse.codecombat.com/t/finally-solved-thunderhooves/2326>\
**Category:** Uncategorized\
**Created:** [January 13, 2015, 10:24am UTC](https://discourse.codecombat.com/t/finally-solved-thunderhooves/2326 "2015-01-13T10:24:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbaaron13](https://avatars.discourse-cdn.com/v4/letter/n/49beb7/32.png) [@nbaaron13](https://discourse.codecombat.com/u/nbaaron13)\
**Post date:** [January 13, 2015, 10:24am UTC](https://discourse.codecombat.com/t/finally-solved-thunderhooves/2326/1 "2015-01-13T10:24:04Z")

</div>

After around thirty minutes I finally solved the level Thunderhooves! It actually proved to be difficult compared to most of the previous levels, I myself have little programming knowledge prior to code combat and was having trouble at first with the level. I remembered previously it stated that enemies can have a position assigned as well as myself. I would have not been able to solve the puzzle if I had not remembered that.

I would like to make a suggestion, a full out solution for an example would be a bad idea as that would make things too easy. On the self.pos item it would have made my night a little less hectic had there been a tip or reminder that enemies also have positions assigned to them. With that little tip it would have been much more smooth to solve the problem. It does mention in the help section that the yak has a position, just was not to clear the formula is similar to finding our own.

I enjoyed the challenge even though it was quite frustrating! I simply feel as if a younger person was in my predicament and new to coding, they would have had a very difficult time.

---

<div class="post-metadata">

**Author:** ![Vettax](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vettax/32/1514_2.png) [@Vettax](https://discourse.codecombat.com/u/Vettax)\
**Post date:** [January 13, 2015, 12:33pm UTC](https://discourse.codecombat.com/t/finally-solved-thunderhooves/2326/2 "2015-01-13T12:33:53Z")

</div>

I’m agree with you. Properties and method for this are quite well explained, but that’s not the case for the ennemy or object.  
When the debugger was allowed, it was possible to view information about a variable, but that’s not the case anymore.

---

<div class="post-metadata">

**Author:** ![J\_F\_B\_M](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_f_b_m/32/2756_2.png) [@J\_F\_B\_M](https://discourse.codecombat.com/u/J_F_B_M)\
**Post date:** [January 13, 2015, 12:53pm UTC](https://discourse.codecombat.com/t/finally-solved-thunderhooves/2326/3 "2015-01-13T12:53:58Z")

</div>

Feel free to edit the hints of the level. When you feel that everything important is mentioned, submit a patch and it will eventually be incorporated.

In the [level-editor](http://codecombat.com/editor/level) you can adjust the help-texts ect. Simply submit a patch after you  
finished, and if it fits the intentions, it will be accepted and  
included in the level.

The concrete level in the editor is actually [this one](http://codecombat.com/editor/level/thunderhooves), the above is the general link.  
You can access the example-code by doubleclicking the Hero-Placeholder, scrolling down to programming.Programmable, expanding programmable methods and then plan.

You can adjust languages, source and comments.

---

<div class="post-metadata">

**Author:** ![deboerss](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@deboerss](https://discourse.codecombat.com/u/deboerss)\
**Post date:** [January 25, 2015, 9:29pm UTC](https://discourse.codecombat.com/t/finally-solved-thunderhooves/2326/4 "2015-01-25T21:29:16Z")

</div>

My JS code looks like this:

```python
loop {
    var enemy = this.findNearestEnemy();
    if (enemy){
        if (this.distanceTo(enemy) < 20){
            var x = enemy.pos.x;
            var y = enemy.pos.y - 10;
            this.buildXY("fence", x, y);
        }
        if (this.distanceTo(enemy) > 10){
            x = enemy.pos.x;
            y = enemy.pos.y + 10;
            this.buildXY("fence", x, y);
        pass;
        }
        else {
            // Move right 10m towards the oasis.
            pass;
            x = this.pos.x + 10;
            y = this.pos.y;
            this.moveXY(x, y);
        }
    }
}

```

Why won’t it work?

---

<div class="post-metadata">

**Author:** ![J\_F\_B\_M](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_f_b_m/32/2756_2.png) [@J\_F\_B\_M](https://discourse.codecombat.com/u/J_F_B_M)\
**Post date:** [January 31, 2015, 6:24pm UTC](https://discourse.codecombat.com/t/finally-solved-thunderhooves/2326/5 "2015-01-31T18:24:13Z")

</div>

Fixed your indentations.

You only ever have the possibility to move if there is an enemy visible. You may want to change it to

```python
loop{
    var enemy = this.findNearestEnemy();
    if(enemy){
        //Deal with it
    }
    else{
        //Move towards oasis
    }
}

```

To further improve this: Check also the distance to the enemy if your visual range is to big.

```python
if (enemy && this.distanceTo(enemy) < 9001)

```

This works even if no enemy is present, because the condition exits early when it can’t be fullfilled anymore.  
If there is no enemy, the AND can’t become `true` anymore, therefore you won’t get an error because you try to `this.distanceTo(null)`.
