diff --git a/assets/beer.png b/assets/beer.png new file mode 100644 index 0000000..304ce9f Binary files /dev/null and b/assets/beer.png differ diff --git a/index.html b/index.html index 8665c9a..b2e5e9c 100644 --- a/index.html +++ b/index.html @@ -9,29 +9,20 @@ - - - - - +
-
+
Your detector. Click on it to generate events. @@ -69,6 +60,16 @@
+
+ +
+

Upgrades

+
+ + {{ u.name }} + +
+
diff --git a/js/game.js b/js/game.js index bb80e05..c0856ae 100644 --- a/js/game.js +++ b/js/game.js @@ -12,9 +12,11 @@ return res; } - var lab = { name: 'My Awesome Lab', + detector: { + rate: 1 + }, data: 0, reputation: 0, money: 0, @@ -84,6 +86,53 @@ }; }); + var upgrades = loadJsonFile('json/upgrades.json'); + upgrades.map(function (upgrade) { + upgrade.getReceiver = function() { + if (this.type === "detector") { + return lab.detector; + } else { + var context; + if (this.type === "research") { context = research; } + else if (this.type === "hr") { context = workers; } + else { return null; } + for (var i = 0; i < context.length; i++) { + if (context[i].name === this.receiver) { + return context[i]; + } + } + return null; + } + }; + upgrade.hasReceiver = function () { + if (this.type === "detector") { + return true; + } + var rec = this.getReceiver(); + if (this.type === "research") { + return rec.level > 0; + } else if (this.type === "hr") { + return rec.hired > 0; + } + return false; + }; + upgrade.is_visible = function () { + return !this.used && this.hasReceiver() && lab.money >= this.cost * .9; + }; + upgrade.is_available = function () { + return !this.used && this.hasReceiver() && lab.money >= this.cost; + }; + upgrade.buy = function () { + if (!this.used && lab.buy(this.cost)) { + this.used = true; + var rec = this.getReceiver(); + if (rec) { + rec[this.property] = rec[this.property] * this.factor + this.constant; + } + } + }; + }); + var app = angular.module('particleClicker', []); @@ -97,8 +146,7 @@ app.controller('DetectorController', function () { this.click = function () { - lab.acquire(1); - + lab.acquire(lab.detector.rate); detector.addEvent(); }; }); @@ -122,6 +170,10 @@ app.controller('HRController', function () { this.workers = workers; }); + + app.controller('UpgradesController', function () { + this.upgrades = upgrades; + }); })(); diff --git a/json/upgrades.json b/json/upgrades.json index d21cd1e..5efdea1 100644 --- a/json/upgrades.json +++ b/json/upgrades.json @@ -2,12 +2,13 @@ { "name": "Free beer", "description": "The work is easier when the worker is happy.", - "type": "hr", // "hr" || "detector" || "research" - "reciever": "PhD Students", // name of the object "cost": 100, "used": false, + "type": "hr", + "receiver": "PhD Students", + "property": "rate", "factor": 1.2, "constant": 0, - //"image": + "image": "assets/beer.png" } -} +]