[решена]/[SOLVED] Помогите с задачкой

Да да привет еще раз кто поможет разобраться с солёной землёй? В лесу почти последняя задача

Пожалуйста, не могли бы вы опубликовать свой код, как указано в https://discourse.codecombat.com/faq
и скажи мне, с чем у тебя проблемы.
Спасибо

Please could you post your code as stated in the https://discourse.codecombat.com/faq
and tell me what you’re having trouble with.
Thanks
:lion: :lion: :lion:

while (true) {
var enemy = hero.findNearestEnemy();
if (enemy.type == “munchkin” || enemy.type == “thrower”) {
hero.attack(enemy);
}
var item = hero.findNearestItem();
// Проверь тип предмета, чтобы не поднять случайно яд!
// Если тип предмета “gem” или “coin”
if (item.type == “poison” || enemy.type == “burl”) {
hero.moveXY(22, 30);
hero.moveXY(22, 43);
hero.moveXY(37, 39);
}
if (item.type == “gem” || item.type == “coin”) {
hero.moveXY(48, 33);
hero.moveXY(45, 52);
hero.moveXY(37, 55);
} // Тогда иди и возьми его:
}

Прежде всего, не могли бы вы отформатировать свой код. Как говорится в FAQ.
Во-вторых, вы двигаетесь к определенным координатам, когда вы должны двигаться к координатам объектов. Например: драгоценный камень или монета.
Это «жестко запрограммированная» координата:
hero.moveXY(19, 69);
И это перемещение в положение объекта (в данном случае, монеты):

item = hero.findNearestItem ();
if(item.type == "gem" || or item.type == "coin") {
     hero.moveXY(item.pos.x, item.pos.y);
}

На этом уровне вы хотите перейти к позиции монет, а не к позиции, которую вы жестко закодировали.
Потому что каждый раз, когда вы нажимаете кнопку отправки, монеты будут появляться в случайных местах. Они не всегда приходят в одни и те же места.
Наконец, эта часть вашего кода не обязательна. Если он не говорит вам что-то делать в комментариях, лучше этого не делать:

if (item.type == "poison" || enemy.type == "burl") {
        hero.moveXY (22, 30);
        hero.moveXY (22, 43);
        hero.moveXY (37, 39);
    }

Надеюсь, это поможет.

First of all, please could you format your code. Like it says in the faq.
Secondly, you’re are moving to specific coordinates when you should be moving to coordinates of objects. For example: a gem or coin.
This is a “hard-coded” coordinate:
hero.moveXY(19, 69);
And this is moving to the position of an object (in this case, a coin):

item = hero.findNearestItem();
if(item.type == "gem" || or item.type == "coin") {
     hero.moveXY(item.pos.x, item.pos.y);
}

In this level, you want to move to the position of the coins, not a position you have “hard-coded”.
Because every time you press the submit button the coins will come in random locations. They don’t always come in the same spots.
Finally, this part of your code:

    if (item.type == "poison" || enemy.type == "burl") {
        hero.moveXY(22, 30);
        hero.moveXY(22, 43);
        hero.moveXY(37, 39);
    }

is not neccesary. If it doesn’t tell you to do something in the comments, it’s best not to do it.
I hope this helps.
:lion: :lion: :lion:

Это что так просто было?? Господи ! Спасибо тебе чувак! А так можно вообще ? А проверить тип предмета как:?

Да, вы всегда можете собрать предмет (зелье или монету), перейдя к его .pos.x / .pos.y. Вы уже проверяете правильные типы:"gem" + "coin"
Yes, you can always collect an item (potion or coin) by going to its .pos.x / .pos.y. You are already checking the correct types: "gem" + "coin"
:lion: :lion: :lion:

1 Like