This file contains hidden or 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
/*----------------------------------------------------- | |
REQUIRE | |
-------------------------------------------------------*/ | |
var yo = require('yo-yo') | |
var csjs = require('csjs-inject') | |
var minixhr = require('minixhr') | |
/*----------------------------------------------------- | |
THEME | |
-------------------------------------------------------*/ | |
var font = 'Kaushan Script, cursive' |
This file contains hidden or 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
/*----------------------------------------------------- | |
REQUIRE | |
-------------------------------------------------------*/ | |
var yo = require('yo-yo') | |
var csjs = require('csjs-inject') | |
var minixhr = require('minixhr') | |
/*----------------------------------------------------- | |
THEME | |
-------------------------------------------------------*/ | |
var font = 'Kaushan Script, cursive' |
This file contains hidden or 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
/*----------------------------------------------------- | |
REQUIRE | |
-------------------------------------------------------*/ | |
var yo = require('yo-yo') | |
var csjs = require('csjs-inject') | |
var minixhr = require('minixhr') | |
/*----------------------------------------------------- | |
THEME | |
-------------------------------------------------------*/ | |
var font = 'Kaushan Script, cursive' |
This file contains hidden or 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
/*----------------------------------------------------------------------------- | |
REQUIRE | |
-----------------------------------------------------------------------------*/ | |
var yo = require('yo-yo') | |
var csjs = require('csjs-inject') | |
var minixhr = require('minixhr') | |
/*----------------------------------------------------------------------------- | |
THEME | |
-----------------------------------------------------------------------------*/ | |
var FONT = 'Ubuntu, sans-serif' |
This file contains hidden or 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
/*----------------------------------------------------------------------------- | |
REQUIRE | |
-----------------------------------------------------------------------------*/ | |
var yo = require('yo-yo') | |
var csjs = require('csjs-inject') | |
var minixhr = require('minixhr') | |
/*----------------------------------------------------------------------------- | |
THEME | |
-----------------------------------------------------------------------------*/ | |
var FONT = 'Ubuntu, sans-serif' |
This file contains hidden or 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
function summonHero (name, position) { | |
return { | |
say: function (sentence) { | |
alert(sentence); | |
}, | |
move: function (position) { | |
console.log('Moving to x=' + position.x + ' and y=' +position.y); | |
this.pos = position; | |
}, | |
name: name, |
This file contains hidden or 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
// Your goal is to keep at least one flower alive for 60 seconds. | |
// set 3 new locations | |
var LOCATIONS = [ | |
{x: 72, y: 44}, | |
{x: 49, y: 59}, | |
{x: 50, y: 25}, | |
{x: 23, y: 43} | |
]; | |
// loop through all locations | |
// build a tower on each of them |
This file contains hidden or 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
this.chooseStrategy = function () { | |
var enemies = this.findEnemies(); | |
if (this.gold >= this.costOf("griffin-rider")) { | |
this.summon("griffin-rider"); | |
return "griffin-rider"; | |
} else if (enemies) { | |
for (var i = 0; i < enemies.length; i++) { | |
var enemy = enemies[i]; | |
if (enemy && enemy.type === "fangrider") { | |
return "fight-back"; |
This file contains hidden or 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
// Practice using modulo to loop over an array | |
this.pickUpNearestCoin = function() { | |
var items = this.findItems(); | |
var nearestCoin = this.findNearest(items); | |
if(nearestCoin) { | |
this.move(nearestCoin.pos); | |
} | |
}; |
This file contains hidden or 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
while (this.gold < 81) { | |
var coin = this.findNearest(this.findItems()); | |
this.move(coin.pos); | |
} | |
if (this.gold > this.costOf("soldier")) { | |
this.summon("soldier"); | |
} | |
for (var i=0; i < 4; i++) { |