Repository navigation
Expand file tree
/
Copy pathgame.js
More file actions
115 lines (115 loc) · 3.53 KB
/
Copy pathgame.js
File metadata and controls
115 lines (115 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Resource = (function () {
function Resource() {
}
Resource.prototype.display = function () {
if (this.amount - Math.floor(this.amount) > 0) {
return this.amount.toFixed(2);
}
else
return this.amount.toString();
};
return Resource;
})();
var Scrap = (function (_super) {
__extends(Scrap, _super);
function Scrap(amount) {
_super.call(this);
this.amount = amount;
this.name = "scrap";
this.cost = {
"scrap": 0
};
document.getElementById('scrapLbl').innerHTML = this.name + ": ";
}
return Scrap;
})(Resource);
var Rat = (function (_super) {
__extends(Rat, _super);
function Rat(amount) {
_super.call(this);
this.amount = amount;
this.name = "rat";
this.cost = {
"scrap": 10
};
this.value = 1;
document.getElementById('ratLbl').innerHTML = this.name + ": ";
}
return Rat;
})(Resource);
var wRat = (function (_super) {
__extends(wRat, _super);
function wRat(amount) {
_super.call(this);
this.amount = amount;
this.name = "wrat";
this.cost = {
"scrap": 10,
"rat": 1
};
this.value = 1;
document.getElementById('wratLbl').innerHTML = this.name + ": ";
}
return wRat;
})(Resource);
var resourceList = {};
var curScrap = new Scrap(0);
var curRat = new Rat(0);
var curWRat = new wRat(0);
resourceList["scrap"] = curScrap;
resourceList["rat"] = curRat;
resourceList["wrat"] = curWRat;
function updateView() {
document.getElementById('scrapId').innerHTML = resourceList["scrap"].display();
document.getElementById('ratId').innerHTML = resourceList["rat"].display();
document.getElementById('wratId').innerHTML = resourceList["wrat"].display();
if (resourceList["scrap"].amount >= resourceList["rat"].cost["scrap"]) {
document.getElementById('scrapRat').disabled = false;
}
else {
document.getElementById('scrapRat').disabled = true;
}
if (resourceList["scrap"].amount >= resourceList["wrat"].cost["scrap"] && resourceList["rat"].amount >= resourceList["wrat"].cost["rat"]) {
document.getElementById('wRat').disabled = false;
}
else {
document.getElementById('wRat').disabled = true;
}
document.getElementById('ratId').title = resourceList["rat"].cost.toString(); // doesn't work yet
}
function updateValues() {
if (resourceList["rat"].amount > 0)
resourceList["scrap"].amount += (resourceList["rat"].value * resourceList["rat"].amount) / 10;
}
function collectScrap() {
resourceList["scrap"].amount += 1;
}
function scrapRat() {
//cost
resourceList["scrap"].amount -= resourceList["rat"].cost["scrap"];
//create
resourceList["rat"].amount += 1;
//update cost
resourceList["rat"].cost["scrap"] *= 1.12;
}
function wScrapRat() {
//cost
resourceList["scrap"].amount -= resourceList["wrat"].cost["scrap"];
resourceList["rat"].amount -= resourceList["wrat"].cost["rat"];
//create
resourceList["wrat"].amount += 1;
//update cost
resourceList["wrat"].cost["scrap"] *= 1.12;
resourceList["wrat"].cost["rat"] *= 1.12;
}
window.setInterval(function () {
this.updateValues();
updateView();
}, 100);
//# sourceMappingURL=game.js.map