mirror of
https://github.com/wassname/cardsforscience.git
synced 2026-06-27 21:06:32 +08:00
Basic achievements
This commit is contained in:
@@ -146,6 +146,7 @@
|
||||
|
||||
<script src="js/event.js"></script>
|
||||
<script src="js/detector.js"></script>
|
||||
<script src="js/achievements.js"></script>
|
||||
<script src="js/game.js"></script>
|
||||
<script src="js/ui.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+15
-1
@@ -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;
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user