Mine crystals

This commit is contained in:
Aaron Fischer 2015-08-25 09:16:58 +02:00
parent 50934d3672
commit 92dbc0fc58
3 changed files with 15 additions and 13 deletions

View file

@ -2,9 +2,9 @@ default: compile
compile: compile:
mkdir -p out mkdir -p out
babel src/*.js -o out/js13kgames-2015.js babel src/*.js -o out/js13kgames-2015.min.js
uglifyjs --compress --mangle -- out/js13kgames-2015.js > out/js13kgames-2015.min.js # uglifyjs --compress --mangle -- out/js13kgames-2015.js > out/js13kgames-2015.min.js
rm out/js13kgames-2015.js # rm out/js13kgames-2015.js
cp -f src/*.{html,css} out/ cp -f src/*.{html,css} out/
zip: compile zip: compile
@ -16,7 +16,7 @@ stats: zip
watch: watch:
while true; do \ while true; do \
make stats; \ make compile; \
inotifywait -qre close_write src/.; \ inotifywait -qre close_write src/.; \
done done

View file

@ -1,3 +1,5 @@
export function random_number(min, max) { class Helper {
return Math.floor((Math.random() * max) + min); static random_number(min, max) {
}; return Math.floor((Math.random() * max) + min);
}
}

View file

@ -1,8 +1,8 @@
import random_number from './helpers';
class Engine { class Engine {
constructor() { constructor() {
this.ticks = 0; this.ticks = 0;
this.current_asteroid = new Asteroid();
this.asteroids = [this.current_asteroid];
this.resources = { this.resources = {
dust: 0, dust: 0,
crystals: 0 crystals: 0
@ -16,6 +16,7 @@ class Engine {
update() { update() {
document.querySelector('#time').innerHTML = this.ticks + ' hours'; document.querySelector('#time').innerHTML = this.ticks + ' hours';
document.querySelector('#res-dust').innerHTML = this.resources.dust; document.querySelector('#res-dust').innerHTML = this.resources.dust;
document.querySelector('#res-crystals').innerHTML = this.resources.crystals;
} }
} }
@ -25,20 +26,19 @@ class Player {
} }
mine() { mine() {
console.log('mine'); let type = this.engine.current_asteroid.mine_resource();
this.engine.resources.dust++; this.engine.resources[type]++;
} }
} }
class Asteroid { class Asteroid {
mine_resource() { mine_resource() {
console.log(random_number(2, 10)); return ['dust', 'dust', 'dust', 'crystals'][Helper.random_number(0, 4)];
} }
} }
var engine = new Engine(); var engine = new Engine();
var player = new Player(engine); var player = new Player(engine);
var current_asteroid = new Asteroid();
var bootstrap = function() { var bootstrap = function() {
setInterval(() => { setInterval(() => {