-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameobject.js
54 lines (32 loc) · 841 Bytes
/
gameobject.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
44
45
46
47
48
49
50
51
52
53
54
var NOWHERE = -1;
function GameObject(name) {
for (c in cfg_data.objects) {
if (cfg_data.objects[c].name == name) {
Object.assign(this,cfg_data.objects[c]);
}
}
this.row = NOWHERE;
this.col = NOWHERE;
}
/* game logic flags functions */
GameObject.prototype.hasFlag = function(flag) {
return this.flags.indexOf(flag) != -1;
}
GameObject.prototype.setFlag = function(flag) {
if (!this.hasFlag(flag)) {
this.flags.push(flag);
}
}
GameObject.prototype.clearFlag = function(flag) {
this.flags = this.flags.remove(f => f !== flag );
}
function replacer(match, p1, p2, p3, offset, string) {
return go_curobj[match.slice(1)].toString();
}
var go_curobj;
GameObject.prototype.getMessage = function (message) {
go_curobj = this;
s = new String(this[message]);
s = s.replace(/%\w+/gm,replacer)
return s;
}