Commit 3fe7e321 authored by 18신대성's avatar 18신대성

대기실 카운터 구현완료

parent d7bf6857
...@@ -34,12 +34,13 @@ GameServer.makeRoom = function() ...@@ -34,12 +34,13 @@ GameServer.makeRoom = function()
var roomOption = var roomOption =
{ {
roomNum: GameServer.nextRoomNumber++, roomNum: GameServer.nextRoomNumber++,
maxPlayer: 5, maxPlayer: 100,
nextRank: 0, nextRank: 100,
currentPlayer: [], currentPlayer: [],
aliveCount: 0, aliveCount: 0,
currentSocket: [], currentSocket: [],
currentPhase: GameServer.Phase.READY, currentPhase: GameServer.Phase.READY,
endTime: 0,
rateArrangePoint: 300, rateArrangePoint: 300,
maxTypingPlayer: null, maxTypingPlayer: null,
...@@ -86,16 +87,16 @@ GameServer.enterRoom = function(roomIdx, playerData) ...@@ -86,16 +87,16 @@ GameServer.enterRoom = function(roomIdx, playerData)
console.log('[' + playerData.id + '] entered to room #' + room.roomNum); console.log('[' + playerData.id + '] entered to room #' + room.roomNum);
playerData.socketId.emit('enterRoom'); playerData.socketId.emit('enterRoom');
let endTimeToAnnounce = Date.now() + 6000; room.endTime = Date.now() + 6000; // 테스트로 6초로 남겨둠
if (room.currentPlayer.length >= this.startCount) if (room.currentPlayer.length >= this.startCount)
{ {
if (room.currentPhase === this.Phase.READY) // start count if (room.currentPhase === this.Phase.READY) // start count
{ {
this.announceToRoom(room.roomNum, 'setCount', {isEnable: true, endTime: endTimeToAnnounce}); this.announceToRoom(room.roomNum, 'setCount', {isEnable: true, endTime: room.endTime});
} }
else if (room.currentPhase === this.Phase.COUNT) // countinue count else if (room.currentPhase === this.Phase.COUNT) // countinue count
{ {
playerData.socketId.emit('setCount', {isEnable: true, endTime: endTimeToAnnounce}); playerData.socketId.emit('setCount', {isEnable: true, endTime: room.endTime});
} }
} }
else // stop count else // stop count
......
...@@ -72,14 +72,14 @@ io.on('connection', function(socket) ...@@ -72,14 +72,14 @@ io.on('connection', function(socket)
socket.emit('setPlayerTypingRate', playerTypingRate); socket.emit('setPlayerTypingRate', playerTypingRate);
}); });
socket.on('endCount') socket.on('endCount', function()
{ {
socket.currentRoom.aliveCount--; socket.playerData.currentRoom.aliveCount--;
if (socket.currentRoom.aliveCount === 0) if (socket.playerData.currentRoom.aliveCount === 0)
{ {
GameServer.startRoom(GameServer.findRoomIndex(socket.currentRoom.roomNum)); GameServer.startRoom(GameServer.findRoomIndex(socket.playerData.currentRoom.roomNum));
} }
} });
socket.on('attack', function(msg) socket.on('attack', function(msg)
{ {
...@@ -118,7 +118,6 @@ io.on('connection', function(socket) ...@@ -118,7 +118,6 @@ io.on('connection', function(socket)
socket.on('disconnect', function(reason) socket.on('disconnect', function(reason)
{ {
let data = socket.playerData; let data = socket.playerData;
console.log('['+ data.id +'] client disconnected, reason: ' + reason);
if (typeof data.id === undefined) if (typeof data.id === undefined)
{ {
console.log('[ERROR] data.id is undefined'); console.log('[ERROR] data.id is undefined');
...@@ -126,6 +125,7 @@ io.on('connection', function(socket) ...@@ -126,6 +125,7 @@ io.on('connection', function(socket)
} }
else // data.id is not undefined else // data.id is not undefined
{ {
console.log('['+ data.id +'] client disconnected, reason: ' + reason);
let idxToDel = GameServer.currentPlayer.findIndex(function(element) let idxToDel = GameServer.currentPlayer.findIndex(function(element)
{ {
return element.id === data.id; return element.id === data.id;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment