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
47bb8f98
Commit
47bb8f98
authored
Jul 10, 2019
by
18류지석
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'server'
parents
13860f74
9ff5a83c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
27 deletions
+84
-27
GameServer.js
GameServer.js
+29
-7
Client.js
js/Client.js
+8
-0
Input.js
js/Input.js
+1
-2
WordObject.js
js/WordObject.js
+1
-1
server.js
server.js
+45
-17
No files found.
GameServer.js
View file @
47bb8f98
var
GameServer
=
GameServer
||
{};
GameServer
.
Phase
=
{
READY
:
0
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
startCount
=
4
;
GameServer
.
startCount
=
2
;
GameServer
.
currentPlayer
=
[];
GameServer
.
playingRoom
=
[];
...
...
@@ -57,14 +57,32 @@ GameServer.findRoomIndex = function(roomNum)
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
{
let
room
=
this
.
playingRoom
[
roomIdx
];
let
player
=
new
Player
(
room
.
currentPlayer
.
length
,
playerData
);
let
nextIdx
=
-
1
;
for
(
let
i
=
0
;
i
<
room
.
currentPlayer
.
length
;
i
++
)
{
if
(
room
.
currentPlayer
[
i
]
===
null
)
{
nextIdx
=
i
;
break
}
}
let
player
=
new
Player
((
nextIdx
!=
-
1
?
nextIdx
:
room
.
currentPlayer
.
length
),
playerData
);
room
.
currentPlayer
.
push
(
player
);
room
.
currentSocket
.
push
(
playerData
);
if
(
nextIdx
!=
-
1
)
{
room
.
currentPlayer
[
nextIdx
]
=
player
;
room
.
currentSocket
[
nextIdx
]
=
playerData
;
}
else
{
room
.
currentPlayer
.
push
(
player
);
room
.
currentSocket
.
push
(
playerData
);
}
playerData
.
playingData
=
player
;
playerData
.
currentRoom
=
room
;
console
.
log
(
'
[
'
+
playerData
.
id
+
'
] entered to room #
'
+
room
.
roomNum
);
playerData
.
socketId
.
emit
(
'
enterRoom
'
);
if
(
room
.
currentPlayer
.
length
>=
this
.
startCount
)
GameServer
.
startRoom
(
roomIdx
);
return
room
;
}
...
...
@@ -91,6 +109,10 @@ GameServer.startRoom = function(roomIdx)
room
.
currentPhase
=
this
.
Phase
.
START
;
room
.
maxTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
minTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
currentSocket
.
forEach
(
function
(
element
)
{
element
.
isReceivable
=
true
;
});
// sync roomData
let
toSync
=
...
...
@@ -98,10 +120,10 @@ GameServer.startRoom = function(roomIdx)
roomNum
:
room
.
roomNum
,
players
:
room
.
currentPlayer
};
console
.
log
(
toSync
);
//
console.log(toSync);
this
.
announceToRoom
(
roomIdx
,
'
syncRoomData
'
,
toSync
);
console
.
log
(
'
[ROOM#
'
+
room
.
roomNum
+
'
] Game Start
'
);
console
.
log
(
'
[ROOM#
'
+
room
.
roomNum
+
'
] Game Start
with
'
+
room
.
currentPlayer
.
length
+
'
players
'
);
this
.
announceToRoom
(
roomIdx
,
'
changePhase
'
,
this
.
Phase
.
START
);
this
.
announceToRoom
(
roomIdx
,
'
startGame
'
);
}
...
...
@@ -118,7 +140,7 @@ GameServer.announceToTarget = function(roomIdx, targetNum, _message, _data = nul
{
return
element
.
id
===
targetNum
;
});
if
(
targetSocket
!=
undefined
)
targetSocket
.
socketId
.
emit
(
_message
,
_data
);
if
(
targetSocket
!=
undefined
&&
targetSocket
.
isReceivable
)
targetSocket
.
socketId
.
emit
(
_message
,
_data
);
}
// 데이터 동기화 함수 만들기
// 동기화할것: 유저리스트(id - nickname 쌍)
...
...
js/Client.js
View file @
47bb8f98
...
...
@@ -7,6 +7,14 @@ socket.on('setId', function(msg) // {str, num playerNum}
console
.
log
(
msg
.
str
);
PlayerData
.
idNum
=
msg
.
num
;
});
socket
.
on
(
'
errNicknameOverlaped
'
,
function
()
{
alert
(
'
이미 사용중인 닉네임입니다.
'
);
});
socket
.
on
(
'
enterRoom
'
,
function
()
{
game
.
scene
.
remove
(
'
menuScene
'
);
});
// init game
socket
.
on
(
'
syncRoomData
'
,
function
(
msg
)
// {num roomNum, [] players}
...
...
js/Input.js
View file @
47bb8f98
...
...
@@ -26,12 +26,11 @@ Input.gameSceneEnterReaction = function()
Input
.
menuSceneEnterReaction
=
function
()
{
Input
.
convInput
=
Input
.
removeConVow
(
Input
.
convInput
);
if
(
Input
.
convInput
.
length
>
0
)
if
(
Input
.
convInput
.
length
>
1
)
{
socket
.
emit
(
'
setNickname
'
,
Input
.
convInput
);
PlayerData
.
nickname
=
Input
.
convInput
;
Input
.
reset
();
game
.
scene
.
remove
(
'
menuScene
'
);
}
else
{
...
...
js/WordObject.js
View file @
47bb8f98
...
...
@@ -14,7 +14,7 @@ class WordObject
instantiate
(
scene
,
lenRate
)
{
let
p
=
[{
x
:
3
,
y
:
0.7
},
{
x
:
20
,
y
:
1.
8
}];
let
p
=
[{
x
:
3
,
y
:
0.7
},
{
x
:
20
,
y
:
1.
2
}];
let
scale
=
((
p
[
1
].
y
-
p
[
0
].
y
)
/
(
p
[
1
].
x
-
p
[
0
].
x
))
*
(
this
.
wordWeight
-
p
[
0
].
x
)
+
p
[
0
].
y
;
let
fontscale
=
25
;
var
random
=
WordSpace
.
getSpawnPoint
(
lenRate
);
...
...
server.js
View file @
47bb8f98
...
...
@@ -28,8 +28,7 @@ io.on('connection', function(socket)
socketId
:
socket
,
currentRoom
:
null
,
playingData
:
null
,
playerTyping
:
0
isReceivable
:
false
};
GameServer
.
currentPlayer
.
push
(
socket
.
playerData
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client request
'
);
...
...
@@ -42,9 +41,19 @@ io.on('connection', function(socket)
socket
.
on
(
'
setNickname
'
,
function
(
msg
)
// string new_nickname
{
socket
.
playerData
.
nickname
=
msg
;
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] nickname set to
'
+
msg
);
GameServer
.
enterEmptyRoom
(
socket
.
playerData
);
let
isAlreadyHave
=
false
;
GameServer
.
currentPlayer
.
forEach
(
function
(
element
)
{
if
(
element
.
nickname
===
msg
)
isAlreadyHave
=
true
;
});
if
(
isAlreadyHave
)
socket
.
emit
(
'
errNicknameOverlaped
'
);
else
{
socket
.
playerData
.
nickname
=
msg
;
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] nickname set to
'
+
msg
);
GameServer
.
enterEmptyRoom
(
socket
.
playerData
);
}
});
socket
.
on
(
'
setPlayerTyping
'
,
function
(
msg
)
// number playerTyping
...
...
@@ -72,6 +81,7 @@ io.on('connection', function(socket)
{
socket
.
playerData
.
playingData
.
isAlive
=
false
;
socket
.
playerData
.
playingData
.
rank
=
socket
.
playerData
.
currentRoom
.
nextRank
--
;
socket
.
playerData
.
isReceivable
=
false
;
// 패배단어 체크
GameServer
.
announceToRoom
(
socket
.
playerData
.
currentRoom
.
roomNum
,
'
defeat
'
,
socket
.
playerData
.
playingData
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
]
'
+
'
defeated
'
);
...
...
@@ -79,22 +89,40 @@ io.on('connection', function(socket)
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
{
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
let
data
=
socket
.
playerData
;
console
.
log
(
'
[
'
+
data
.
id
+
'
] client disconnected, reason:
'
+
reason
);
if
(
typeof
data
.
id
===
undefined
)
{
return
element
.
id
===
socket
.
playerData
.
id
;
});
if
(
idxToDel
!=
-
1
)
console
.
log
(
'
[ERROR] data.id is undefined
'
);
console
.
log
(
GameServer
.
currentPlayer
);
}
else
// data.id is not undefined
{
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client disconnected, reason:
'
+
reason
);
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
// 룸에서도 제거
if
(
socket
.
playerData
.
currentRoom
!=
null
)
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
data
.
id
;
});
if
(
idxToDel
!=
-
1
)
{
socket
.
playerData
.
playingData
.
isAlive
=
false
;
if
(
socket
.
playerData
.
playingData
.
rank
===
-
1
)
socket
.
playerData
.
playingData
.
rank
=
socket
.
playerData
.
currentRoom
.
nextRank
--
;
socket
.
playerData
.
currentRoom
.
currentSocket
.
splice
(
socket
.
playerData
.
playingData
.
index
,
1
);
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
socket
.
playerData
.
currentRoom
.
roomNum
),
'
userDisconnect
'
,
socket
.
playerData
.
playingData
);
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
// 룸에서도 제거
if
(
data
.
currentRoom
!=
null
)
{
if
(
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
READY
)
{
data
.
currentRoom
.
currentPlayer
[
data
.
playingData
.
index
]
=
null
;
data
.
currentRoom
.
currentSocket
[
data
.
playingData
.
index
]
=
null
;
}
else
{
data
.
playingData
.
isAlive
=
false
;
if
(
data
.
playingData
.
rank
===
-
1
)
data
.
playingData
.
rank
=
data
.
currentRoom
.
nextRank
--
;
data
.
currentRoom
.
currentSocket
[
data
.
playingData
.
index
].
isReceivable
=
false
;
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
data
.
currentRoom
.
roomNum
),
'
userDisconnect
'
,
data
.
playingData
);
}
}
}
console
.
log
(
'
[
'
+
data
.
id
+
'
] disconnect complete
'
);
}
});
});
\ 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