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
fc2d177d
Commit
fc2d177d
authored
Jul 04, 2019
by
18신대성
Committed by
16이지혜
Jul 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
이제 클라이언트 접속시 고유 번호(id)를 할당받음
parent
303a919d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
7 deletions
+36
-7
main.js
js/main.js
+7
-3
server.js
server.js
+29
-4
No files found.
js/main.js
View file @
fc2d177d
...
...
@@ -17,6 +17,7 @@ var config = {
};
var
game
=
new
Phaser
.
Game
(
config
)
var
playerNum
=
-
1
;
// load assets
function
preload
()
...
...
@@ -45,8 +46,11 @@ function update()
});
}
// client side
var
socket
=
io
.
connect
();
socket
.
on
(
'
hi
'
,
function
(
msg
)
{
console
.
log
(
msg
);
socket
.
on
(
'
idSet
'
,
function
(
msg
)
// {str, num}
{
console
.
log
(
msg
.
str
);
this
.
playerNum
=
msg
.
num
;
});
socket
.
emit
(
'
hello
'
);
\ No newline at end of file
socket
.
emit
(
'
idRequest
'
);
\ No newline at end of file
server.js
View file @
fc2d177d
...
...
@@ -16,10 +16,35 @@ server.listen(80, function() {
console
.
log
(
'
Listening on port
'
+
server
.
address
().
port
);
});
var
GameServer
=
GameServer
||
{};
GameServer
.
waitingRoom
=
[];
GameServer
.
getPlayerNumber
=
function
()
{
do
{
var
num
=
Math
.
floor
(
Math
.
random
()
*
1000
+
1
);
if
(
!
this
.
waitingRoom
.
includes
(
num
))
return
num
;
}
while
(
true
)
}
// 클라이언트 요청에 대한 콜백 정의
io
.
on
(
'
connection
'
,
function
(
socket
)
{
socket
.
on
(
'
hello
'
,
function
()
{
console
.
log
(
'
client request
'
);
socket
.
emit
(
'
hi
'
,
'
Hello, Client!
'
);
io
.
on
(
'
connection
'
,
function
(
socket
)
{
socket
.
on
(
'
idRequest
'
,
function
()
{
var
playerSocket
=
{
id
:
GameServer
.
getPlayerNumber
(),
socketId
:
socket
}
GameServer
.
waitingRoom
.
push
(
playerSocket
);
console
.
log
(
'
client request, id:
'
+
playerSocket
.
id
);
socket
.
emit
(
'
idSet
'
,
{
str
:
'
your number is
'
+
playerSocket
.
id
,
num
:
playerSocket
.
id
});
});
});
\ 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