This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Summon some soldiers, then direct them to your base. | |
// Each soldier costs 20 gold. | |
while (hero.gold > hero.costOf("soldier")) { | |
hero.summon("soldier"); | |
} | |
var soldiers = hero.findFriends(); | |
var soldierIndex = 0; | |
// Add a while loop to command all the soldiers. | |
for (var i = 0; soldierIndex < soldiers.length; i++) { | |
hero.command(soldiers[i], "move", { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ogres are assaulting the Crux of the Desert! | |
// Defend against the waves by checking which direction the ogres are coming from. | |
// Store the results of comparisons as variables to make your code easy to read. | |
while (true) { | |
var enemy = hero.findNearestEnemy(); | |
if (enemy) { | |
// An enemy is to the left if the hero's x is greater than the enemy's. | |
var isLeft = hero.pos.x > enemy.pos.x; | |
// An enemy is above if the enemy's y is greater than the hero's. | |
var isAbove = hero.pos.y < enemy.pos.y; |