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
a5784ccc
Commit
a5784ccc
authored
Jul 08, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Plain Diff
서버와 머지함
parents
2f14acfd
4f461a07
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
34 deletions
+88
-34
GameServer.js
GameServer.js
+46
-17
Client.js
js/Client.js
+15
-5
Input.js
js/Input.js
+11
-4
WordObject.js
js/WordObject.js
+1
-1
WordSpace.js
js/WordSpace.js
+5
-5
main.js
js/main.js
+10
-2
No files found.
GameServer.js
View file @
a5784ccc
...
...
@@ -33,9 +33,11 @@ GameServer.makeRoom = function()
var
roomOption
=
{
roomNum
:
GameServer
.
nextRoomNumber
++
,
maxPlayer
:
3
,
maxPlayer
:
5
,
nextRank
:
5
,
currentPlayer
:
[],
currnetPhase
:
GameServer
.
Phase
.
READY
,
currentSocket
:
[],
currentPhase
:
GameServer
.
Phase
.
READY
,
rateArrangePoint
:
300
,
maxTypingPlayer
:
null
,
...
...
@@ -54,18 +56,24 @@ GameServer.findRoomIndex = function(roomNum)
}
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
{
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
push
(
playerData
);
playerData
.
currentRoom
=
this
.
playingRoom
[
roomIdx
];
console
.
log
(
'
[
'
+
playerData
.
id
+
'
] entered to room #
'
+
this
.
playingRoom
[
roomIdx
].
roomNum
);
if
(
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
length
>=
this
.
startCount
&&
this
.
playingRoom
[
roomIdx
].
Phase
!=
GameServer
.
Phase
.
START
)
GameServer
.
startRoom
(
roomIdx
);
return
this
.
playingRoom
[
roomIdx
];
let
room
=
this
.
playingRoom
[
roomIdx
];
let
player
=
new
Player
(
room
.
currentPlayer
.
length
,
playerData
);
room
.
currentPlayer
.
push
(
player
);
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
)
{
var
toEnter
=
-
1
;
for
(
let
i
=
0
;
i
<
this
.
playingRoom
.
length
;
i
++
)
{
if
(
this
.
playingRoom
[
i
].
currentPlayer
.
length
<
this
.
playingRoom
[
i
].
maxPlayer
)
if
(
this
.
playingRoom
[
i
].
currentPlayer
.
length
<
this
.
playingRoom
[
i
].
maxPlayer
&&
this
.
playingRoom
[
i
].
currentPhase
==
this
.
Phase
.
READY
)
{
toEnter
=
i
;
break
;
...
...
@@ -80,23 +88,44 @@ GameServer.enterEmptyRoom = function(playerData)
GameServer
.
startRoom
=
function
(
roomIdx
)
{
let
room
=
this
.
playingRoom
[
roomIdx
];
this
.
playingRoom
[
roomIdx
].
Phase
=
this
.
Phase
.
START
;
this
.
playingRoom
[
roomIdx
].
maxTypingPlayer
=
room
.
currentPlayer
[
0
];
this
.
playingRoom
[
roomIdx
].
mimTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
currentPhase
=
this
.
Phase
.
START
;
room
.
maxTypingPlayer
=
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
'
);
this
.
announceToRoom
(
roomIdx
,
'
phaseChang
e
'
,
this
.
Phase
.
START
);
this
.
announceToRoom
(
roomIdx
,
'
changePhas
e
'
,
this
.
Phase
.
START
);
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 쌍)
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
;
\ No newline at end of file
js/Client.js
View file @
a5784ccc
var
socket
=
io
.
connect
();
socket
.
emit
(
'
idRequest
'
);
socket
.
on
(
'
idSet
'
,
function
(
msg
)
// {str, num playerNum}
socket
.
on
(
'
setId
'
,
function
(
msg
)
// {str, num playerNum}
{
console
.
log
(
msg
.
str
);
player
Num
=
msg
.
num
;
PlayerData
.
id
Num
=
msg
.
num
;
});
socket
.
on
(
'
setPlayerTypingRate
'
,
function
(
msg
)
// number playerTypingRate
{
WordSpace
.
PlayerTypingRate
=
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
);
WordSpace
.
CurrentPhase
=
msg
;
console
.
log
(
msg
);
RoomData
.
roomNum
=
msg
.
roomNum
;
RoomData
.
players
=
msg
.
players
;
});
socket
.
on
(
'
startGame
'
,
function
()
{
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}
{
console
.
log
(
msg
.
id
+
'
/
'
+
msg
.
nickname
+
'
disconnected
'
);
...
...
js/Input.js
View file @
a5784ccc
...
...
@@ -4,6 +4,7 @@ Input.input = [];
Input
.
convInput
=
''
;
// converted input
Input
.
isShifted
=
false
;
Input
.
isEntered
=
false
;
Input
.
pressCount
=
0
;
Input
.
justPressed
=
''
;
Input
.
maxInput
=
5
;
...
...
@@ -13,10 +14,14 @@ Input.attackOption = null;
Input
.
gameSceneEnterReaction
=
function
()
{
if
(
!
Input
.
isEntered
)
{
Input
.
convInput
=
Input
.
removeConVow
(
Input
.
convInput
);
if
(
Input
.
attackMode
)
WordSpace
.
attack
(
Input
.
convInput
,
Input
.
attackOption
.
wordGrade
);
else
WordSpace
.
findWord
(
Input
.
convInput
);
Input
.
reset
();
Input
.
isEntered
=
true
;
}
}
Input
.
menuSceneEnterReaction
=
function
()
{
...
...
@@ -24,6 +29,7 @@ Input.menuSceneEnterReaction = function()
if
(
Input
.
convInput
.
length
>
0
)
{
socket
.
emit
(
'
setNickname
'
,
Input
.
convInput
);
PlayerData
.
nickname
=
Input
.
convInput
;
Input
.
reset
();
game
.
scene
.
remove
(
'
menuScene
'
);
}
...
...
@@ -317,6 +323,7 @@ Input.inputField =
}
});
scene
.
input
.
keyboard
.
on
(
'
keydown-ENTER
'
,
enterCallback
);
scene
.
input
.
keyboard
.
on
(
'
keyup-ENTER
'
,
function
(){
Input
.
isEntered
=
false
;})
// upside 10 keys
scene
.
input
.
keyboard
.
on
(
'
keydown-Q
'
,
function
()
{
Input
.
pushInput
(
'
ㅂ
'
)});
scene
.
input
.
keyboard
.
on
(
'
keydown-W
'
,
function
()
{
Input
.
pushInput
(
'
ㅈ
'
)});
...
...
js/WordObject.js
View file @
a5784ccc
...
...
@@ -120,7 +120,7 @@ class AttackWord extends WordObject
this
.
wordGrade
=
_wordGrade
;
this
.
wordWeight
=
WordReader
.
getWordWeight
(
this
.
wordGrade
);
if
(
WordReader
.
getWordTyping
(
_attacker
)
<=
9
)
this
.
wordWeight
+=
this
.
wordWeight
*
0.2
*
(
WordReader
.
getWordTyping
(
playerN
ame
)
-
9
);
this
.
wordWeight
+=
this
.
wordWeight
*
0.2
*
(
WordReader
.
getWordTyping
(
PlayerData
.
nickn
ame
)
-
9
);
this
.
wordWeight
*=
isStrong
?
3
:
2
;
this
.
attacker
=
_attacker
;
//서버 사용하게 되면 PlayerTyping을 피격자의 것으로 바꿔야 함
...
...
js/WordSpace.js
View file @
a5784ccc
...
...
@@ -253,7 +253,7 @@ WordSpace.generateWord =
Name
:
function
(
scene
,
isStrong
,
lenRate
)
{
//To do
word
=
new
NameWord
(
playerN
ame
,
isStrong
);
word
=
new
NameWord
(
PlayerData
.
nickn
ame
,
isStrong
);
WordSpace
.
pushWord
(
scene
,
word
,
lenRate
);
}
}
...
...
@@ -346,8 +346,8 @@ WordSpace.setPlayerTyping =
add
:
function
(
wordText
)
{
this
.
totalTyping
+=
wordText
!=
null
?
WordReader
.
getWordTyping
(
wordText
)
:
0
;
WordSpace
.
playerTyping
=
this
.
totalTyping
/
WordSpace
.
gameTimer
.
now
*
1000
;
socket
.
emit
(
'
setPlayerTyping
'
,
this
.
playerTyping
);
WordSpace
.
playerTyping
=
this
.
totalTyping
/
WordSpace
.
gameTimer
.
now
*
60
*
1000
;
socket
.
emit
(
'
setPlayerTyping
'
,
WordSpace
.
playerTyping
);
this
.
text
.
setText
(
'
현재 타수 :
'
+
WordSpace
.
playerTyping
.
toFixed
(
1
));
},
initiate
:
function
(
scene
)
...
...
@@ -367,7 +367,7 @@ WordSpace.attack = function(wordText, grade)
//호패에 따른 isStrong 구분 필요함
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
WordSpace
.
generateWord
.
Attack
(
WordSpace
.
gameSceneForTest
,
wordText
,
grade
,
playerN
ame
,
element
.
isStrong
);
WordSpace
.
generateWord
.
Attack
(
WordSpace
.
gameSceneForTest
,
wordText
,
grade
,
PlayerData
.
nickn
ame
,
element
.
isStrong
);
});
WordSpace
.
nameGroup
=
[];
...
...
js/main.js
View file @
a5784ccc
...
...
@@ -16,5 +16,13 @@ var game = new Phaser.Game(config)
//플레이어 정보, 서버 통신시 필요할 듯
//테스트용이므로 차후 수정 요망
var
playerNum
=
-
1
;
//플레이어 아이디, 고유 번호
var
playerName
=
'
임시아이디
'
//플레이어 닉네임
\ No newline at end of file
var
PlayerData
=
PlayerData
||
{};
PlayerData
.
idNum
=
-
1
;
//플레이어 아이디, 고유 번호
PlayerData
.
nickname
=
'
홍길동
'
;
//플레이어 닉네임
// 현재 들어가있는 Game Room의 정보
var
RoomData
=
RoomData
||
{};
RoomData
.
roomNum
=
-
1
;
RoomData
.
players
=
null
;
\ 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