Code Combat|SHORT-SIGHTED BURL(java script)の解答

結構悩んだので共有します。自力で解きたい方は見ないようにしてください。

Code Combat, SHORT-SIGHTED BURL (java script) stage solution.

画面全体
code
// Collect coins and run, or else the burl will find you.

// This function allows your hero take an item.
function takeItem(item) {
    hero.moveXY(item.pos.x, item.pos.y);
}

// Write the function "checkTakeRun" with one parameter.
// If the item exists, use "takeItem" function to take it.
// Go back to the start (green mark), with or without the item.
function checkTakeRun(target) {
if (target) {
    hero.moveXY(target.pos.x, target.pos.y);
}
    hero.moveXY(40, 12);
}

// Don't change this code.
while (true) {
    hero.moveXY(16, 56);
    var coin = hero.findNearestItem();
    checkTakeRun(coin);
    
    hero.moveXY(64, 56);
    coin = hero.findNearestItem();
    checkTakeRun(coin);
}

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA