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
4f461a07
Commit
4f461a07
authored
Jul 08, 2019
by
18신대성
Committed by
18류지석
Jul 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
게임 시작시 룸 동기화 구현
parent
9e260d8d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
21 deletions
+60
-21
GameServer.js
GameServer.js
+40
-11
Client.js
js/Client.js
+13
-4
server.js
server.js
+7
-6
No files found.
GameServer.js
View file @
4f461a07
...
@@ -34,7 +34,9 @@ GameServer.makeRoom = function()
...
@@ -34,7 +34,9 @@ GameServer.makeRoom = function()
{
{
roomNum
:
GameServer
.
nextRoomNumber
++
,
roomNum
:
GameServer
.
nextRoomNumber
++
,
maxPlayer
:
5
,
maxPlayer
:
5
,
nextRank
:
5
,
currentPlayer
:
[],
currentPlayer
:
[],
currentSocket
:
[],
currentPhase
:
GameServer
.
Phase
.
READY
,
currentPhase
:
GameServer
.
Phase
.
READY
,
rateArrangePoint
:
300
,
rateArrangePoint
:
300
,
...
@@ -54,11 +56,17 @@ GameServer.findRoomIndex = function(roomNum)
...
@@ -54,11 +56,17 @@ GameServer.findRoomIndex = function(roomNum)
}
}
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
{
{
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
push
(
playerData
);
let
room
=
this
.
playingRoom
[
roomIdx
];
playerData
.
currentRoom
=
this
.
playingRoom
[
roomIdx
];
let
player
=
new
Player
(
room
.
currentPlayer
.
length
,
playerData
);
console
.
log
(
'
[
'
+
playerData
.
id
+
'
] entered to room #
'
+
this
.
playingRoom
[
roomIdx
].
roomNum
);
if
(
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
length
>=
this
.
startCount
)
GameServer
.
startRoom
(
roomIdx
);
room
.
currentPlayer
.
push
(
player
);
return
this
.
playingRoom
[
roomIdx
];
room
.
currentSocket
.
push
(
playerData
);
playerData
.
playingData
=
player
;
playerData
.
currentRoom
=
room
;
console
.
log
(
'
[
'
+
playerData
.
id
+
'
] entered to room #
'
+
room
.
roomNum
);
if
(
room
.
currentPlayer
.
length
>=
this
.
startCount
)
GameServer
.
startRoom
(
roomIdx
);
return
room
;
}
}
GameServer
.
enterEmptyRoom
=
function
(
playerData
)
GameServer
.
enterEmptyRoom
=
function
(
playerData
)
{
{
...
@@ -84,19 +92,40 @@ GameServer.startRoom = function(roomIdx)
...
@@ -84,19 +92,40 @@ GameServer.startRoom = function(roomIdx)
room
.
maxTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
maxTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
minTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
minTypingPlayer
=
room
.
currentPlayer
[
0
];
// sync roomData
let
toSync
=
{
roomNum
:
room
.
roomNum
,
players
:
room
.
currentPlayer
};
console
.
log
(
toSync
);
this
.
announceToRoom
(
roomIdx
,
'
syncRoomData
'
,
toSync
);
console
.
log
(
'
[ROOM#
'
+
room
.
roomNum
+
'
] Game Start
'
);
console
.
log
(
'
[ROOM#
'
+
room
.
roomNum
+
'
] Game Start
'
);
this
.
announceToRoom
(
roomIdx
,
'
phaseChang
e
'
,
this
.
Phase
.
START
);
this
.
announceToRoom
(
roomIdx
,
'
changePhas
e
'
,
this
.
Phase
.
START
);
this
.
announceToRoom
(
roomIdx
,
'
startGame
'
);
this
.
announceToRoom
(
roomIdx
,
'
startGame
'
);
// 데이터 동기화도
}
}
GameServer
.
announceToRoom
=
function
(
roomIdx
,
message
,
data
=
null
)
GameServer
.
announceToRoom
=
function
(
roomIdx
,
_message
,
_
data
=
null
)
{
{
this
.
playingRoom
[
roomIdx
].
current
Player
.
forEach
(
element
=>
this
.
playingRoom
[
roomIdx
].
current
Socket
.
forEach
(
function
(
element
)
{
{
element
.
socketId
.
emit
(
message
,
data
);
element
.
socketId
.
emit
(
_message
,
_
data
);
});
});
}
}
// 데이터 동기화 함수 만들기
// 데이터 동기화 함수 만들기
// 동기화할것: 유저리스트(id - nickname 쌍)
// 동기화할것: 유저리스트(id - nickname 쌍)
class
Player
{
constructor
(
index
,
playerData
)
{
this
.
index
=
index
;
this
.
id
=
playerData
.
id
;
this
.
nickname
=
playerData
.
nickname
;
this
.
isAlive
=
true
;
this
.
rank
=
-
1
;
this
.
playerTyping
=
0
;
}
}
module
.
exports
=
GameServer
;
module
.
exports
=
GameServer
;
\ No newline at end of file
js/Client.js
View file @
4f461a07
var
socket
=
io
.
connect
();
var
socket
=
io
.
connect
();
socket
.
emit
(
'
idRequest
'
);
socket
.
emit
(
'
idRequest
'
);
socket
.
on
(
'
idSet
'
,
function
(
msg
)
// {str, num playerNum}
socket
.
on
(
'
setId
'
,
function
(
msg
)
// {str, num playerNum}
{
{
console
.
log
(
msg
.
str
);
console
.
log
(
msg
.
str
);
PlayerData
.
idNum
=
msg
.
num
;
PlayerData
.
idNum
=
msg
.
num
;
...
@@ -11,15 +11,24 @@ socket.on('setPlayerTypingRate', function(msg) // number playerTypingRate
...
@@ -11,15 +11,24 @@ socket.on('setPlayerTypingRate', function(msg) // number playerTypingRate
WordSpace
.
PlayerTypingRate
=
msg
;
WordSpace
.
PlayerTypingRate
=
msg
;
console
.
log
(
'
rate:
'
+
msg
);
console
.
log
(
'
rate:
'
+
msg
);
});
});
socket
.
on
(
'
phaseChange
'
,
function
(
msg
)
// number Phase
socket
.
on
(
'
syncRoomData
'
,
function
(
msg
)
// {num roomNum, [] players}
{
{
console
.
log
(
'
phase changed from
'
+
WordSpace
.
CurrentPhase
+
'
to
'
+
msg
);
console
.
log
(
msg
);
WordSpace
.
CurrentPhase
=
msg
;
RoomData
.
roomNum
=
msg
.
roomNum
;
RoomData
.
players
=
msg
.
players
;
});
});
socket
.
on
(
'
startGame
'
,
function
()
socket
.
on
(
'
startGame
'
,
function
()
{
{
game
.
scene
.
start
(
'
gameScene
'
);
game
.
scene
.
start
(
'
gameScene
'
);
});
});
socket
.
on
(
'
changePhase
'
,
function
(
msg
)
// number Phase
{
console
.
log
(
'
phase changed from
'
+
WordSpace
.
CurrentPhase
+
'
to
'
+
msg
);
WordSpace
.
CurrentPhase
=
msg
;
});
socket
.
on
(
'
userDisconnect
'
,
function
(
msg
)
// {num id, str nickname}
socket
.
on
(
'
userDisconnect
'
,
function
(
msg
)
// {num id, str nickname}
{
{
console
.
log
(
msg
.
id
+
'
/
'
+
msg
.
nickname
+
'
disconnected
'
);
console
.
log
(
msg
.
id
+
'
/
'
+
msg
.
nickname
+
'
disconnected
'
);
...
...
server.js
View file @
4f461a07
...
@@ -27,12 +27,11 @@ io.on('connection', function(socket)
...
@@ -27,12 +27,11 @@ io.on('connection', function(socket)
nickname
:
'
게스트
'
,
nickname
:
'
게스트
'
,
socketId
:
socket
,
socketId
:
socket
,
currentRoom
:
null
,
currentRoom
:
null
,
playingData
:
null
playerTyping
:
0
};
};
GameServer
.
currentPlayer
.
push
(
socket
.
playerData
);
GameServer
.
currentPlayer
.
push
(
socket
.
playerData
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client request
'
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client request
'
);
socket
.
emit
(
'
idSet
'
,
socket
.
emit
(
'
setId
'
,
{
{
str
:
'
your number is
'
+
socket
.
playerData
.
id
,
str
:
'
your number is
'
+
socket
.
playerData
.
id
,
num
:
socket
.
playerData
.
id
num
:
socket
.
playerData
.
id
...
@@ -48,7 +47,7 @@ io.on('connection', function(socket)
...
@@ -48,7 +47,7 @@ io.on('connection', function(socket)
socket
.
on
(
'
setPlayerTyping
'
,
function
(
msg
)
// number playerTyping
socket
.
on
(
'
setPlayerTyping
'
,
function
(
msg
)
// number playerTyping
{
{
socket
.
playerData
.
playerTyping
=
msg
;
socket
.
playerData
.
play
ingData
.
play
erTyping
=
msg
;
if
(
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
.
playerTyping
<
msg
)
if
(
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
.
playerTyping
<
msg
)
{
{
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
=
socket
.
playerData
;
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
=
socket
.
playerData
;
...
@@ -84,9 +83,11 @@ io.on('connection', function(socket)
...
@@ -84,9 +83,11 @@ io.on('connection', function(socket)
{
{
return
element
.
id
===
socket
.
playerData
.
id
;
return
element
.
id
===
socket
.
playerData
.
id
;
});
});
if
(
idxToDel
!=
-
1
)
if
(
_
idxToDel
!=
-
1
)
{
{
socket
.
playerData
.
currentRoom
.
currentPlayer
.
splice
(
_idxToDel
,
1
);
socket
.
playerData
.
currentRoom
.
currentPlayer
[
_idxToDel
].
isAlive
=
false
;
socket
.
playerData
.
currentRoom
.
currentPlayer
[
_idxToDel
].
rank
=
socket
.
playerData
.
currentRoom
.
nextRank
--
;
socket
.
playerData
.
currentRoom
.
currentSocket
.
splice
(
_idxToDel
,
1
);
}
}
}
}
}
}
...
...
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