-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.js
More file actions
38 lines (38 loc) · 720 Bytes
/
Factory.js
File metadata and controls
38 lines (38 loc) · 720 Bytes
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
const stampit = require('stampit');
const character = stampit({
props: {
name: 'Anonymous',
lifePoint: 100,
x: 0,
y: 0
}
});
const mover = stampit({
methods: {
move(x, y) {
this.x += x;
this.y += y;
console.log(`${this.name} moved to (${this.x},${this.y})`);
}
}
});
const shooter = stampit({
props: {
bullets: 6
},
methods: {
shot() {
if(this.bullets <= 0) {
console.log('run out of bullets');
return 0;
}
this.bullets -= 1;
console.log(`${this.name} shooted`);
}
}
});
let Player = stampit.compose(character, mover, shooter);
let player1 = Player();
player1.name = 'kimmy';
player1.move(1,1);
player1.shot();