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
acb37829
Commit
acb37829
authored
Aug 19, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/server'
parents
745814fd
67495311
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
64 deletions
+95
-64
GameServer.js
GameServer.js
+46
-19
Client.js
js/Client.js
+6
-4
GameCycle.js
js/GameCycle.js
+0
-2
WordSpace.js
js/WordSpace.js
+12
-20
server.js
server.js
+31
-19
No files found.
GameServer.js
View file @
acb37829
...
...
@@ -2,7 +2,7 @@ var GameServer = GameServer || {};
GameServer
.
serverNumber
=
-
1
;
GameServer
.
Phase
=
{
READY
:
0
,
COUNT
:
-
1
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
Phase
=
{
READY
:
0
,
COUNT
:
-
1
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
,
GAMEEND
:
4
};
GameServer
.
connectCount
=
0
;
GameServer
.
disconnectCount
=
0
;
...
...
@@ -82,7 +82,7 @@ class GameRoom
{
this
.
roomId
=
GameServer
.
getRoomNumber
();
this
.
roomIndex
=
-
1
;
this
.
startCount
=
3
;
this
.
startCount
=
2
;
this
.
maxPlayer
=
100
;
this
.
nextRank
=
100
;
...
...
@@ -215,13 +215,31 @@ class GameRoom
clearTimeout
(
this
.
startTimer
);
this
.
startTimer
=
undefined
;
}
this
.
announceToRoom
(
'
enterRoom
'
);
this
.
announceToRoom
(
'
syncRoomScene
'
,
this
.
currentPlayer
);
this
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
false
,
endTime
:
0
,
playerCount
:
this
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
{
id
:
-
1
}
});
console
.
error
(
'
[ROOM#
'
+
this
.
roomId
+
'
] room Refreshed
'
);
if
(
this
.
currentPhase
!=
GameServer
.
Phase
.
GAMEEND
)
{
this
.
announceToRoom
(
'
enterRoom
'
);
this
.
announceToRoom
(
'
syncRoomScene
'
,
this
.
currentPlayer
);
this
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
false
,
endTime
:
0
,
playerCount
:
this
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
{
id
:
-
1
}
});
console
.
error
(
'
[ROOM#
'
+
this
.
roomId
+
'
] room Refreshed
'
);
}
else
{
this
.
startTime
=
0
;
this
.
currentPlayer
=
[];
this
.
aliveCount
=
0
;
this
.
currentSocket
=
[];
this
.
currentPhase
=
GameServer
.
Phase
.
READY
;
this
.
phaseChanger
=
-
1
;
this
.
countEndTime
=
0
;
this
.
rateArrangePoint
=
300
;
this
.
maxTypingPlayer
=
null
;
this
.
minTypingPlayer
=
null
;
console
.
log
(
'
[ROOM#
'
+
this
.
roomId
+
'
] room Refreshed with End of Game
'
);
}
}
startRoom
()
...
...
@@ -308,20 +326,26 @@ class GameRoom
announceToRoom
(
_message
,
_data
=
null
)
{
this
.
currentSocket
.
forEach
(
function
(
element
)
if
(
this
.
currentPhase
!=
GameServer
.
Phase
.
GAMEEND
)
{
if
(
element
.
playerData
.
playingData
.
isInThisRoom
)
element
.
emit
(
_message
,
_data
);
});
this
.
currentSocket
.
forEach
(
function
(
element
)
{
if
(
element
.
playerData
.
playingData
.
isInThisRoom
)
element
.
emit
(
_message
,
_data
);
});
}
}
announceToTarget
(
targetId
,
_message
,
_data
=
null
)
{
let
targetSocketIndex
=
this
.
currentSocket
.
findIndex
(
function
(
element
)
if
(
this
.
currentPhase
!=
GameServer
.
Phase
.
GAMEEND
)
{
return
element
.
playerData
.
id
===
targetId
;
});
//console.log('send to ' + targetSocketIndex + ', receivable? ' + this.currentSocket[targetSocketIndex].playerData.isReceivable);
if
(
targetSocketIndex
!=
-
1
&&
this
.
currentSocket
[
targetSocketIndex
].
playerData
.
isReceivable
)
this
.
currentSocket
[
targetSocketIndex
].
emit
(
_message
,
_data
);
let
targetSocketIndex
=
this
.
currentSocket
.
findIndex
(
function
(
element
)
{
return
element
.
playerData
.
id
===
targetId
;
});
//console.log('send to ' + targetSocketIndex + ', receivable? ' + this.currentSocket[targetSocketIndex].playerData.isReceivable);
if
(
targetSocketIndex
!=
-
1
&&
this
.
currentSocket
[
targetSocketIndex
].
playerData
.
isReceivable
)
this
.
currentSocket
[
targetSocketIndex
].
emit
(
_message
,
_data
);
}
}
}
...
...
@@ -356,6 +380,7 @@ class Player
this
.
isAlive
=
false
;
this
.
rank
=
room
.
nextRank
--
;
if
(
this
.
tabCheckTime
!=
undefined
)
clearTimeout
(
this
.
tabCheckTime
);
socket
.
playerData
.
isReceivable
=
false
;
room
.
aliveCount
--
;
...
...
@@ -383,14 +408,16 @@ class Player
room
.
announceToRoom
(
'
defeat
'
,
this
);
console
.
log
(
'
[
'
+
this
.
id
+
'
] defeated, rank:
'
+
this
.
rank
+
'
,
'
+
room
.
aliveCount
+
'
player left
'
);
if
(
socket
.
playerData
.
currentR
oom
.
aliveCount
===
1
)
if
(
r
oom
.
aliveCount
===
1
)
{
let
winner
=
room
.
currentPlayer
.
find
(
function
(
element
)
{
return
element
.
isAlive
;
});
room
.
announceToRoom
(
'
gameEnd
'
,
winner
);
if
(
winner
.
tabCheckTime
!=
undefined
)
clearTimeout
(
winner
.
tabCheckTime
);
room
.
announceToRoom
(
'
gameEnd
'
,
winner
.
id
);
room
.
announceToTarget
(
winner
.
id
,
'
alert
'
,
'
gameWin
'
);
room
.
currentPhase
=
GameServer
.
Phase
.
GAMEEND
;
console
.
log
(
'
[
'
+
winner
.
id
+
'
]
'
+
'
winner!
'
+
winner
.
nickname
);
}
}
...
...
js/Client.js
View file @
acb37829
...
...
@@ -143,7 +143,8 @@ socket.on('changePhase', function(msg) // number Phase
});
socket
.
on
(
'
setPlayerTypingRate
'
,
function
(
msg
)
// number playerTypingRate
{
WordSpace
.
PlayerTypingRate
=
msg
;
WordSpace
.
playerTypingRate
=
msg
;
WordSpace
.
adjustVarByPhase
();
//console.log('rate: ' + msg);
});
socket
.
on
(
'
writeWord
'
,
function
(
msg
)
// number playerId
...
...
@@ -244,10 +245,11 @@ socket.on('defeat', function(msg) // object player
backToMenu
(
false
);
}
});
socket
.
on
(
'
gameEnd
'
,
function
(
msg
)
//
object player
socket
.
on
(
'
gameEnd
'
,
function
(
msg
)
//
number winnerId
{
console
.
log
(
msg
.
nickname
+
'
Win!!!!!!
'
);
if
(
msg
.
id
==
RoomData
.
myself
.
id
)
const
winner
=
RoomData
.
findPlayer
(
msg
);
console
.
log
(
winner
.
nickname
+
'
Win!!!!!!
'
);
if
(
msg
==
RoomData
.
myself
.
id
)
{
RoomData
.
myself
.
rank
=
1
;
backToMenu
(
true
);
...
...
js/GameCycle.js
View file @
acb37829
...
...
@@ -2,7 +2,6 @@ WordSpace.startCycle = function(scene)
{
WordSpace
.
wordCycle
.
resetCycle
(
scene
,
3000
,
0
,
true
);
WordSpace
.
nameCycle
.
resetCycle
(
scene
,
3000
,
0
,
true
);
WordSpace
.
varAdjustCycle
.
resetCycle
(
scene
,
100
,
0
,
true
);
WordSpace
.
playerTypingCycle
.
resetCycle
(
scene
,
500
,
500
,
true
);
}
...
...
@@ -10,7 +9,6 @@ WordSpace.pauseCycle = function(isPause)
{
WordSpace
.
wordCycle
.
currentCycle
.
paused
=
isPause
;
WordSpace
.
nameCycle
.
currentCycle
.
paused
=
isPause
;
WordSpace
.
varAdjustCycle
.
currentCycle
.
paused
=
isPause
;
WordSpace
.
attackGauge
.
pauseCycle
(
isPause
);
WordSpace
.
playerTypingCycle
.
currentCycle
.
paused
=
isPause
;
WordSpace
.
attackedEvents
.
forEach
(
function
(
element
)
{
element
.
currentCycle
.
paused
=
isPause
});
...
...
js/WordSpace.js
View file @
acb37829
...
...
@@ -65,34 +65,34 @@ WordSpace.spaceInitiate = function(scene)
});
}
WordSpace
.
AdjustVarByPhase
=
function
(
typingRate
,
phase
)
WordSpace
.
adjustVarByPhase
=
function
(
)
{
if
(
p
hase
==
WordSpace
.
Phase
.
START
)
if
(
WordSpace
.
CurrentP
hase
==
WordSpace
.
Phase
.
START
)
{
WordSpace
.
delay
.
WordSpawn
=
3000
;
WordSpace
.
delay
.
NameSpawn
=
15000
;
WordSpace
.
NameSpawnReduce
=
1000
;
WordSpace
.
GradeProb
[
0
]
=
0.35
;
WordSpace
.
GradeProb
[
1
]
=
1
-
0.4
*
t
ypingRate
;
WordSpace
.
GradeProb
[
1
]
=
1
-
0.4
*
WordSpace
.
playerT
ypingRate
;
WordSpace
.
GradeProb
[
2
]
=
1
;
}
else
if
(
p
hase
==
WordSpace
.
Phase
.
MAIN
)
else
if
(
WordSpace
.
CurrentP
hase
==
WordSpace
.
Phase
.
MAIN
)
{
WordSpace
.
delay
.
WordSpawn
=
3000
-
t
ypingRate
*
1000
;
WordSpace
.
delay
.
WordSpawn
=
3000
-
WordSpace
.
playerT
ypingRate
*
1000
;
WordSpace
.
delay
.
NameSpawn
=
12000
;
WordSpace
.
NameSpawnReduce
=
1000
;
WordSpace
.
GradeProb
[
0
]
=
0.5
-
0.5
*
t
ypingRate
;
WordSpace
.
GradeProb
[
1
]
=
1
-
0.5
*
t
ypingRate
;
WordSpace
.
GradeProb
[
2
]
=
1
-
0.15
*
t
ypingRate
;
WordSpace
.
GradeProb
[
0
]
=
0.5
-
0.5
*
WordSpace
.
playerT
ypingRate
;
WordSpace
.
GradeProb
[
1
]
=
1
-
0.5
*
WordSpace
.
playerT
ypingRate
;
WordSpace
.
GradeProb
[
2
]
=
1
-
0.15
*
WordSpace
.
playerT
ypingRate
;
}
else
if
(
p
hase
==
WordSpace
.
Phase
.
MUSIC
)
else
if
(
WordSpace
.
CurrentP
hase
==
WordSpace
.
Phase
.
MUSIC
)
{
WordSpace
.
delay
.
WordSpawn
=
1500
;
WordSpace
.
delay
.
NameSpawn
=
8000
;
WordSpace
.
NameSpawnReduce
=
400
;
WordSpace
.
GradeProb
[
0
]
=
0.2
-
0.2
*
t
ypingRate
;
WordSpace
.
GradeProb
[
1
]
=
0.8
-
0.45
*
t
ypingRate
;
WordSpace
.
GradeProb
[
2
]
=
0.9
-
0.15
*
t
ypingRate
;
WordSpace
.
GradeProb
[
0
]
=
0.2
-
0.2
*
WordSpace
.
playerT
ypingRate
;
WordSpace
.
GradeProb
[
1
]
=
0.8
-
0.45
*
WordSpace
.
playerT
ypingRate
;
WordSpace
.
GradeProb
[
2
]
=
0.9
-
0.15
*
WordSpace
.
playerT
ypingRate
;
}
WordSpace
.
wordCycle
.
resetCycle
(
ScenesData
.
gameScene
,
WordSpace
.
delay
.
WordSpawn
,
WordSpace
.
wordCycle
.
currentCycle
.
getElapsed
(),
true
);
WordSpace
.
nameCycle
.
resetCycle
(
ScenesData
.
gameScene
,
WordSpace
.
delay
.
NameSpawn
,
WordSpace
.
nameCycle
.
currentCycle
.
getElapsed
(),
true
);
...
...
@@ -530,14 +530,6 @@ WordSpace.resetGame = function()
{
WordSpace
.
generateWord
.
Name
(
ScenesData
.
gameScene
,
false
,
null
);
});
//이건 뭐지
WordSpace
.
varAdjustCycle
=
new
Cycle
(
function
()
{
//나중에는 메세지 분석해서 Phase랑 playerTypingRate 받겠지만 일단 이렇게 해둠
//WordSpace.GetPhase();
//WordSpace.GetPlayerTypingRate();
WordSpace
.
AdjustVarByPhase
(
WordSpace
.
playerTypingRate
,
WordSpace
.
CurrentPhase
);
});
// playerTypingRate 갱신용 사이클
WordSpace
.
playerTypingCycle
=
new
Cycle
(
function
()
{
...
...
server.js
View file @
acb37829
...
...
@@ -62,30 +62,45 @@ io.on('connection', function(socket)
{
try
{
socket
.
playerData
.
playingData
.
playerTyping
=
msg
.
playerTyping
;
if
(
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
.
playerTyping
<
msg
.
playerTyping
)
let
player
=
socket
.
playerData
.
playingData
;
let
room
=
socket
.
playerData
.
currentRoom
;
player
.
playerTyping
=
msg
.
playerTyping
;
if
(
room
.
maxTypingPlayer
.
playerTyping
<
msg
.
playerTyping
)
{
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
=
socket
.
playerData
.
playingData
;
room
.
maxTypingPlayer
=
player
;
}
if
(
socket
.
playerData
.
currentR
oom
.
minTypingPlayer
.
playerTyping
>
msg
.
playerTyping
)
if
(
r
oom
.
minTypingPlayer
.
playerTyping
>
msg
.
playerTyping
)
{
socket
.
playerData
.
currentRoom
.
minTypingPlayer
=
socket
.
playerData
.
playingData
;
room
.
minTypingPlayer
=
player
;
}
let
playerTypingRate
=
(
msg
.
playerTyping
-
(
socket
.
playerData
.
currentRoom
.
minTypingPlayer
.
playerTyping
-
socket
.
playerData
.
currentR
oom
.
rateArrangePoint
))
/
(
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
.
playerTyping
-
socket
.
playerData
.
currentRoom
.
minTypingPlayer
.
playerTyping
+
socket
.
playerData
.
currentR
oom
.
rateArrangePoint
*
2
);
let
playerTypingRate
=
(
msg
.
playerTyping
-
(
room
.
minTypingPlayer
.
playerTyping
-
r
oom
.
rateArrangePoint
))
/
(
room
.
maxTypingPlayer
.
playerTyping
-
room
.
minTypingPlayer
.
playerTyping
+
r
oom
.
rateArrangePoint
*
2
);
socket
.
emit
(
'
setPlayerTypingRate
'
,
playerTypingRate
);
if
(
msg
.
isWord
)
{
socket
.
playerData
.
currentRoom
.
announceToRoom
(
'
writeWord
'
,
socket
.
playerData
.
id
);
room
.
announceToRoom
(
'
writeWord
'
,
player
.
id
);
}
if
(
msg
.
isAttackMode
)
{
socket
.
playerData
.
currentRoom
.
announceToRoom
(
'
attackMode
'
,
socket
.
playerData
.
id
);
room
.
announceToRoom
(
'
attackMode
'
,
player
.
id
);
}
if
(
player
.
tabCheckTime
!=
undefined
)
{
clearTimeout
(
player
.
tabCheckTime
);
player
.
tabCheckTime
=
setTimeout
(
function
()
{
if
(
room
.
currentPhase
!=
GameServer
.
Phase
.
GAMEEND
)
player
.
defeat
();
},
1000
);
}
else
player
.
tabCheckTime
=
setTimeout
(
function
()
{
if
(
room
.
currentPhase
!=
GameServer
.
Phase
.
GAMEEND
)
player
.
defeat
();
},
1000
);
}
catch
(
e
)
{
console
.
error
(
'
[ERR] error catched on setPlayerTyping
'
);
console
.
error
(
'
[ERR] error catched on setPlayerTyping
(
'
+
e
+
'
)
'
);
socket
.
disconnect
();
}
});
...
...
@@ -106,20 +121,17 @@ io.on('connection', function(socket)
room
.
startTimer
=
setTimeout
(
function
()
{
let
deads
=
room
.
currentPlayer
.
filter
(
element
=>
!
element
.
isAlive
);
if
(
room
.
aliveCount
!=
0
)
if
(
room
.
aliveCount
!=
0
&&
room
.
currentPlayer
.
length
-
deads
.
length
>=
room
.
startCount
)
{
console
.
error
(
'
[ROOM#
'
+
room
.
roomId
+
'
] FORCE START!!!
'
);
if
(
room
.
currentPlayer
.
length
-
deads
.
length
>=
room
.
startCount
)
room
.
startRoom
();
deads
.
forEach
(
function
(
element
)
{
room
.
startRoom
();
deads
.
forEach
(
function
(
element
)
{
element
.
defeat
();
});
}
element
.
defeat
();
});
clearTimeout
(
room
.
startTimer
);
}
else
else
if
(
deads
.
length
>
0
)
{
deads
.
forEach
(
function
(
element
)
{
...
...
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