-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwallet.js
43 lines (35 loc) · 864 Bytes
/
wallet.js
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
var inherits = require('inherits');
module.exports = Wallet;
function Wallet(game, options) {
this.game = game;
this.cash = 100;
this.createHTML();
this.meter = options.meter
}
Wallet.prototype.createHTML = function(){
this.el = document.createElement('div');
this.el.id = 'wallet';
this.el.innerHTML = '$' + this.cash;
document.body.appendChild(this.el);
};
Wallet.prototype.add = function(amount){
this.cash += amount;
this.draw();
this.meter.add(amount);
}
Wallet.prototype.remove = function(amount){
this.cash -= amount;
this.draw();
this.meter.remove(amount);
}
Wallet.prototype.changeEvent = function(type, amount) {
if (type == "remove") {
this.cash -= amount;
} else if (type == "add") {
this.cash += amount;
}
this.draw();
}
Wallet.prototype.draw = function() {
this.el.innerHTML = '$' + this.cash;
}