mirror of
https://github.com/wassname/cardsforscience.git
synced 2026-07-13 17:42:41 +08:00
Working on this A LOT. However, at this point this version is unfinished and DOESNT WORK!
This commit is contained in:
+4
-3
@@ -88,8 +88,8 @@
|
||||
<hr>
|
||||
<ul class="media-list" ng-cloak>
|
||||
<li class="media" ng-repeat="r in rc.research" ng-show="r.is_visible()">
|
||||
<img ng-show="r.level > 0" class="pull-left" class="media-object" src="{{ r.image }}" alt="">
|
||||
<img ng-hide="r.level > 0" class="pull-left" class="media-object" src="assets/icons/png/unknown.png" alt="">
|
||||
<img ng-show="r.level > 0" class="pull-left media-object" src="{{ r.image }}" alt="">
|
||||
<img ng-hide="r.level > 0" class="pull-left media-object" src="assets/icons/png/unknown.png" alt="">
|
||||
<div class="media-body">
|
||||
<h4 class="media-heading">{{ r.level > 0 ? r.name : '?????' }} <span ng-show="r.level > 0" class="badge">Level {{ r.level }}</span></h4>
|
||||
<p ng-show="r.level > 0">{{ r.description }}</p>
|
||||
@@ -158,7 +158,7 @@
|
||||
<ul class="media-list" ng-cloak>
|
||||
<li class="media" ng-repeat="u in uc.upgrades" ng-show="u.isVisible()">
|
||||
<div class="media-body">
|
||||
<h4 class="media-heading">{{ u.name }} <i class="fa {{ u.icon }}" class="media-object"></i></h4>
|
||||
<h4 class="media-heading">{{ u.name }} <i class="fa {{ u.icon }} media-object"></i></h4>
|
||||
<p>{{ u.description }}</p>
|
||||
<p class="small">{{ u.effect }}</p>
|
||||
<button class="btn btn-primary" ng-disabled="!u.isAvailable()" ng-click="uc.upgrade(u)">Buy <small>({{ u.cost | currency }})</small></button>
|
||||
@@ -260,5 +260,6 @@
|
||||
<script src="js/ui.js"></script>
|
||||
<script src="js/game.js"></script>
|
||||
<script src="js/warnmobile.js"></script>
|
||||
<script src="js/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
'use strict';
|
||||
(function() {
|
||||
var game = new Game.Game();
|
||||
game.load();
|
||||
var lab, research, workers, upgrades;
|
||||
|
||||
$.when(game.load).then(function() {
|
||||
lab = game.lab;
|
||||
research = game.research;
|
||||
workers = game.workers;
|
||||
upgrades = game.upgrades;
|
||||
});
|
||||
|
||||
UI.validateVersion(lab.version);
|
||||
|
||||
achievements.addResearch(research);
|
||||
achievements.addWorkers(workers);
|
||||
|
||||
var app = angular.module('particleClicker', []);
|
||||
|
||||
app.filter('niceNumber', ['$filter', function($filter) {
|
||||
return Helpers.formatNumberPostfix;
|
||||
}]);
|
||||
|
||||
app.filter('currency', ['$filter', function($filter) {
|
||||
return function(input) {
|
||||
return 'JTN ' + $filter('niceNumber')(input);
|
||||
};
|
||||
}]);
|
||||
|
||||
app.filter('reverse', ['$filter', function($filter) {
|
||||
return function(items) {
|
||||
return items.slice().reverse();
|
||||
};
|
||||
}]);
|
||||
|
||||
app.controller('DetectorController', function() {
|
||||
this.click = function() {
|
||||
lab.acquire(lab.detector.rate);
|
||||
detector.addEvent();
|
||||
achievements.update('count', 'clicks', 1);
|
||||
achievements.update('count', 'data', lab.detector.rate);
|
||||
UI.showUpdateValue("#update-data", lab.detector.rate);
|
||||
return false;
|
||||
};
|
||||
});
|
||||
|
||||
app.controller('LabController', ['$interval', function($interval) {
|
||||
this.lab = lab;
|
||||
this.showDetectorInfo = function() {
|
||||
if (!this._detectorInfo) {
|
||||
this._detectorInfo = Helpers.loadFile('html/detector.html');
|
||||
}
|
||||
UI.showModal('Detector', this._detectorInfo);
|
||||
};
|
||||
$interval(function() { // one tick
|
||||
var grant = lab.getGrant();
|
||||
achievements.update('count', 'money', grant);
|
||||
UI.showUpdateValue("#update-funding", grant);
|
||||
var sum = 0;
|
||||
for (var i = 0; i < workers.length; i++) {
|
||||
sum += workers[i].hired * workers[i].rate;
|
||||
}
|
||||
lab.acquire(sum);
|
||||
achievements.update('count', 'data', sum);
|
||||
UI.showUpdateValue("#update-data", sum);
|
||||
detector.addEventExternal();
|
||||
}, 1000);
|
||||
}]);
|
||||
|
||||
app.controller('ResearchController', ['$compile', function($compile) {
|
||||
this.research = research;
|
||||
this.doResearch = function(item) {
|
||||
var cost = item.research();
|
||||
if (cost > 0) {
|
||||
achievements.update('count', 'reputation', item.reputation);
|
||||
achievements.update('count', 'dataSpent', cost);
|
||||
achievements.update('research', item.name, 1);
|
||||
UI.showUpdateValue("#update-data", -cost);
|
||||
UI.showUpdateValue("#update-reputation", item.reputation);
|
||||
analytics.sendEvent(
|
||||
analytics.events.categoryResearch,
|
||||
analytics.events.actionResearch,
|
||||
item.name,
|
||||
item.level
|
||||
);
|
||||
}
|
||||
};
|
||||
this.showInfo = function(r) {
|
||||
UI.showModal(r.name, r.getInfo());
|
||||
UI.showLevels(r.level);
|
||||
};
|
||||
}]);
|
||||
|
||||
app.controller('HRController', function() {
|
||||
this.workers = workers;
|
||||
this.hire = function(worker) {
|
||||
var cost = worker.hire();
|
||||
if (cost > 0) {
|
||||
achievements.update('count', 'moneyWorkers', cost);
|
||||
achievements.update('workers', worker.name, 1);
|
||||
achievements.update('count', 'workers', 1);
|
||||
UI.showUpdateValue("#update-funding", -cost);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
app.controller('UpgradesController', function() {
|
||||
this.upgrades = upgrades;
|
||||
this.upgrade = function(upgrade) {
|
||||
if (upgrade.buy()) {
|
||||
achievements.update('count', 'moneyUpgrades', upgrade.cost);
|
||||
UI.showUpdateValue("#update-funding", upgrade.cost);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
achievements.setList(Helpers.loadFile('json/achievements.json'));
|
||||
achievements.restore();
|
||||
|
||||
app.controller('AchievementsController', function() {
|
||||
this.achievements = achievements.listSummary;
|
||||
this.achievementsAll = achievements.list;
|
||||
});
|
||||
|
||||
app.controller('SaveController',
|
||||
['$scope', '$interval', function($scope, $interval) {
|
||||
$scope.lastSaved = new Date();
|
||||
$scope.saveNow = function() {
|
||||
GameObjects.saveAll();
|
||||
$scope.lastSaved = new Date();
|
||||
achievements.lastSave = $scope.lastSaved.getTime();
|
||||
};
|
||||
$scope.restart = function() {
|
||||
if (window.confirm(
|
||||
'Do you really want to restart the game? All progress will be lost.'
|
||||
)) {
|
||||
ObjectStorage.clear();
|
||||
window.location.reload(true);
|
||||
}
|
||||
};
|
||||
$interval($scope.saveNow, 10000);
|
||||
}]);
|
||||
|
||||
analytics.init();
|
||||
analytics.sendScreen(analytics.screens.main);
|
||||
})();
|
||||
+48
-136
@@ -1,141 +1,53 @@
|
||||
'use strict';
|
||||
(function() {
|
||||
var lab = GameObjects.lab;
|
||||
var research = GameObjects.research;
|
||||
var workers = GameObjects.workers;
|
||||
var upgrades = GameObjects.upgrades;
|
||||
var Game = (function() {
|
||||
'use strict';
|
||||
|
||||
UI.validateVersion(lab.version);
|
||||
var Game = function() {
|
||||
this.lab = new GameObjects.Lab();
|
||||
this.research = null;
|
||||
this.workers = null;
|
||||
this.upgrades = null;
|
||||
this.allObjects = {lab : this.lab};
|
||||
this.loaded = false;
|
||||
};
|
||||
|
||||
achievements.addResearch(research);
|
||||
achievements.addWorkers(workers);
|
||||
|
||||
var app = angular.module('particleClicker', []);
|
||||
|
||||
app.filter('niceNumber', ['$filter', function($filter) {
|
||||
return Helpers.formatNumberPostfix;
|
||||
}]);
|
||||
|
||||
app.filter('currency', ['$filter', function($filter) {
|
||||
return function(input) {
|
||||
return 'JTN ' + $filter('niceNumber')(input);
|
||||
};
|
||||
}]);
|
||||
|
||||
app.filter('reverse', ['$filter', function($filter) {
|
||||
return function(items) {
|
||||
return items.slice().reverse();
|
||||
};
|
||||
}]);
|
||||
|
||||
app.controller('DetectorController', function() {
|
||||
this.click = function() {
|
||||
lab.acquire(lab.detector.rate);
|
||||
detector.addEvent();
|
||||
achievements.update('count', 'clicks', 1);
|
||||
achievements.update('count', 'data', lab.detector.rate);
|
||||
UI.showUpdateValue("#update-data", lab.detector.rate);
|
||||
return false;
|
||||
};
|
||||
});
|
||||
|
||||
app.controller('LabController', ['$interval', function($interval) {
|
||||
this.lab = lab;
|
||||
this.showDetectorInfo = function() {
|
||||
if (!this._detectorInfo) {
|
||||
this._detectorInfo = Helpers.loadFile('html/detector.html');
|
||||
}
|
||||
UI.showModal('Detector', this._detectorInfo);
|
||||
};
|
||||
$interval(function() { // one tick
|
||||
var grant = lab.getGrant();
|
||||
achievements.update('count', 'money', grant);
|
||||
UI.showUpdateValue("#update-funding", grant);
|
||||
var sum = 0;
|
||||
for (var i = 0; i < workers.length; i++) {
|
||||
sum += workers[i].hired * workers[i].rate;
|
||||
}
|
||||
lab.acquire(sum);
|
||||
achievements.update('count', 'data', sum);
|
||||
UI.showUpdateValue("#update-data", sum);
|
||||
detector.addEventExternal();
|
||||
}, 1000);
|
||||
}]);
|
||||
|
||||
app.controller('ResearchController', ['$compile', function($compile) {
|
||||
this.research = research;
|
||||
this.doResearch = function(item) {
|
||||
var cost = item.research();
|
||||
if (cost > 0) {
|
||||
achievements.update('count', 'reputation', item.reputation);
|
||||
achievements.update('count', 'dataSpent', cost);
|
||||
achievements.update('research', item.name, 1);
|
||||
UI.showUpdateValue("#update-data", -cost);
|
||||
UI.showUpdateValue("#update-reputation", item.reputation);
|
||||
analytics.sendEvent(
|
||||
analytics.events.categoryResearch,
|
||||
analytics.events.actionResearch,
|
||||
item.name,
|
||||
item.level
|
||||
);
|
||||
}
|
||||
};
|
||||
this.showInfo = function(r) {
|
||||
UI.showModal(r.name, r.getInfo());
|
||||
UI.showLevels(r.level);
|
||||
};
|
||||
}]);
|
||||
|
||||
app.controller('HRController', function() {
|
||||
this.workers = workers;
|
||||
this.hire = function(worker) {
|
||||
var cost = worker.hire();
|
||||
if (cost > 0) {
|
||||
achievements.update('count', 'moneyWorkers', cost);
|
||||
achievements.update('workers', worker.name, 1);
|
||||
achievements.update('count', 'workers', 1);
|
||||
UI.showUpdateValue("#update-funding", -cost);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
app.controller('UpgradesController', function() {
|
||||
this.upgrades = upgrades;
|
||||
this.upgrade = function(upgrade) {
|
||||
if (upgrade.buy()) {
|
||||
achievements.update('count', 'moneyUpgrades', upgrade.cost);
|
||||
UI.showUpdateValue("#update-funding", upgrade.cost);
|
||||
}
|
||||
Game.prototype.load = function() {
|
||||
if (this.loaded) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
achievements.setList(Helpers.loadFile('json/achievements.json'));
|
||||
achievements.restore();
|
||||
|
||||
app.controller('AchievementsController', function() {
|
||||
this.achievements = achievements.listSummary;
|
||||
this.achievementsAll = achievements.list;
|
||||
});
|
||||
|
||||
app.controller('SaveController',
|
||||
['$scope', '$interval', function($scope, $interval) {
|
||||
$scope.lastSaved = new Date();
|
||||
$scope.saveNow = function() {
|
||||
GameObjects.saveAll();
|
||||
$scope.lastSaved = new Date();
|
||||
achievements.lastSave = $scope.lastSaved.getTime();
|
||||
};
|
||||
$scope.restart = function() {
|
||||
if (window.confirm(
|
||||
'Do you really want to restart the game? All progress will be lost.'
|
||||
)) {
|
||||
ObjectStorage.clear();
|
||||
window.location.reload(true);
|
||||
var _this = this;
|
||||
$.when($.get('json/research.json', function(jR) { _this.research = jR; }),
|
||||
$.get('json/workers.json', function(jW) { _this.workers = jW; }),
|
||||
$.get('json/upgrades.json', function(jU) { _this.upgrades = jU; }))
|
||||
.then(function() {
|
||||
// Turn JSON files into actual game objects and fill map of all objects
|
||||
var makeGameObject = function(type, object) {
|
||||
// It's okay to define this function here since load is only called
|
||||
// once anyway...
|
||||
var o = new type(object);
|
||||
_this.allObjects[o.key] = o;
|
||||
return o;
|
||||
};
|
||||
_this.research = _this.research.map(
|
||||
function(r) { return makeGameObject(GameObjects.Research, r); });
|
||||
_this.workers = _this.workers.map(
|
||||
function(w) { return makeGameObject(GameObjects.Worker, w); });
|
||||
_this.upgrades = _this.upgrades.map(
|
||||
function(u) { return makeGameObject(GameObjects.Upgrade, u); });
|
||||
// Load states from local store
|
||||
for (var i = 0; i < _this.allObjects.length; i++) {
|
||||
var o = _this.allObjects[i];
|
||||
o.loadState(ObjectStorage.load(o.key));
|
||||
}
|
||||
};
|
||||
$interval($scope.saveNow, 10000);
|
||||
}]);
|
||||
_this.loaded = true;
|
||||
});
|
||||
};
|
||||
|
||||
analytics.init();
|
||||
analytics.sendScreen(analytics.screens.main);
|
||||
})();
|
||||
Game.prototype.save = function() {
|
||||
// Save every object's state to local storage
|
||||
for (var i = 0; i < this.allObjects.length; i++) {
|
||||
ObjectStorage.save(this.allObjects[i].state);
|
||||
}
|
||||
};
|
||||
|
||||
return {Game : Game};
|
||||
}());
|
||||
|
||||
+196
-176
@@ -1,193 +1,213 @@
|
||||
'use strict';
|
||||
|
||||
/** Define all objects used in the game.
|
||||
* They can be either loaded from localStorage or from JSON in case nothing is
|
||||
* found in the localStorage.
|
||||
*/
|
||||
var GameObjects = (function() {
|
||||
var allObjects = {
|
||||
push: function(key_property, list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
this[list[i][key_property]] = list[i];
|
||||
}
|
||||
'use strict';
|
||||
var GLOBAL_VISIBILITY_THRESHOLD = 0.7;
|
||||
|
||||
/** @class GameObject
|
||||
* Base class for all objects in the game. This works together with the
|
||||
* saving mechanism.
|
||||
*/
|
||||
var GameObject = function(obj) {
|
||||
this.state = {};
|
||||
$.extend(this, obj);
|
||||
if (!this.key) {
|
||||
throw 'Error: GameObject has to have a key!';
|
||||
}
|
||||
};
|
||||
GameObject.prototype.loadState =
|
||||
function(state) { $.extend(this.state, state); };
|
||||
|
||||
/** Lab
|
||||
/** @class Lab
|
||||
*/
|
||||
var labPrototype = {
|
||||
version: '0.2',
|
||||
name: 'Click here to give your lab a catchy name',
|
||||
detector: {
|
||||
rate: 1
|
||||
},
|
||||
factor: {
|
||||
rate: 5
|
||||
},
|
||||
data: 0,
|
||||
reputation: 0,
|
||||
money: 0,
|
||||
getGrant: function () {
|
||||
var addition = this.reputation * this.factor.rate;
|
||||
this.money += addition;
|
||||
return addition;
|
||||
},
|
||||
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;
|
||||
}
|
||||
var Lab = function() {
|
||||
GameObject.apply(this, [{
|
||||
key : 'lab',
|
||||
version : 0.4,
|
||||
state : {
|
||||
name : 'Give your lab an awesome name!',
|
||||
detector : 1,
|
||||
factor : 5,
|
||||
data : 0,
|
||||
money : 0,
|
||||
reputation : 0
|
||||
}
|
||||
}]);
|
||||
};
|
||||
var lab = $.extend({}, labPrototype, ObjectStorage.load('lab'));
|
||||
allObjects['lab'] = lab;
|
||||
|
||||
/** Research
|
||||
*/
|
||||
var researchPrototype = {
|
||||
level: 0,
|
||||
interesting: false,
|
||||
is_visible: function() {
|
||||
return this.level > 0 || lab.data >= this.cost * .7;
|
||||
},
|
||||
is_available: function() {
|
||||
return lab.data >= this.cost;
|
||||
},
|
||||
research: function() {
|
||||
if (lab.research(this.cost, this.reputation)) {
|
||||
this.level++;
|
||||
if (this.info_levels.length > 0 && this.level === this.info_levels[0]) {
|
||||
this.interesting = true;
|
||||
this.info_levels.splice(0, 1);
|
||||
}
|
||||
var oldCost = this.cost;
|
||||
this.cost = Math.round(this.cost * this.cost_increase);
|
||||
return oldCost;
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
getInfo: function() {
|
||||
if (!this._info) {
|
||||
this._info = Helpers.loadFile(this.info);
|
||||
}
|
||||
this.interesting = false;
|
||||
return this._info;
|
||||
},
|
||||
Lab.prototype = Object.create(GameObject.prototype);
|
||||
|
||||
Lab.prototype.constructor = Lab;
|
||||
|
||||
Lab.prototype.getGrant = function() {
|
||||
var addition = this.state.reputation * this.state.factor;
|
||||
this.state.money += addition;
|
||||
return addition;
|
||||
};
|
||||
var research = $.extend([], Helpers.loadFile('json/research.json'),
|
||||
ObjectStorage.load('research'));
|
||||
research = research.map(function(item) {
|
||||
return $.extend({}, researchPrototype, item);
|
||||
});
|
||||
allObjects.push('name', research);
|
||||
|
||||
Lab.prototype.acquireData = function(amount) { this.state.data += amount; };
|
||||
|
||||
/** Workers
|
||||
*/
|
||||
var workersPrototype = {
|
||||
hired: 0,
|
||||
is_visible: function() {
|
||||
return this.hired > 0 || lab.money >= this.cost * .7;
|
||||
},
|
||||
is_available: function() {
|
||||
return lab.money >= this.cost;
|
||||
},
|
||||
hire: function() {
|
||||
if (lab.buy(this.cost)) {
|
||||
this.hired++;
|
||||
analytics.sendEvent(analytics.events.categoryHR, analytics.events.actionHire, this.name, this.hired);
|
||||
var cost = this.cost;
|
||||
this.cost = Math.round(this.cost * this.cost_increase);
|
||||
return cost;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
var workers = $.extend([], Helpers.loadFile('json/workers.json'),
|
||||
ObjectStorage.load('workers'));
|
||||
workers = workers.map(function(worker) {
|
||||
return $.extend({}, workersPrototype, worker);
|
||||
});
|
||||
allObjects.push('name', workers);
|
||||
|
||||
|
||||
/** Upgrades
|
||||
*/
|
||||
var upgradesPrototype = {
|
||||
_visible: false,
|
||||
_used: false,
|
||||
meetsRequirements: function() {
|
||||
for (var i = 0; i < this.requirements.length; i++) {
|
||||
var req = this.requirements[i];
|
||||
if (allObjects[req.key][req.property] < req.threshold) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Lab.prototype.research = function(cost, reputation) {
|
||||
if (this.state.data >= cost) {
|
||||
this.state.data -= cost;
|
||||
this.state.reputation += reputation;
|
||||
return true;
|
||||
},
|
||||
isAvailable: function() {
|
||||
if (!this._used && lab.money >= this.cost && this.meetsRequirements()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Lab.prototype.buy = function(cost) {
|
||||
if (this.state.money >= cost) {
|
||||
this.state.money -= cost;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/** @class Research
|
||||
*/
|
||||
var Research = function(obj) {
|
||||
GameObject.apply(
|
||||
this, [$.extend({}, obj, {state : {level : 0, interesting : false}})]);
|
||||
};
|
||||
|
||||
Research.prototype = Object.create(GameObject.prototype);
|
||||
|
||||
Research.prototype.constructor = Research;
|
||||
|
||||
Research.prototype.isVisible = function(lab) {
|
||||
if (!lab) {
|
||||
return false;
|
||||
},
|
||||
isVisible: function() {
|
||||
if (!this._used && (this._visible || lab.money >= this.cost * .7 && this.meetsRequirements())) {
|
||||
this._visible = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return this.state.level > 0 ||
|
||||
lab.state.data >= this.state.cost * GLOBAL_VISIBILITY_THRESHOLD;
|
||||
};
|
||||
|
||||
Research.prototype.isAvailable = function(lab) {
|
||||
if (!lab) {
|
||||
return false;
|
||||
},
|
||||
buy: function() {
|
||||
if (!this._used && lab.buy(this.cost)) {
|
||||
for (var i = 0; i < this.targets.length; i++) {
|
||||
var t = this.targets[i];
|
||||
allObjects[t.key][t.property] *= this.factor || 1;
|
||||
allObjects[t.key][t.property] += this.constant || 0;
|
||||
}
|
||||
this._used = true;
|
||||
this._visible = false;
|
||||
}
|
||||
return lab.state.data >= this.state.cost;
|
||||
};
|
||||
|
||||
Research.prototype.research = function(lab) {
|
||||
if (lab && lab.research(this.state.cost, this.state.reputation)) {
|
||||
this.state.level++;
|
||||
if (this.state.info_levels.length > 0 &&
|
||||
this.state.level === this.state.info_levels[0]) {
|
||||
this.state.interesting = true;
|
||||
this.state.info_levels.splice(0, 1);
|
||||
}
|
||||
var old_cost = this.state.cost;
|
||||
this.state.cost = Math.round(this.state.cost * this.cost_increase);
|
||||
return old_cost;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
Research.prototype.getInfo = function() {
|
||||
if (!this._info) {
|
||||
this._info = Helpers.loadFile(this.info);
|
||||
}
|
||||
this.state.interesting = false;
|
||||
return this._info;
|
||||
};
|
||||
|
||||
/** @class Worker
|
||||
* Implement an auto-clicker in the game.
|
||||
*/
|
||||
var Worker = function(obj) {
|
||||
GameObject.apply(this, [$.extend({}, obj, {state : {hired : 0}})]);
|
||||
};
|
||||
|
||||
Worker.prototype = Object.create(GameObject.prototype);
|
||||
|
||||
Worker.prototype.constructor = Worker;
|
||||
|
||||
Worker.prototype.isVisible = function(lab) {
|
||||
if (!lab) {
|
||||
return false;
|
||||
}
|
||||
return this.state.hired > 0 ||
|
||||
lab.state.money >= this.state.cost * GLOBAL_VISIBILITY_THRESHOLD;
|
||||
};
|
||||
|
||||
Worker.prototype.isAvailable = function(lab) {
|
||||
if (!lab) {
|
||||
return false;
|
||||
}
|
||||
return lab.state.money >= this.state.cost;
|
||||
};
|
||||
|
||||
Worker.prototype.hire = function(lab) {
|
||||
if (lab && lab.buy(this.cost)) {
|
||||
this.state.hired++;
|
||||
var cost = this.state.cost;
|
||||
this.state.cost = Math.round(cost * this.cost_increase);
|
||||
return cost;
|
||||
}
|
||||
return -1; // not enough money
|
||||
};
|
||||
|
||||
Worker.prototype.getTotal =
|
||||
function() { return this.state.hired * this.state.rate; }
|
||||
|
||||
/** @class Upgrade
|
||||
*/
|
||||
var Upgrade = function(obj) {
|
||||
GameObject.apply(
|
||||
this, [$.extend({}, obj, {state : {visible : false, used : false}})]);
|
||||
};
|
||||
|
||||
Upgrade.prototype = Object.create(GameObject.prototype);
|
||||
|
||||
Upgrade.prototype.constructor = Upgrade;
|
||||
|
||||
Upgrade.prototype.meetsRequirements = function(allObjects) {
|
||||
if (!allObjects) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < this.requirements.length; i++) {
|
||||
var req = this.requirements[i];
|
||||
if (allObjects[req.key].state[req.property] < req.threshold) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
var upgrades = $.extend([], Helpers.loadFile('json/upgrades.json'),
|
||||
ObjectStorage.load('upgrades'));
|
||||
upgrades = upgrades.map(function(upgrade) {
|
||||
return $.extend({}, upgradesPrototype, upgrade);
|
||||
});
|
||||
allObjects.push('name', upgrades);
|
||||
|
||||
|
||||
/** Save all the game objects at once.
|
||||
*/
|
||||
var saveAll = function() {
|
||||
ObjectStorage.save('lab', lab);
|
||||
ObjectStorage.save('research', research);
|
||||
ObjectStorage.save('workers', workers);
|
||||
ObjectStorage.save('upgrades', upgrades);
|
||||
ObjectStorage.save('achievements', achievements);
|
||||
return true;
|
||||
};
|
||||
|
||||
return {
|
||||
lab: lab,
|
||||
research: research,
|
||||
workers: workers,
|
||||
upgrades: upgrades,
|
||||
saveAll: saveAll,
|
||||
}
|
||||
})();
|
||||
Upgrade.prototype.isAvailable = function(lab) {
|
||||
if (!lab) {
|
||||
return false;
|
||||
}
|
||||
return !this.state.used && lab.state.money >= this.cost &&
|
||||
this.meetsRequirements();
|
||||
};
|
||||
|
||||
Upgrade.prototype.isVisible = function(lab) {
|
||||
if (!lab) {
|
||||
return false;
|
||||
}
|
||||
if (!this.state.used &&
|
||||
(this.state.visible ||
|
||||
lab.state.money >= this.cost * GLOBAL_VISIBILITY_THRESHOLD &&
|
||||
this.meetsRequirements())) {
|
||||
this._visible = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Upgrade.prototype.buy = function(lab, allObjects) {
|
||||
if (lab && allObjects && !this.state.used && lab.buy(this.cost)) {
|
||||
for (var i = 0; i < this.targets.length; i++) {
|
||||
var t = this.targets[i];
|
||||
allObjects[t.key].state[t.property] *= this.factor || 1;
|
||||
allObjects[t.key].state[t.property] += this.constant || 0;
|
||||
}
|
||||
this.state.used = true; // How about actually REMOVING used upgrades?
|
||||
this.state.visible = false;
|
||||
}
|
||||
};
|
||||
|
||||
// Expose classes in module.
|
||||
return {Lab : Lab, Research : Research, Worker : Worker, Upgrade : Upgrade};
|
||||
}());
|
||||
|
||||
+3
-4
@@ -1,14 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
/** Define some useful helpers that are used throughout the game.
|
||||
/** @module Helpers
|
||||
* Define some useful helpers that are used throughout the game.
|
||||
*/
|
||||
var Helpers = (function() {
|
||||
'use strict';
|
||||
/** Load a file (usually JSON).
|
||||
*/
|
||||
var loadFile = function(filename) {
|
||||
var res;
|
||||
$.ajax({
|
||||
async: false,
|
||||
url : filename,
|
||||
success : function(data) {
|
||||
res = data;
|
||||
|
||||
+18
-22
@@ -1,34 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
/** Allows to save objects to HTML5 local storage.
|
||||
* However, it can only save properties, not functions.
|
||||
*/
|
||||
var ObjectStorage = (function() {
|
||||
'use strict';
|
||||
try {
|
||||
var _s = localStorage;
|
||||
return {
|
||||
save: function(key, item) {
|
||||
_s.setItem(key, JSON.stringify(item, function (key, val) {
|
||||
if (key == '$$hashKey') {
|
||||
return undefined;
|
||||
}
|
||||
return val;
|
||||
}));
|
||||
},
|
||||
load: function(key) {
|
||||
return JSON.parse(_s.getItem(key));
|
||||
},
|
||||
clear: function() {
|
||||
_s.clear();
|
||||
}
|
||||
save :
|
||||
function(key, item) {
|
||||
_s.setItem(key, JSON.stringify(item, function(key, val) {
|
||||
if (key == '$$hashKey') {
|
||||
return undefined;
|
||||
}
|
||||
return val;
|
||||
}));
|
||||
},
|
||||
load : function(key) { return JSON.parse(_s.getItem(key)); },
|
||||
clear : function() { _s.clear(); }
|
||||
};
|
||||
} catch (e) {
|
||||
alert('There is no local storage for you.'
|
||||
+ ' If you refresh the page, all progress will be lost');
|
||||
alert('There is no local storage for you.' +
|
||||
' If you refresh the page, all progress will be lost');
|
||||
return {
|
||||
save: function(key, item) {},
|
||||
load: function(key) { return null; },
|
||||
clear: function() {}
|
||||
save : function(key, item) {},
|
||||
load : function(key) { return null; },
|
||||
clear : function() {}
|
||||
};
|
||||
};
|
||||
})();
|
||||
}());
|
||||
|
||||
+54
-27
@@ -1,92 +1,119 @@
|
||||
[
|
||||
{
|
||||
"key": "research-cpv",
|
||||
"name": "CP violation",
|
||||
"description": "CP symmetry is broken!",
|
||||
"reputation": 1,
|
||||
"cost": 10,
|
||||
"cost_increase": 1.4,
|
||||
"image": "assets/icons/png/CPV.png",
|
||||
"info": "html/CPV.html",
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
"state": {
|
||||
"reputation": 1,
|
||||
"cost": 10,
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "research-jpsi",
|
||||
"name": "J/ψ",
|
||||
"description": "The J/ψ meson consists of a c and an anti-c quark.",
|
||||
"reputation": 5,
|
||||
"cost": 100,
|
||||
"cost_increase": 1.45,
|
||||
"image": "assets/icons/png/Jpsi.png",
|
||||
"info": "html/Jpsi.html",
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
"state": {
|
||||
"reputation": 5,
|
||||
"cost": 100,
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "research-tau",
|
||||
"name": "τ lepton",
|
||||
"description": "The third generation charged lepton.",
|
||||
"reputation": 50,
|
||||
"cost": 2000,
|
||||
"cost_increase": 1.5,
|
||||
"image": "assets/icons/png/tau.png",
|
||||
"info": "html/tau.html",
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
"state": {
|
||||
"reputation": 50,
|
||||
"cost": 2000,
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "research-beauty",
|
||||
"name": "Beauty quark",
|
||||
"description": "The third generation down-type quark.",
|
||||
"reputation": 100,
|
||||
"cost": 25000,
|
||||
"cost_increase": 1.55,
|
||||
"image": "assets/icons/png/b.png",
|
||||
"info": "html/b.html",
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
"state": {
|
||||
"reputation": 100,
|
||||
"cost": 25000,
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "research-weak",
|
||||
"name": "W and Z boson",
|
||||
"description": "The carriers of the weak force.",
|
||||
"reputation": 200,
|
||||
"cost": 50000,
|
||||
"cost_increase": 1.6,
|
||||
"image": "assets/icons/png/weak.png",
|
||||
"info": "html/weak.html",
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
"state": {
|
||||
"reputation": 200,
|
||||
"cost": 50000,
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "research-top",
|
||||
"name": "Top quark",
|
||||
"description": "The heaviest of the quarks.",
|
||||
"reputation": 1000,
|
||||
"cost": 2000000,
|
||||
"cost_increase": 2,
|
||||
"image": "assets/icons/png/t.png",
|
||||
"info": "html/top.html",
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
"state": {
|
||||
"reputation": 1000,
|
||||
"cost": 2000000,
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "research-antihydrogen",
|
||||
"name": "Antihydrogen",
|
||||
"description": "The lightest anti-atom, it consists of an antiproton and a positron.",
|
||||
"reputation": 5000,
|
||||
"cost": 10000000,
|
||||
"cost_increase": 2.5,
|
||||
"image": "assets/icons/png/antihydrogen.png",
|
||||
"info": "html/antihydrogen.html",
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
"state": {
|
||||
"reputation": 5000,
|
||||
"cost": 10000000,
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "research-boscillations",
|
||||
"name": "B oscillations",
|
||||
"description": "B mesons turn into their antiparticles and vice versa!",
|
||||
"reputation": 5000,
|
||||
"cost": 50000000,
|
||||
"cost_increase": 2.5,
|
||||
"image": "assets/icons/png/BBbar.png",
|
||||
"info": "html/BBbar.html",
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
"state": {
|
||||
"reputation": 5000,
|
||||
"cost": 50000000,
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "research-higgs",
|
||||
"name": "Higgs boson",
|
||||
"description": "Spontaneous symmetry breaking and Goldstone bosons sound familiar to you, right?",
|
||||
"reputation": 10000,
|
||||
"cost": 72500000,
|
||||
"cost_increase": 3,
|
||||
"image": "assets/icons/png/H.png",
|
||||
"info": "html/H.html",
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
"state": {
|
||||
"reputation": 10000,
|
||||
"cost": 72500000,
|
||||
"info_levels": [1, 5, 10, 25]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[
|
||||
{
|
||||
"key": "upgrade-thesissupervision",
|
||||
"name": "Thesis supervision",
|
||||
"description": "Somebody takes care of your PhD Students.",
|
||||
"effect": "PhD Students produce twice as much data per second.",
|
||||
@@ -11,6 +12,7 @@
|
||||
"constant": 0
|
||||
},
|
||||
{
|
||||
"key": "upgrade-owndesk",
|
||||
"name": "Own desk",
|
||||
"description": "Not having to share one is a blessing.",
|
||||
"effect": "PhD Students produce twice as much data per second.",
|
||||
@@ -21,6 +23,7 @@
|
||||
"factor": 2
|
||||
},
|
||||
{
|
||||
"key": "upgrade-coffee",
|
||||
"name": "Free coffee",
|
||||
"description": "Addictively delicious. Also free.",
|
||||
"effect": "All workers produce twice as much data per second.",
|
||||
|
||||
+30
-12
@@ -1,44 +1,62 @@
|
||||
[
|
||||
{
|
||||
"key": "workers-phdstudents",
|
||||
"name": "PhD Students",
|
||||
"description": "Cheap and enthusiastic manpower, they can save you a lot of work.",
|
||||
"cost": 100,
|
||||
"cost_increase": 1.4,
|
||||
"rate": 1
|
||||
"state": {
|
||||
"cost": 100,
|
||||
"rate": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "workers-postdocs",
|
||||
"name": "Postdocs",
|
||||
"description": "These brilliant minds are here only to serve your needs.",
|
||||
"cost": 2000,
|
||||
"cost_increase": 1.4,
|
||||
"rate": 5
|
||||
"state": {
|
||||
"cost": 2000,
|
||||
"rate": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "workers-fellows",
|
||||
"name": "Research Fellows",
|
||||
"description": "You pay them a lot. They work a lot.",
|
||||
"cost": 50000,
|
||||
"cost_increase": 1.5,
|
||||
"rate": 50
|
||||
"state": {
|
||||
"cost": 50000,
|
||||
"rate": 50
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "workers-profs",
|
||||
"name": "Tenured Professors",
|
||||
"description": "They bring their own group along and are able to get a lot of work done.",
|
||||
"cost": 1000000,
|
||||
"cost_increase": 1.6,
|
||||
"rate": 100
|
||||
"state": {
|
||||
"cost": 1000000,
|
||||
"rate": 100
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "workers-nobel",
|
||||
"name": "Nobel Prize Winners",
|
||||
"description": "They received their prize for a reason... Why don't you give them more money?",
|
||||
"cost": 50000000,
|
||||
"cost_increase": 2,
|
||||
"rate": 500
|
||||
"state": {
|
||||
"cost": 50000000,
|
||||
"rate": 500
|
||||
}
|
||||
},
|
||||
{
|
||||
"key": "workers-summies",
|
||||
"name": "Summer Students",
|
||||
"description": "They are AWESOME. Their best ideas come between two parties.",
|
||||
"cost": 99999999,
|
||||
"cost_increase": 3,
|
||||
"rate": 1000
|
||||
"state": {
|
||||
"cost": 99999999,
|
||||
"rate": 1000
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user