-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRoom.js
36 lines (34 loc) · 860 Bytes
/
Room.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
var SetupGhost = require('./GN.server/Setup/Ghost');
var SetupHuman = require('./GN.server/Setup/Human');
var Room = function (roomNo) {
this.roomNo = roomNo;
this.GN = null;
this.mode = '';
this.players = [];
//this.p1 = {socket: null, side: 'ghost'};
//this.p2 = {socket: null, side: 'human'};
this.isPlaying = false;
this.map = 'm01';
this.loadedNo = 0;
}
Room.prototype.broadcast = function(event, data){
// console.log("Room " + this.roomNo + " broadcast " + event);
this.players.forEach(function(p){
p.socket.emit(event, data);
});
}
Room.prototype.SetupSocket = function(on) {
this.players.forEach((p)=>{
switch(p.side) {
case 'ghost':
SetupGhost(p.socket, this, on);
break;
case 'human':
SetupHuman(p.socket, this, on);
break;
default:
break;
}
});
}
module.exports = Room;