From 92dbc0fc58c1b5fe867826f90fc711e7b540dd17 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Tue, 25 Aug 2015 09:16:58 +0200 Subject: [PATCH] Mine crystals --- Makefile | 8 ++++---- src/helpers.js | 8 +++++--- src/main.js | 12 ++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index bed1eea..7048569 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/helpers.js b/src/helpers.js index 7cb3639..eff9f51 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -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); + } +} diff --git a/src/main.js b/src/main.js index 098b7c0..7a2f77d 100644 --- a/src/main.js +++ b/src/main.js @@ -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(() => {