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

View file

@ -1,3 +1,5 @@
export function random_number(min, max) {
return Math.floor((Math.random() * max) + min);
};
class Helper {
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 {
constructor() {
this.ticks = 0;
this.current_asteroid = new Asteroid();
this.asteroids = [this.current_asteroid];
this.resources = {
dust: 0,
crystals: 0
@ -16,6 +16,7 @@ class Engine {
update() {
document.querySelector('#time').innerHTML = this.ticks + ' hours';
document.querySelector('#res-dust').innerHTML = this.resources.dust;
document.querySelector('#res-crystals').innerHTML = this.resources.crystals;
}
}
@ -25,20 +26,19 @@ class Player {
}
mine() {
console.log('mine');
this.engine.resources.dust++;
let type = this.engine.current_asteroid.mine_resource();
this.engine.resources[type]++;
}
}
class Asteroid {
mine_resource() {
console.log(random_number(2, 10));
return ['dust', 'dust', 'dust', 'crystals'][Helper.random_number(0, 4)];
}
}
var engine = new Engine();
var player = new Player(engine);
var current_asteroid = new Asteroid();
var bootstrap = function() {
setInterval(() => {