-
Notifications
You must be signed in to change notification settings - Fork 323
/
game.js
56 lines (49 loc) · 1.22 KB
/
game.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
55
56
"use strict";
const stampit = require('stampit');
const character = stampit().
props({
name: 'anonymous',
lifePoints: 100,
x: 0,
y: 0
})
;
const mover = stampit().
methods({
move(xIncr, yIncr) {
this.x += xIncr;
this.y += yIncr;
console.log(`${this.name} moved to [${this.x}, ${this.y}]`);
}
})
;
const slasher = stampit().
methods({
slash(direction) {
console.log(`${this.name} slashed to the ${direction}`);
}
})
;
const shooter = stampit().
props({
bullets: 6
}).
methods({
shoot(direction) {
if (this.bullets > 0) {
--this.bullets;
console.log(`${this.name} shoot to the ${direction}`);
}
}
})
;
const runner = stampit.compose(character, mover);
const samurai = stampit.compose(character, mover, slasher);
const sniper = stampit.compose(character, shooter);
const gunslinger = stampit.compose(character, mover, shooter);
const westernSamurai = stampit.compose(gunslinger, samurai);
let gojiro = westernSamurai();
gojiro.name = 'Gojiro Kiryu';
gojiro.move(1,0);
gojiro.slash('left');
gojiro.shoot('right');