prisskreative
8/6/2015 - 2:24 AM

Codecombat Game

Codecombat Game

loop {
    var enemy1 = this.findNearestEnemy();
    this.attack(enemy1);
    this.moveRight(2);
    var enemy2 = this.findNearestEnemy();
    this.attack(enemy2);
}


// -------------

// The commands below an if statement only run when the if's condition is true.
// Fix all the if-statements to beat the level.

// == means "is equal to".
if (1 + 3 + 1 == 3) {  // ∆ Make this false.
    this.moveXY(5, 15);  // Move to the first mines.
}
if (2 + 3 == 5) {  // ∆ Make this true.
	this.moveXY(15, 40);  // Move to the first gem.
}
// != means "is not equal to".
if (2 + 2 == 4) {  // ∆ Make this true.
	this.moveXY(25, 15);  // Move to the second gem.
}
// < means "is less than".
if (2 + 2 > 3) {  // ∆ Make this true.
    var enemy = this.findNearestEnemy();
    this.attack(enemy);
}
if (2 > 4) {  // ∆ Make this false.
	this.moveXY(40, 55);
}
if (false) {  // ∆ Make this false.
	this.moveXY(50, 10);
}
if (true) {  // ∆ Make this true.
	this.moveXY(55, 25);
}
// You can put one if-statement within another if-statement.
// However, doing so can be tricky, so you have to pay close attention to how the if statements interact with each other.
// Use comments to describe your logic in plain language!
// It's helpful to start with one outer if/else, using comments as placeholders for the inner if/else, like so:
loop {
    var enemy = this.findNearestEnemy();
    
    // If there is an enemy, then...
    if(enemy) {
        // Create a distance variable with distanceTo.
        var distance = this.distanceTo(enemy);
        
        // If the enemy is less than 5 meters away, then attack()       
        if (distance < 5){
            this.attack(enemy);
        }   
        // Otherwise (the enemy is far away), then shield()
        else if (enemy > 5){
            this.shield(enemy);
    // Otherwise (there is no enemy...)
        }
    } else {
        // ... then move back to the X.
        this.moveXY(40, 34);
    }
}