diff --git a/index.html b/index.html index b0650a0..e6badaa 100644 --- a/index.html +++ b/index.html @@ -146,6 +146,7 @@ + diff --git a/js/achievements.js b/js/achievements.js new file mode 100644 index 0000000..ee0c115 --- /dev/null +++ b/js/achievements.js @@ -0,0 +1,55 @@ +var achievements = +{ + list: [], + + count: + { + clicks: 0, + data: 0, + money: 0 + }, + + workers: {}, + research: {}, + + setList: function(list) + { + achievements.list = list; + achievements.list.map(function (item) { // define additional stuff on the objects + item.completed = false; + item.is_visible = function() { + return this.completed; + }; + }); + }, + + addWorkers: function(list) + { + for (var i = 0; i < list.length; i++) { + achievements.workers[list[i].name] = 0; + } + }, + + addResearch: function(list) + { + for (var i = 0; i < list.length; i++) { + achievements.research[list[i].name] = 0; + } + }, + + update: function(type, subtype, val) + { + achievements[type][subtype] += val; + + for (var i = 0; i < achievements.list.length; i++) { + if (achievements.list[i].type == type && + achievements.list[i].target == subtype && + achievements.list[i].threshold >= achievements[type][subtype] + ) + { + achievements.list[i].completed = true; + } + } + } +}; + diff --git a/js/game.js b/js/game.js index 4399bfe..d77970c 100644 --- a/js/game.js +++ b/js/game.js @@ -31,10 +31,13 @@ reputation: 0, money: 0, getGrant: function () { - this.money += this.reputation * this.factor.rate; // TODO: adjust factor, 5 + var addition = this.reputation * this.factor.rate; // TODO: adjust factor + this.money += addition; + achievements.count.money += addition; }, acquire: function(amount) { this.data += amount; + achievements.count.data += amount; }, research: function(cost, reputation) { if (this.data >= cost) { @@ -55,8 +58,11 @@ this.money += cost; } }; + + achievements.setList(loadFile('json/achievements.json')); var research = loadFile('json/research.json'); + achievements.addResearch(research); research.map(function(item) { item.level = 0; item.is_visible = function() { @@ -69,6 +75,7 @@ if (lab.research(this.cost, this.reputation)) { this.level++; this.cost = Math.round(this.cost * this.cost_increase); + achievements.research[this.name]++; } }; item.getInfo = function() { @@ -83,6 +90,7 @@ }); var workers = loadFile('json/workers.json'); + achievements.addWorkers(workers); workers.map(function(worker) { worker.hired = 0; worker.is_visible = function() { @@ -95,6 +103,7 @@ if (lab.buy(this.cost)) { this.hired++; this.cost = Math.round(this.cost * this.cost_increase); + achievements.update('workers', this.name, 1); } }; }); @@ -183,6 +192,7 @@ this.click = function() { lab.acquire(lab.detector.rate); detector.addEvent(); + achievements.count.clicks += 1; return false; }; }); @@ -216,4 +226,8 @@ app.controller('UpgradesController', function() { this.upgrades = upgrades; }); + + app.controller('AchievementsController', function () { + this.achievements = achievements.list; + }); })(); diff --git a/json/achievements.json b/json/achievements.json new file mode 100644 index 0000000..2a46857 --- /dev/null +++ b/json/achievements.json @@ -0,0 +1,29 @@ +[ + { + "name": "Discovered Z-Boson", + "description": "Achievement: You just discoverd Z-Boson!", + "difficulty": "1", + "type": "research", + "target": "Z-Boson", + "threshold": 1, + "image": "assets/Z.png" + }, + { + "name": "Discovered top-Quark", + "description": "Achievement: You just discovered top-Quark", + "difficulty": "2", + "type": "research", + "target": "top-Quark", + "threshold": 1, + "image": "assets/t.png" + }, + { + "name": "Hired First Nobel Prize Winner", + "description": "Achievement: Yo! You have hired your first nobel prize winner!", + "difficulty": "5", + "type": "workers", + "target": "PhD Students", + "threshold": 1, + "image": "assets/W.png" + } +]