Codecombat Raiders game --JavaScript Writing language - level (Computer Science four) Ⅰ

1st Off: dust

// use the loop until you kill 10 Munchkins 
var Attacks = 0; 
the while (Attacks <10) { 
    // attack the nearest enemy! 
    Enemy hero.findNearestEnemy = var (); 
    IF (Enemy) { 
        hero.attack (Enemy); 
    } 
    // increment means 1 increases. 
    // "attacks" variable is incremented. 1 
    Attacks + =. 1; 
} 
// if you finish, retreat to ambush. 
hero.say ( "Should the I Retreat!"); 
// Do not stand there gab [Delta]! Quickly withdrawn ambush 
hero.moveXY (79, 33);

 

2 off: Review

// First, beat 6 ~ Ogres 
// then collecting coins until you have 30 gold. 
// variable used to count ogres 
var defeatedOgres = 0; 
// not defeat 6 ogres, continue to play 
the while (defeatedOgres <. 6) { 
    var hero.findNearestEnemy Enemy = (); 
    IF (Enemy) { 
        hero.attack (Enemy ); 
        defeatedOgres + =. 1; 
    } the else { 
        hero.say ( "Ogre!"); 
    } 
} 
// map to the right. 
hero.moveXY (49, 36); 
// save enough money is not 30, it continues to pick up 
the while (hero.gold <30) { 
    // find and collect coins 
    var = hero.findNearestItem Item (); 
    IF (Item) { 
        hero.moveXY (item.pos.x, item.pos.y); 
    } // remove the line say (). 
} 
// move to the outlet. 
Hero.moveXY (76, 32);

 

3 Off: Wind and bovine Valley

// Desert Storm is coming! 
// yak able to predict sand storm Desert 
// this loop judgment condition as variable 
var yak = hero.findNearestEnemy (); 
// Check if there is the presence of sand yak 
the while (Yak) { 
    var = hero.findNearestItem Item ( ); 
    IF (Item) { 
        hero.moveXY (item.pos.x, item.pos.y); 
    } 
    // update the value of the variable `yak` 
    // use findNearestEnemy () 
    var hero.findNearestEnemy Yak = (); 
} 
// cow gone! 
// Go evacuation point: Red the X- 
hero.moveXY (38, 58);

 

4 Off: first you have to pay, for returns

// changing the condition of the while loop. 
// when the value is greater than 200 life-blood hero, it has been run. 
the while (hero.health> 200) { 
    // delta line to change it! 
    hero.moveXY (48, 24); 
    hero.moveXY (16, 24); 
} 
// Okar to move there. 
hero.moveXY (32, 40);

 

Level 5: Desert Battle

// while loop repeats until the condition is no. 
ordersGiven = 0 var; 
the while (ordersGiven <. 5) { 
    // move 10 meters down 
    var X = hero.pos.x; 
    var Y = hero.pos.y; 
    Y = Y - 10; 
    hero.moveXY (X, Y ); 
    // use hero.say command your allies 'attack'! 
    // You just stand on X mark, they can listen to you 
    hero.say ( "Attack!"); 
    // make sure to add ordersGiven 1 
    ordersGiven + = 1; 
} 
the while (to true) { 
    var = Enemy hero.findNearestEnemy ( ); 
    // when you finish orders, immediately join the fight! 
    IF (Enemy) { 
        hero.attack (Enemy); 
    } 
}

 

Level 6: bait and switch

// use bait to lure Ogre lured to the trap. 
// This function allows the hero continued to collect gold coins, gold coins have until the number of enoughGold. 
collectUntil function (enoughGold) { 
    // when While hero.gold less than enoughGold: 
    the while (hero.gold <enoughGold) { 
        // find a coin, and take it away: 
        var = COIN hero.findNearestItem (); 
        IF (COIN) { 
            hero.moveXY (coin.pos.x, coin.pos.y); 
        } 
    } 
} 
// 25 coins collected, and then build a bait on the red marker 
collectUntil (25); 
hero.buildXY ( "decoy", 40, 52); 
// best to hide. 
hero.moveXY (20 is, 52 is); 
// Use collectUntil collection function 50 coins: 
collectUntil (50); 
// create a "decoy" marks on the bone: 
hero.buildXY ( "decoy", 68, 22 is); 
/ / establish a "decoy" on the wooden marker:
hero.buildXY("decoy", 30, 20);

 

7 Off: mirage

// lure Ogre into an ambush! 
// When your gold is less than 25, collect coins. 
while (hero.gold <25) { 
    var = COIN hero.findNearestItem (); 
    hero.moveXY (coin.pos.x, coin.pos.y); 
} 
// After the while loop, in the construction of a white X " decoy ". 
hero.buildXY ( "decoy", 72, 68); 
// while loop, when your health equal maxHealth, `say` used to challenge Ogre. 
while (hero.health == hero.maxHealth) { 
    Hero. say ( 'still stunned with what, quickly hit me ah! "); 
} 
// then return to the red X at. 
hero.moveXY (22, 16);

 

8 Off: Spinach powder

// collect seven spinach syrup. 
// Then you will be strong enough to defeat the ogre. 
potionCount = 0 var; 
// write code medicine collected while loop 
// check the amount of medicine potionCount 
while (to true) { 
    Item hero.findNearestItem = var (); 
    IF (Item) { 
        hero.moveXY (item.pos.x , item.pos.y); 
        potionCount + =. 1; 
    } 
    iF (potionCount ==. 7) { 
        BREAK; 
    } 
} 
// At the end of the while loop, 
// to fight! 
the while (to true) { 
    var hero.findNearestEnemy Enemy = (); 
    IF (Enemy) { 
        hero.attack (Enemy); 
    } 
}

 

9 Off: Teamwork

// gem will soon disappear. You need help! 
// findItems () returns an array of items. 
items hero.findItems = var (); 
// get the first jewel from the array. 
// Do not forget the first index is 0. 
gem0 = items var [0]; 
// # Tell Bruno to get gem0 
hero.say ( "Bruno" + gem0); 
// You can not reference variables gem. 
hero.say ( "Matilda" + items [1]); 
// create a variable for the last gem [2]: 
hero.say ( "Lisa" + items [2]); 
// use moveXY () to move to the position gemstone 
hero.moveXY (items [2] .pos.x, items [2] .pos.y);

 

Level 10: assist defense

// to protect farmers from the ogre damage. 
the while (to true) { 
    // get an enemy array. 
    hero.findEnemies enemies = var (); 
    // if the array is not empty. 
    IF (enemies.length> 0) { 
        // first enemy attack from "enemies" array. 
        hero.attack (enemies [0]); 
        // return to the starting position. 
        hero.moveXY (40, 20 is); 
    } 
}

 

11 Off: Recruitment Team

// call one by one farmer. 
// Neutral unit is detected as the enemy. 
Neutrals hero.findEnemies = var (); 
the while (to true) { 
    IF (neutrals.length) { 
        // speaks the first element of the array say neutral 
        hero.say (Neutrals [0]); 
    } the else { 
        hero.say ( "nobody here"); 
    } 
    // use findEnemies () neutral newly updated array 
    var = hero.findEnemies Neutrals (); 
}

 

12 Off: second gem

// jewel is safe, the other one is the bomb. 
// But you know the answer: always choose the second. 
the while (to true) { 
    var = hero.findItems items (); 
    // if the number of array elements is greater than or equal to Item 2: 
    IF (items.length> = 2) { 
        // the article is moved to the second array 
        hero. moveXY (items [. 1] .pos.x, items [. 1] .pos.y); 
    } // else: 
    the else { 
        // move to the center mark. 
        hero.moveXY (40, 34 is); 
    } 
}

 

13 Off: Sarven Savior

// an array (Array) is the number of columns in the article. 
// This array is the number of columns in a friend's name. 
friendNames = var [ 
    'Joan', 
    'Ronan', 
    'Nikita', 
    'Augustus' 
]; 
// array counts from zero, not 1! 
friendIndex = 0 var; 
// for each cycle of the array name 
// use .lenght property to obtain the length of the array. 
the while (friendIndex <friendNames.length) { 
    // square brackets to obtain the array name. 
    friendNames FRIENDNAME = var [friendIndex]; 
    // Tell your friends back home. 
    + // use to connect two strings. 
    hero.say (FRIENDNAME + ', Go Home!'); 
    // increase in the index to get the next name in the array 
    friendIndex + = 1; 
} 
// return to the oasis, built in the X at the "fence" 
hero.moveXY (15 , 30); 
hero.buildXY ( "fence", 30, 30);

 

14 Off: Bank raid

// Wait ogre, beat them and collect gold. 
the while (to true) { 
    var enemies hero.findEnemies = (); 
    // iterate enemyIndex array. 
    enemyIndex = 0 var; 
    // enemyIndex although less than enemies.length 
    the while (enemyIndex <enemies.length) { 
        // the enemy attack enemyIndex 
        var = Enemy enemies [enemyIndex]; 
        hero.attack (Enemy); 
        // add 1 to enemyIndex . 
        ++ enemyIndex; 
    } 
    var = hero.findItems Coins (); 
    // iterate coinIndex coins array. 
    coinIndex = 0 var; 
    the while (coinIndex <coins.length) { 
        // coinIndex obtained with a gold coins from the array. 
        Coins COIN = var [coinIndex]; 
        // collect the coins.
        hero.moveXY (coin.pos.x, coin.pos.y); 
        // coinIndex to increase the value 1. 
        ++ coinIndex; 
    } 
}

 

15 Off: disembodied spirits

Skeleton @ attack seized gem 
the while (to true) { 
    var enemies hero.findEnemies = (); 
    var enemyIndex = 0; 
    the while (enemyIndex <enemies.length) { 
        ; = var Enemy enemies [enemyIndex] 
        // the blood enemy attack. 
        the while (enemy.health> 0) { 
            hero.attack (Enemy); 
        } 
        enemyIndex + =. 1; 
    } 
    var = hero.findItems items (); 
    var itemIndex = 0; 
    // iterate through all items. 
    the while (itemIndex <items.length) { 
        var = Item items [itemIndex]; 
        // distance is greater than the article 2: 
        the while (hero.distanceTo (Item)> 2) { 
            // try to get the items 
            hero.moveXY (item. pos.x, item.pos.y);
            // Do not forget to make larger itemIndex (itemIndex + = 1) or (+ itemIndex = itemIndex. 1) 
            itemIndex + =. 1; 
        } 
    } 
}

 

Guess you like

Origin www.cnblogs.com/shihaiying/p/11706755.html