Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sejong25
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Tear of Sejong
sejong25
Commits
1090e19e
Commit
1090e19e
authored
Jul 05, 2019
by
18신대성
Committed by
18류지석
Jul 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
룸에서 퇴장시 그 룸에서 유저를 삭제함
parent
026e9ec6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
14 deletions
+47
-14
GameServer.js
GameServer.js
+22
-7
Client.js
js/Client.js
+4
-0
server.js
server.js
+21
-7
No files found.
GameServer.js
View file @
1090e19e
var
GameServer
=
GameServer
||
{};
var
GameServer
=
GameServer
||
{};
GameServer
.
Phase
=
{
READY
:
0
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
Phase
=
{
READY
:
0
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
startCount
=
1
;
GameServer
.
startCount
=
2
;
GameServer
.
currentPlayer
=
[];
GameServer
.
currentPlayer
=
[];
GameServer
.
playingRoom
=
[];
GameServer
.
playingRoom
=
[];
...
@@ -42,15 +42,22 @@ GameServer.makeRoom = function()
...
@@ -42,15 +42,22 @@ GameServer.makeRoom = function()
minPlayerTyping
:
0
minPlayerTyping
:
0
}
}
this
.
playingRoom
.
push
(
roomOption
);
this
.
playingRoom
.
push
(
roomOption
);
console
.
log
(
'
[SERVER] new room made, roomCount:
'
+
this
.
playingRoom
.
length
);
console
.
log
(
'
[SERVER] new room
#
'
+
roomOption
.
roomNum
+
'
made, roomCount:
'
+
this
.
playingRoom
.
length
);
return
this
.
playingRoom
.
length
-
1
;
return
this
.
playingRoom
.
length
-
1
;
}
}
GameServer
.
findRoomIndex
=
function
(
roomNum
)
{
return
GameServer
.
playingRoom
.
findIndex
(
function
(
element
)
{
return
element
.
roomNum
===
roomNum
;
});
}
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
{
{
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
push
(
playerData
);
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
push
(
playerData
);
playerData
.
currentRoom
=
this
.
playingRoom
[
roomIdx
];
playerData
.
currentRoom
=
this
.
playingRoom
[
roomIdx
];
console
.
log
(
'
[
'
+
playerData
.
id
+
'
] entered to room #
'
+
this
.
playingRoom
[
roomIdx
].
roomNum
);
console
.
log
(
'
[
'
+
playerData
.
id
+
'
] entered to room #
'
+
this
.
playingRoom
[
roomIdx
].
roomNum
);
if
(
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
length
>
this
.
startCount
)
GameServer
.
startRoom
(
roomIdx
);
if
(
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
length
>
=
this
.
startCount
&&
this
.
playingRoom
[
roomIdx
].
Phase
!=
GameServer
.
Phase
.
START
)
GameServer
.
startRoom
(
roomIdx
);
return
this
.
playingRoom
[
roomIdx
];
return
this
.
playingRoom
[
roomIdx
];
}
}
GameServer
.
enterEmptyRoom
=
function
(
playerData
)
GameServer
.
enterEmptyRoom
=
function
(
playerData
)
...
@@ -73,11 +80,19 @@ GameServer.enterEmptyRoom = function(playerData)
...
@@ -73,11 +80,19 @@ GameServer.enterEmptyRoom = function(playerData)
GameServer
.
startRoom
=
function
(
roomIdx
)
GameServer
.
startRoom
=
function
(
roomIdx
)
{
{
this
.
playingRoom
[
roomIdx
].
Phase
=
this
.
Phase
.
START
;
this
.
playingRoom
[
roomIdx
].
Phase
=
this
.
Phase
.
START
;
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
forEach
(
element
=>
{
console
.
log
(
'
[ROOM#
'
+
this
.
playingRoom
[
roomIdx
].
roomNum
+
'
] Game Start
'
);
element
.
socketId
.
emit
(
'
phaseChange
'
,
this
.
Phase
.
START
);
this
.
anounceToRoom
(
roomIdx
,
'
phaseChange
'
,
this
.
Phase
.
START
);
element
.
socketId
.
emit
(
'
startGame
'
);
this
.
anounceToRoom
(
roomIdx
,
'
startGame
'
);
// 데이터 동기화
// 데이터 동기화도
}
GameServer
.
anounceToRoom
=
function
(
roomIdx
,
message
,
data
=
null
)
{
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
forEach
(
element
=>
{
element
.
socketId
.
emit
(
message
,
data
);
});
});
}
}
// 데이터 동기화 함수 만들기
// 동기화할것: 유저리스트(id - nickname 쌍)
module
.
exports
=
GameServer
;
module
.
exports
=
GameServer
;
\ No newline at end of file
js/Client.js
View file @
1090e19e
...
@@ -18,4 +18,8 @@ socket.on('phaseChange', function(msg) // number Phase
...
@@ -18,4 +18,8 @@ socket.on('phaseChange', function(msg) // number Phase
socket
.
on
(
'
startGame
'
,
function
()
socket
.
on
(
'
startGame
'
,
function
()
{
{
game
.
scene
.
start
(
'
gameScene
'
);
game
.
scene
.
start
(
'
gameScene
'
);
});
socket
.
on
(
'
userDisconnect
'
,
function
(
msg
)
// {num id, str nickname}
{
console
.
log
(
msg
.
id
+
'
/
'
+
msg
.
nickname
+
'
disconnected
'
);
});
});
\ No newline at end of file
server.js
View file @
1090e19e
...
@@ -26,7 +26,7 @@ io.on('connection', function(socket)
...
@@ -26,7 +26,7 @@ io.on('connection', function(socket)
id
:
GameServer
.
getPlayerNumber
(),
id
:
GameServer
.
getPlayerNumber
(),
nickname
:
'
게스트
'
,
nickname
:
'
게스트
'
,
socketId
:
socket
,
socketId
:
socket
,
curr
ne
tRoom
:
null
,
curr
en
tRoom
:
null
,
playerTyping
:
0
playerTyping
:
0
}
}
...
@@ -56,17 +56,31 @@ io.on('connection', function(socket)
...
@@ -56,17 +56,31 @@ io.on('connection', function(socket)
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
{
{
var
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
{
{
return
element
.
id
===
socket
.
playerData
.
id
;
return
element
.
id
===
socket
.
playerData
.
id
;
}
});
);
if
(
idxToDel
!=
-
1
)
if
(
idxToDel
!=
-
1
)
{
{
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client disconnected, reason:
'
+
reason
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client disconnected, reason:
'
+
reason
);
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
// 룸에서도 제거
// 룸에서도 제거
// 모두에게 삭제했다고 보내기
if
(
socket
.
playerData
.
currentRoom
!=
null
)
{
GameServer
.
anounceToRoom
(
GameServer
.
findRoomIndex
(
socket
.
playerData
.
currentRoom
.
roomNum
),
'
userDisconnect
'
,
{
id
:
socket
.
playerData
.
id
,
nickname
:
socket
.
playerData
.
nickname
});
let
_idxToDel
=
socket
.
playerData
.
currentRoom
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
socket
.
playerData
.
id
;
});
if
(
idxToDel
!=
-
1
)
{
socket
.
playerData
.
currentRoom
.
currentPlayer
.
splice
(
_idxToDel
,
1
);
}
}
}
}
});
});
});
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment