-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (57 loc) · 1.54 KB
/
index.js
File metadata and controls
70 lines (57 loc) · 1.54 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var io = require('socket.io').listen(7000);
var words = new Array('a', 'as', 'asd', '1', '2')
var count = 0;
var roundClientCount = 0;
var round = 0;
var solver;
var drawer;
function randomitem(words) {
var ritem = words[Math.floor(Math.random() * words.length)];
return ritem;
}
io.on('connection', client => {
count++;
console.log(count + ' 명 입장');
var wordDatas = new Array();
for (var i = 0; i < 6; i++) {
wordDatas[i] = randomitem(words);
}
if (count % 2 != 0) drawer = client;
else solver = client;
client.on('ready', data => {
if (count % 2 == 0) {
drawer.emit('start', true);
solver.emit('start', false);
}
});
client.on('roundStart', data => {
roundClientCount++;
console.log(roundClientCount + ' 번 준비완료');
if (roundClientCount % 2 == 0) {
round++;
drawer.emit('wordData', wordDatas[round]);
solver.emit('wordData', wordDatas[round]);
}
});
client.on('action', data => {
solver.emit('action', data);
});
client.on('pass', data => {
console.log('pass');
io.emit('pass');
var flag = drawer;
drawer = solver;
solver = flag;
});
client.on('disconnect', data => {
count--;
if (count == 0) {
roundClientCount = 0;
round = 0;
solver = null;
drawer = null;
console.log("초기화됨");
}
console.log(count);
})
});