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
My Hotkeys: | |
CTRL T (in the browser) - opens a new tab | |
CTRL SHIFT T (in the browser) - reopens recently cosed tab | |
CTRL C - copy the text | |
CTRL V - paste the text |
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
{ - shift alt š | |
} - shift alt đ | |
[ - alt š | |
] - alt đ | |
= - shift 0 | |
< - < | |
> - shift < | |
, - , | |
; - shift , | |
. - . |
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
/* ////////////////////////////////////////////////////// | |
// STRINGS, NUMBERS, VARIABLES AND LOOPS // | |
//////////////////////////////////////////////////////*/ | |
// 1. Single-line comments start with two slashes. | |
/* Multiline comments start with slash-star, | |
and end with star-slash */ | |
// 2. JavaScript has a number type |
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
//FIND FARTHEST | |
var enemy; | |
loop { | |
var farthest = null; | |
var maxDistance = 0; | |
var enemyIndex = 0; | |
var enemies = this.findEnemies(); | |
while (enemyIndex < enemies.length) { | |
var target = enemies[enemyIndex]; |
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
/***************************************************************************** | |
Defeat the enemy hero in a duel! | |
*****************************************************************************/ | |
var SELF = this; | |
SELF.ATTACK = function (enemy, xE, yE) { | |
if (SELF.distanceTo(enemy) <= 7) { | |
SELF.attack(enemy); | |
} else { | |
if (isApproaching(enemy)) { | |
SELF.shield(); |
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
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++) { |
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
// 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 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 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 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, |
OlderNewer