Skip to content

Instantly share code, notes, and snippets.

View esova-ana's full-sized avatar

Ana Esova esova-ana

View GitHub Profile
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
@esova-ana
esova-ana / gist:9fd6594652deb7a5df6c
Last active February 10, 2016 16:06
SPECIAL CHARACTERS
{ - shift alt š
} - shift alt đ
[ - alt š
] - alt đ
= - shift 0
< - <
> - shift <
, - ,
; - shift ,
. - .
/*****************************************************************************
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();
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++) {
@esova-ana
esova-ana / gist:f25d6149730e0721d60469306289e91f
Last active April 15, 2016 02:06
CodeCombat - findFarthest/findNearest
//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];
@esova-ana
esova-ana / gist:297550888c1b63327c7985694525d3fe
Last active April 19, 2016 01:13
Functions (CodeCombat)
// 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.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";
@esova-ana
esova-ana / gist:0e18f729a8a679cb518fb2f3a958c1dd
Created May 17, 2016 19:12
Returning a function (CodeCombat) / helper
// 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
@esova-ana
esova-ana / gist:6514664630fc966dcee82a5435083bd6
Created May 17, 2016 20:45
Returning an object with functions (CodeCombat)
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,
/*-----------------------------------------------------
REQUIRE
-------------------------------------------------------*/
var yo = require('yo-yo')
var csjs = require('csjs-inject')
var minixhr = require('minixhr')
/*-----------------------------------------------------
THEME
-------------------------------------------------------*/
var font = 'Kaushan Script, cursive'