From a58b3b42b9cee875adaf9fd9ff99a63a134e6466 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Tue, 25 Aug 2015 16:04:47 +0200 Subject: [PATCH] Add more resources --- src/index.html | 10 +++++++--- src/main.js | 32 +++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/index.html b/src/index.html index 4fe85cc..4988194 100644 --- a/src/index.html +++ b/src/index.html @@ -8,12 +8,16 @@ - +

Asteroid classification:

+ + diff --git a/src/main.js b/src/main.js index 7a2f77d..095ea0f 100644 --- a/src/main.js +++ b/src/main.js @@ -1,3 +1,5 @@ +// Theme: Reversed + class Engine { constructor() { this.ticks = 0; @@ -5,7 +7,9 @@ class Engine { this.asteroids = [this.current_asteroid]; this.resources = { dust: 0, - crystals: 0 + stone: 0, + carbon: 0, + metal: 0 } } @@ -15,8 +19,12 @@ class Engine { update() { document.querySelector('#time').innerHTML = this.ticks + ' hours'; + document.querySelector('#asteroid-classification').innerHTML = this.current_asteroid.classification; + document.querySelector('#res-dust').innerHTML = this.resources.dust; - document.querySelector('#res-crystals').innerHTML = this.resources.crystals; + document.querySelector('#res-stone').innerHTML = this.resources.stone; + document.querySelector('#res-carbon').innerHTML = this.resources.carbon; + document.querySelector('#res-metal').innerHTML = this.resources.metal; } } @@ -32,8 +40,24 @@ class Player { } class Asteroid { + constructor() { + // Determine the class + this.classification = [ + 'A', // small, stone, dust, random + 'C', // dark carbon + 'S', // stone + 'X' // metal + ][Helper.random_number(0, 4)]; + } + mine_resource() { - return ['dust', 'dust', 'dust', 'crystals'][Helper.random_number(0, 4)]; + let resources = { + 'A': ['dust', 'dust', 'stone'], + 'C': ['dust', 'carbon', 'carbon', 'carbon'], + 'S': ['dust', 'stone', 'stone'], + 'X': ['metal'] + }[this.classification]; + return resources[Helper.random_number(0, resources.length)]; } } @@ -50,4 +74,6 @@ var bootstrap = function() { player.mine(); engine.update(); }; + + engine.update(); };