Skip to content

Instantly share code, notes, and snippets.

@DGAcode
DGAcode / Cloudrip Commander
Created July 18, 2016 13:27
CodeCombat.com Solutions, Cloudrip Mountain. Here's a simple gist of my Code Combat solutions. Javascript. Object literals, remote method invocation, for-loops, functions, drawing, modulo
// 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", {
@DGAcode
DGAcode / Crux of the Desert
Last active September 22, 2016 22:05
CodeCombat.com Solutions, Sarven Desert. Here's a simple gist of my Code Combat solutions. Javascript. 4-11 hours: arithmetic, counters, while-loops, break, arrays, string comparison, finding min/max
// 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;