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
b54eea87
Commit
b54eea87
authored
Aug 14, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'server' into gameScene
# Conflicts: # js/FirebaseClient.js
parents
93abd960
15a3a82b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
185 additions
and
90 deletions
+185
-90
GameServer.js
GameServer.js
+69
-30
Client.js
js/Client.js
+19
-2
FirebaseClient.js
js/FirebaseClient.js
+10
-2
ScenesData.js
js/ScenesData.js
+38
-35
main.js
js/main.js
+1
-1
server.js
server.js
+48
-20
No files found.
GameServer.js
View file @
b54eea87
...
...
@@ -80,7 +80,7 @@ class GameRoom
{
this
.
roomId
=
GameServer
.
getRoomNumber
();
this
.
roomIndex
=
-
1
;
this
.
startCount
=
5
;
this
.
startCount
=
2
;
this
.
maxPlayer
=
100
;
this
.
nextRank
=
100
;
...
...
@@ -136,7 +136,7 @@ class GameRoom
{
if
(
this
.
currentPhase
===
GameServer
.
Phase
.
READY
)
{
this
.
endTime
=
Date
.
now
()
+
1
000
;
// 테스트용 10초
this
.
endTime
=
Date
.
now
()
+
5
000
;
// 테스트용 10초
this
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
true
,
endTime
:
this
.
endTime
,
playerCount
:
this
.
currentPlayer
.
length
,
...
...
@@ -172,17 +172,50 @@ class GameRoom
{
for
(
let
j
=
i
+
1
;
j
<
this
.
currentPlayer
.
length
;
j
++
)
{
this
.
currentPlayer
[
i
].
index
--
;
this
.
currentPlayer
[
j
].
index
--
;
}
this
.
aliveCount
--
;
if
(
this
.
aliveCount
<
this
.
startCount
)
{
this
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
false
,
endTime
:
0
,
playerCount
:
this
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
this
.
currentPlayer
[
i
]
});
this
.
currentPhase
=
GameServer
.
Phase
.
READY
;
this
.
refreshRoom
();
}
else
this
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
true
,
endTime
:
this
.
endTime
,
playerCount
:
this
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
this
.
currentPlayer
[
i
]
});
this
.
currentPlayer
.
splice
(
i
,
1
);
this
.
currentSocket
.
splice
(
i
,
1
);
this
.
aliveCount
--
;
return
;
}
}
console
.
log
(
'
[ERR] No player who have
'
+
playerId
);
return
;
}
refreshRoom
()
{
this
.
currentPhase
=
GameServer
.
Phase
.
READY
;
this
.
aliveCount
=
this
.
currentPlayer
.
length
;
if
(
this
.
startTimer
!=
undefined
)
{
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
'
);
}
startRoom
()
{
...
...
@@ -204,6 +237,7 @@ class GameRoom
this
.
announceToRoom
(
'
syncRoomData
'
,
toSync
);
console
.
log
(
'
[ROOM#
'
+
this
.
roomId
+
'
] Game Start with
'
+
this
.
currentPlayer
.
length
+
'
players
'
);
console
.
table
(
this
.
currentPlayer
);
this
.
announceToRoom
(
'
startGame
'
);
this
.
startTime
=
Date
.
now
();
}
...
...
@@ -269,7 +303,7 @@ class GameRoom
{
this
.
currentSocket
.
forEach
(
function
(
element
)
{
element
.
emit
(
_message
,
_data
);
if
(
element
.
playerData
.
playingData
.
isInThisRoom
)
element
.
emit
(
_message
,
_data
);
});
}
...
...
@@ -280,7 +314,7 @@ class GameRoom
return
element
.
playerData
.
id
===
targetId
;
});
//console.log('send to ' + targetSocketIndex + ', receivable? ' + this.currentSocket[targetSocketIndex].playerData.isReceivable);
if
(
this
.
currentSocket
[
targetSocketIndex
].
playerData
.
isReceivable
)
this
.
currentSocket
[
targetSocketIndex
].
emit
(
_message
,
_data
);
if
(
t
argetSocketIndex
!=
-
1
&&
t
his
.
currentSocket
[
targetSocketIndex
].
playerData
.
isReceivable
)
this
.
currentSocket
[
targetSocketIndex
].
emit
(
_message
,
_data
);
}
}
...
...
@@ -294,8 +328,9 @@ class Player
this
.
nickname
=
playerData
.
nickname
;
this
.
playerImage
=
null
;
this
.
position
=
null
;
this
.
isInThisRoom
=
true
;
this
.
isAlive
=
tru
e
;
this
.
isAlive
=
fals
e
;
this
.
rank
=
-
1
;
this
.
playerTyping
=
0
;
...
...
@@ -314,38 +349,42 @@ class Player
socket
.
playerData
.
isReceivable
=
false
;
room
.
aliveCount
--
;
room
.
checkPhase
(
Date
.
now
());
if
(
this
.
lastAttacks
.
length
>
0
)
if
(
room
.
aliveCount
>
0
)
{
this
.
lastAttack
=
this
.
lastAttacks
[
this
.
lastAttacks
.
length
-
1
]
;
if
(
Date
.
now
()
-
this
.
lastAttack
.
time
>
20000
)
this
.
lastAttack
=
null
;
else
room
.
checkPhase
(
Date
.
now
())
;
if
(
this
.
lastAttacks
.
length
>
0
)
{
this
.
lastAttacks
.
forEach
(
function
(
element
)
this
.
lastAttack
=
this
.
lastAttacks
[
this
.
lastAttacks
.
length
-
1
];
if
(
Date
.
now
()
-
this
.
lastAttack
.
time
>
20000
)
this
.
lastAttack
=
null
;
else
{
if
(
Date
.
now
()
-
element
.
time
<
20000
)
this
.
lastAttacks
.
forEach
(
function
(
element
)
{
if
(
element
.
wrongCount
>
player
.
lastAttack
.
wrongCount
)
player
.
lastAttack
=
element
;
else
if
(
element
.
wrongCount
===
player
.
lastAttack
.
wrongCount
&&
element
.
wordGrade
>
player
.
lastAttack
.
wordGrade
)
player
.
lastAttack
=
element
;
}
});
if
(
Date
.
now
()
-
element
.
time
<
20000
)
{
if
(
element
.
wrongCount
>
player
.
lastAttack
.
wrongCount
)
player
.
lastAttack
=
element
;
else
if
(
element
.
wrongCount
===
player
.
lastAttack
.
wrongCount
&&
element
.
wordGrade
>
player
.
lastAttack
.
wordGrade
)
player
.
lastAttack
=
element
;
}
});
}
}
}
room
.
announceToRoom
(
'
defeat
'
,
this
);
console
.
log
(
'
[
'
+
this
.
id
+
'
] defeated, rank:
'
+
this
.
rank
+
'
,
'
+
room
.
aliveCount
+
'
player left
'
);
room
.
announceToRoom
(
'
defeat
'
,
this
);
console
.
log
(
'
[
'
+
this
.
id
+
'
] defeated, rank:
'
+
this
.
rank
+
'
,
'
+
room
.
aliveCount
+
'
player left
'
);
if
(
socket
.
playerData
.
currentRoom
.
aliveCount
===
1
)
{
let
winner
=
room
.
currentPlayer
.
find
(
function
(
element
)
if
(
socket
.
playerData
.
currentRoom
.
aliveCount
===
1
)
{
return
element
.
isAlive
;
});
room
.
announceToRoom
(
'
gameEnd
'
,
winner
);
room
.
announceToTarget
(
winner
.
id
,
'
alert
'
,
'
gameWin
'
);
console
.
log
(
'
[
'
+
winner
.
id
+
'
]
'
+
'
winner!
'
+
winner
.
nickname
);
let
winner
=
room
.
currentPlayer
.
find
(
function
(
element
)
{
return
element
.
isAlive
;
});
room
.
announceToRoom
(
'
gameEnd
'
,
winner
);
room
.
announceToTarget
(
winner
.
id
,
'
alert
'
,
'
gameWin
'
);
console
.
log
(
'
[
'
+
winner
.
id
+
'
]
'
+
'
winner!
'
+
winner
.
nickname
);
}
}
this
.
isInThisRoom
=
false
;
}
}
...
...
js/Client.js
View file @
b54eea87
...
...
@@ -41,6 +41,11 @@ socket.on('enterRoom', function()
fbClient
.
updateUserData
(
'
recentHopae
'
,
PlayerData
.
currentHopae
);
Audio
.
killSound
(
ScenesData
.
menuScene
,
'
login
'
);
ScenesData
.
changeScene
(
'
roomScene
'
);
if
(
ScenesData
.
endCountTimer
!=
undefined
)
{
clearTimeout
(
ScenesData
.
endCountTimer
);
ScenesData
.
endCountTimer
=
undefined
;
}
});
socket
.
on
(
'
syncRoomScene
'
,
function
(
msg
)
{
...
...
@@ -190,8 +195,6 @@ socket.on('defeat', function(msg) // object player
RoomData
.
players
[
msg
.
index
].
nicknameText
=
nicknameText
;
RoomData
.
aliveCount
--
;
console
.
log
(
msg
.
id
);
console
.
log
(
RoomData
.
findPlayer
(
msg
.
id
));
RoomData
.
findPlayer
(
msg
.
id
).
playerImage
.
play
(
WordSpace
.
pyeongminAnims
[
Enums
.
characterAnim
.
gameOver
]);
if
(
msg
.
lastAttack
!=
null
)
{
...
...
@@ -239,11 +242,25 @@ socket.on('defeat', function(msg) // object player
console
.
log
(
RoomData
.
findPlayer
(
msg
.
id
).
nickname
+
'
defeated
'
);
WordSpace
.
killLogForTest
+=
(
'
\n
--Suicide->
'
+
RoomData
.
findPlayer
(
msg
.
id
).
nickname
);
}
if
(
msg
.
id
==
RoomData
.
myself
.
id
)
{
setTimeout
(()
=>
{
socket
.
emit
(
'
defeat
'
);
ScenesData
.
changeScene
(
'
menuScene
'
);
},
2000
);
}
});
socket
.
on
(
'
gameEnd
'
,
function
(
msg
)
// object player
{
console
.
log
(
msg
.
nickname
+
'
Win!!!!!!
'
);
if
(
msg
.
id
==
RoomData
.
myself
.
id
)
{
setTimeout
(()
=>
{
ScenesData
.
changeScene
(
'
menuScene
'
);
},
2000
);
}
});
socket
.
on
(
'
attackSucceed
'
,
function
(
msg
)
{
//console.log('client');
...
...
js/FirebaseClient.js
View file @
b54eea87
...
...
@@ -70,7 +70,7 @@ FirebaseClient.prototype.setLogin = function()
.
then
(
function
()
{
game
=
new
Phaser
.
Game
(
config
);
this
.
isGameStarted
=
true
;
fbClient
.
isGameStarted
=
true
;
});
document
.
getElementById
(
'
mainTitle
'
).
style
.
display
=
'
none
'
;
...
...
@@ -79,7 +79,10 @@ FirebaseClient.prototype.setLogin = function()
FirebaseClient
.
prototype
.
setLogOut
=
function
()
{
if
(
game
!=
null
)
game
.
destroy
(
true
);
this
.
isGameStarted
=
false
;
document
.
getElementById
(
'
mainTitle
'
).
style
.
display
=
'
block
'
;
document
.
getElementById
(
'
titleImg
'
).
style
.
display
=
'
block
'
;
}
FirebaseClient
.
prototype
.
onEmailBtnClick
=
function
()
...
...
@@ -248,6 +251,11 @@ document.addEventListener('DOMContentLoaded', function()
console
.
log
(
'
done load
'
);
});
document
.
onkeydown
=
function
(
e
)
{
if
(
fbClient
.
isGameStarted
&&
e
.
keyCode
===
27
)
fbClient
.
logOut
();
}
class
UserData
{
constructor
()
...
...
js/ScenesData.js
View file @
b54eea87
...
...
@@ -344,16 +344,15 @@ var roomScene = new Phaser.Class(
{
this
.
peopleText
.
setText
(
this
.
peopleCount
+
'
/ 10
'
);
if
(
this
.
isCounting
)
if
(
this
.
isCounting
&&
!
this
.
isCountEnd
)
{
this
.
countText
.
setText
(((
this
.
endTime
-
Date
.
now
())
/
1000
).
toFixed
(
1
));
if
(
this
.
endTime
<
Date
.
now
())
if
(
this
.
endTime
!=
0
&&
this
.
endTime
<
Date
.
now
())
{
//console.log('end Count');
setTimeout
(()
=>
{
ScenesData
.
endCountTimer
=
setTimeout
(()
=>
{
socket
.
emit
(
'
endCount
'
);
},
(
Phaser
.
Math
.
Distance
.
Between
(
0
,
0
,
game
.
config
.
width
/
2
,
game
.
config
.
height
*
10
/
9
)
*
10
));
this
.
isCounting
=
false
;
},
(
Phaser
.
Math
.
Distance
.
Between
(
0
,
0
,
game
.
config
.
width
/
2
,
game
.
config
.
height
*
10
/
9
)
*
3
));
this
.
isCountEnd
=
true
;
this
.
players
.
forEach
(
function
(
element
){
element
.
follower
=
{
t
:
0
,
vec
:
new
Phaser
.
Math
.
Vector2
()
};
...
...
@@ -373,12 +372,21 @@ var roomScene = new Phaser.Class(
}
else
if
(
this
.
isCountEnd
)
{
this
.
players
.
forEach
(
function
(
element
){
element
.
path
.
getPoint
(
element
.
follower
.
t
,
element
.
follower
.
vec
);
element
.
sprite
.
setPosition
(
element
.
follower
.
vec
.
x
,
element
.
follower
.
vec
.
y
);
element
.
nickname
.
setPosition
(
element
.
sprite
.
x
-
game
.
config
.
width
/
128
,
element
.
sprite
.
y
-
game
.
config
.
height
/
12
);
});
this
.
countText
.
setText
(
'
잠시만 기다려주세요...
'
);
if
(
this
.
isCounting
)
{
this
.
players
.
forEach
(
function
(
element
){
element
.
path
.
getPoint
(
element
.
follower
.
t
,
element
.
follower
.
vec
);
element
.
sprite
.
setPosition
(
element
.
follower
.
vec
.
x
,
element
.
follower
.
vec
.
y
);
element
.
nickname
.
setPosition
(
element
.
sprite
.
x
-
game
.
config
.
width
/
128
,
element
.
sprite
.
y
-
game
.
config
.
height
/
12
);
});
this
.
countText
.
setText
(
'
잠시만 기다려주세요...
'
);
}
else
{
this
.
countText
.
setText
(
'
이동 도중 사람이 퇴실했습니다...
\n
잠시만 기다려주세요...
'
);
clearTimeout
(
ScenesData
.
endCountTimer
);
ScenesData
.
endCountTimer
=
undefined
;
}
}
else
{
...
...
@@ -437,8 +445,7 @@ var gameScene = new Phaser.Class(
WordSpace
.
startCycle
(
this
);
WordSpace
.
setPlayerTyping
.
initiate
(
this
);
WordSpace
.
nameWordTextForTest
=
this
.
add
.
text
(
50
,
400
,
'
현재 가진 호패들 : 없음
'
).
setDepth
(
10
).
setColor
(
'
#000000
'
);
WordSpace
.
nameQueue
.
initiate
();
//WordSpace.attackGauge.add(11);
...
...
@@ -446,29 +453,25 @@ var gameScene = new Phaser.Class(
update
:
function
()
{
WordSpace
.
deltaTime
=
this
.
sys
.
game
.
loop
.
delta
;
WordSpace
.
wordForcedGroup
.
forEach
(
function
(
element
)
{
element
.
attract
();
});
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
if
(
ScenesData
.
currentScene
==
ScenesData
.
gameScene
)
{
element
.
attract
();
})
WordSpace
.
attackPaperGroup
.
forEach
(
function
(
element
){
element
.
moveObject
(
element
);
});
let
tempNames
=
''
;
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
//테스트용
tempNames
+=
element
.
wordText
+
(
element
.
isStrong
?
'
[강]
'
:
''
)
+
'
\n
'
;
});
WordSpace
.
nameWordTextForTest
.
setText
(
'
현재 가진 호패들 :
\n
'
+
tempNames
);
WordSpace
.
weightTextObjForTest
.
setText
(
'
뇌의 무게: (현재)
'
+
WordSpace
.
totalWeight
+
'
/
'
+
WordSpace
.
brainCapacity
+
'
(전체)
'
);
WordSpace
.
killLogTextForTest
.
setText
(
WordSpace
.
killLogForTest
);
WordSpace
.
setPlayerTyping
.
add
(
''
);
WordSpace
.
deltaTime
=
this
.
sys
.
game
.
loop
.
delta
;
WordSpace
.
wordForcedGroup
.
forEach
(
function
(
element
)
{
element
.
attract
();
});
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
element
.
attract
();
})
WordSpace
.
attackPaperGroup
.
forEach
(
function
(
element
){
element
.
moveObject
(
element
);
});
WordSpace
.
weightTextObjForTest
.
setText
(
'
뇌의 무게: (현재)
'
+
WordSpace
.
totalWeight
+
'
/
'
+
WordSpace
.
brainCapacity
+
'
(전체)
'
);
WordSpace
.
killLogTextForTest
.
setText
(
WordSpace
.
killLogForTest
);
WordSpace
.
setPlayerTyping
.
add
(
''
);
}
}
});
...
...
js/main.js
View file @
b54eea87
var
config
=
{
type
:
Phaser
.
AUTO
,
type
:
Phaser
.
CANVAS
,
width
:
1920
,
height
:
1080
,
scale
:
{
...
...
server.js
View file @
b54eea87
...
...
@@ -16,7 +16,7 @@ app.get('/', function(req, res) {
server
.
listen
(
80
,
function
()
{
console
.
log
(
'
[SERVER] Listening on port
'
+
server
.
address
().
port
);
GameServer
.
serverNumber
=
Math
.
floor
(
Math
.
random
()
*
1000
+
1
);
console
.
log
(
'
[SERVER] server number is
${GameServer.serverNumber}
'
);
console
.
log
(
'
[SERVER] server number is
'
+
GameServer
.
serverNumber
);
});
...
...
@@ -89,15 +89,51 @@ io.on('connection', function(socket)
socket
.
playerData
.
currentRoom
.
announceToRoom
(
'
attackMode
'
,
socket
.
playerData
.
id
);
}
}
catch
(
e
)
{
console
.
error
(
'
[ERR] error catched on setPlayerTyping
'
)}
catch
(
e
)
{
console
.
error
(
'
[ERR] error catched on setPlayerTyping
'
);
socket
.
disconnect
();
}
});
socket
.
on
(
'
endCount
'
,
function
()
{
socket
.
playerData
.
currentRoom
.
aliveCount
--
;
if
(
socket
.
playerData
.
currentRoom
.
aliveCount
===
0
)
//console.log('counted, ' + socket.playerData.currentRoom.aliveCount);
socket
.
playerData
.
playingData
.
isAlive
=
true
;
if
(
socket
.
playerData
.
currentRoom
.
aliveCount
===
0
&&
socket
.
playerData
.
currentRoom
.
currentPlayer
.
length
>=
socket
.
playerData
.
currentRoom
.
startCount
)
{
socket
.
playerData
.
currentRoom
.
startRoom
();
clearTimeout
(
socket
.
playerData
.
currentRoom
.
startTimer
);
}
if
(
socket
.
playerData
.
currentRoom
.
startTimer
===
undefined
)
{
const
room
=
socket
.
playerData
.
currentRoom
;
room
.
startTimer
=
setTimeout
(
function
()
{
let
deads
=
room
.
currentPlayer
.
filter
(
element
=>
!
element
.
isAlive
);
if
(
room
.
aliveCount
!=
0
)
{
console
.
error
(
'
[ROOM#
'
+
room
.
roomId
+
'
] FORCE START!!!
'
);
if
(
room
.
currentPlayer
.
length
-
deads
.
length
>=
room
.
startCount
)
{
room
.
startRoom
();
deads
.
forEach
(
function
(
element
)
{
element
.
defeat
();
});
}
clearTimeout
(
room
.
startTimer
);
}
else
{
deads
.
forEach
(
function
(
element
)
{
room
.
currentSocket
[
element
.
index
].
disconnect
();
room
.
exitRoom
(
element
.
id
);
});
room
.
refreshRoom
();
}
},
2000
);
}
});
...
...
@@ -148,18 +184,24 @@ io.on('connection', function(socket)
{
GameServer
.
disconnectCount
++
;
let
data
=
socket
.
playerData
;
if
(
typeof
data
===
undefined
)
if
(
data
===
undefined
)
{
console
.
error
(
'
[ERROR] data is undefined
'
);
console
.
table
(
GameServer
.
currentPlayer
);
GameServer
.
disconnectCount
--
;
}
else
// data.id is not undefined
{
disconnectUser
(
data
,
reason
);
}
const
connectDiff
=
GameServer
.
connectCount
-
GameServer
.
disconnectCount
;
const
playerCount
=
GameServer
.
currentPlayer
.
length
console
.
log
({
connectDiff
,
playerCount
});
const
playerCount
=
GameServer
.
currentPlayer
.
length
;
if
(
connectDiff
!=
playerCount
)
{
console
.
log
({
connectDiff
,
playerCount
});
console
.
table
(
GameServer
.
currentPlayer
);
}
socket
.
disconnect
();
});
});
...
...
@@ -178,20 +220,6 @@ var disconnectUser = function(data, reason)
if
(
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
READY
||
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
COUNT
)
{
data
.
currentRoom
.
exitRoom
(
data
.
id
);
if
(
data
.
currentRoom
.
aliveCount
<
data
.
currentRoom
.
startCount
)
{
data
.
currentRoom
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
false
,
endTime
:
0
,
playerCount
:
data
.
currentRoom
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
data
.
playingData
});
data
.
currentRoom
.
currentPhase
=
GameServer
.
Phase
.
READY
;
}
else
data
.
currentRoom
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
true
,
endTime
:
data
.
currentRoom
.
endTime
,
playerCount
:
data
.
currentRoom
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
data
.
playingData
});
}
else
if
(
data
.
playingData
.
isAlive
)
{
...
...
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