From 6305ec4087842dd7bc5d5ea0436b8b600523a3c6 Mon Sep 17 00:00:00 2001 From: Kevin Dungs Date: Sat, 2 Aug 2014 14:06:26 +0200 Subject: [PATCH] Forgot some adds. --- index.html | 37 ++++++++++++++++++ js/game.js | 89 +++++++++++++++++++++++++++++++++++++++++-- json/discoveries.json | 11 ------ 3 files changed, 122 insertions(+), 15 deletions(-) delete mode 100644 json/discoveries.json diff --git a/index.html b/index.html index 88a6852..68227c0 100644 --- a/index.html +++ b/index.html @@ -4,9 +4,46 @@ Particle Clicker + + +
+ Your detector. Click on it to generate events. +
+ +
+

{{ lc.lab.name }}

+

Data: {{ lc.lab.data }}

+

Reputation: {{ lc.lab.reputation }}

+

Money: {{ lc.lab.money }}

+
+ +
+

Research

+
+

{{ r.name }}

+

{{ r.description }} Level: {{ r.level }}

+ +
+
+ +
+

HR Department

+
+

{{ w.name }}

+

{{ w.description }} You have {{ w.hired }} of them working for you.

+ +
+
+ diff --git a/js/game.js b/js/game.js index fb5c6cd..e954577 100644 --- a/js/game.js +++ b/js/game.js @@ -1,4 +1,7 @@ 'use strict'; + +var DEBUG = true; + (function () { var loadJsonFile = function(filename) { var res; @@ -12,14 +15,92 @@ return res; } + var lab = { + name: 'My Awesome Lab', + data: 0, + reputation: 0, + money: 0, + getGrant: function () { + this.money += this.reputation * 10; // TODO: adjust factor + }, + acquire: function (amount) { + this.data += amount; + }, + research: function (cost, reputation) { + if (this.data >= cost) { + this.data -= cost; + this.reputation += reputation; + return true; + } + return false; + }, + buy: function(cost) { + if (this.money >= cost) { + this.money -= cost; + return true; + } + return false; + }, + sell: function(cost) { + this.money += cost; + } + }; + + /* Construct research object from json file. + * Additional attribute level keeps track of the current upgrade status. + * Also add functionality to research each item. + */ + var research = loadJsonFile('json/research.json'); + research.map(function (item) { // define additional stuff on the objects + item.level = 0; + item.is_available = function () { + return this.level > 0 || lab.data > item.cost * .9; + }; + item.research = function () { + if (lab.research(this.cost, this.reputation)) { + this.level++; + } + } + }); + if (DEBUG) console.log(research); - var discoveries = loadJsonFile('json/discoveries.json'); var workers = loadJsonFile('json/workers.json'); - - console.log(discoveries); - console.log(workers); + workers.map(function (worker) { + worker.hired = 0; + worker.hire = function() { + if (lab.buy(this.cost)) { + this.hired++; + } + }; + }); var app = angular.module('particleClicker', []); + + app.controller('DetectorController', function () { + this.click = function () { + lab.acquire(1); + }; + }); + + app.controller('LabController', ['$interval', function ($interval) { + this.lab = lab; + $interval(function () { // one tick + lab.getGrant(); + var sum = 0; + for (var i = 0; i < workers.length; i++) { + sum += workers[i].hired * workers[i].rate; + } + lab.acquire(sum); + }, 1000); + }]); + + app.controller('ResearchController', function () { + this.research = research; + }); + + app.controller('HRController', function () { + this.workers = workers; + }); })(); diff --git a/json/discoveries.json b/json/discoveries.json deleted file mode 100644 index ba4b3f0..0000000 --- a/json/discoveries.json +++ /dev/null @@ -1,11 +0,0 @@ -[ - { - "name": "W-Boson", - "description": "The W-Boson is the carrier boson of the weak force.", - "research": { - "reputation": 1, - "cost": 100 - }, - "histogram": {} - } -]