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
7f8ade81
Commit
7f8ade81
authored
Aug 15, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gameScene'
parents
9c3f21f8
6e58f527
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
369 additions
and
145 deletions
+369
-145
GameServer.js
GameServer.js
+79
-31
Client.js
js/Client.js
+103
-8
FirebaseClient.js
js/FirebaseClient.js
+24
-3
GameCycle.js
js/GameCycle.js
+1
-30
ScenesData.js
js/ScenesData.js
+40
-36
WordObject.js
js/WordObject.js
+2
-0
WordSpace.js
js/WordSpace.js
+64
-4
main.js
js/main.js
+1
-1
server.js
server.js
+55
-32
No files found.
GameServer.js
View file @
7f8ade81
...
@@ -35,7 +35,9 @@ GameServer.enterEmptyRoom = function(playerSocket)
...
@@ -35,7 +35,9 @@ GameServer.enterEmptyRoom = function(playerSocket)
let
emptyRoomIndex
=
-
1
;
let
emptyRoomIndex
=
-
1
;
for
(
let
i
=
0
;
i
<
this
.
playingRoom
.
length
;
i
++
)
for
(
let
i
=
0
;
i
<
this
.
playingRoom
.
length
;
i
++
)
{
{
if
((
this
.
playingRoom
[
i
].
currentPhase
===
this
.
Phase
.
READY
||
this
.
playingRoom
[
i
].
currentPhase
===
this
.
Phase
.
COUNT
)
&&
this
.
playingRoom
[
i
].
maxPlayer
>
this
.
playingRoom
[
i
].
currentPlayer
.
length
)
if
((
this
.
playingRoom
[
i
].
currentPhase
===
this
.
Phase
.
READY
||
this
.
playingRoom
[
i
].
currentPhase
===
this
.
Phase
.
COUNT
)
&&
this
.
playingRoom
[
i
].
maxPlayer
>
this
.
playingRoom
[
i
].
currentPlayer
.
length
&&
this
.
playingRoom
[
i
].
checkHopae
(
playerSocket
.
playerData
.
nickname
))
{
{
emptyRoomIndex
=
i
;
emptyRoomIndex
=
i
;
break
;
break
;
...
@@ -80,7 +82,7 @@ class GameRoom
...
@@ -80,7 +82,7 @@ class GameRoom
{
{
this
.
roomId
=
GameServer
.
getRoomNumber
();
this
.
roomId
=
GameServer
.
getRoomNumber
();
this
.
roomIndex
=
-
1
;
this
.
roomIndex
=
-
1
;
this
.
startCount
=
5
;
this
.
startCount
=
2
;
this
.
maxPlayer
=
100
;
this
.
maxPlayer
=
100
;
this
.
nextRank
=
100
;
this
.
nextRank
=
100
;
...
@@ -116,6 +118,11 @@ class GameRoom
...
@@ -116,6 +118,11 @@ class GameRoom
console
.
log
(
'
[LOG] new room #
'
+
this
.
roomId
+
'
made, roomCount:
'
+
GameServer
.
playingRoom
.
length
);
console
.
log
(
'
[LOG] new room #
'
+
this
.
roomId
+
'
made, roomCount:
'
+
GameServer
.
playingRoom
.
length
);
}
}
checkHopae
(
newHopae
)
{
return
!
this
.
currentPlayer
.
includes
((
element
)
=>
element
.
nickname
===
newHopae
);
}
enterRoom
(
playerSocket
)
enterRoom
(
playerSocket
)
{
{
let
playerInst
=
new
Player
(
this
,
playerSocket
.
playerData
);
let
playerInst
=
new
Player
(
this
,
playerSocket
.
playerData
);
...
@@ -136,7 +143,7 @@ class GameRoom
...
@@ -136,7 +143,7 @@ class GameRoom
{
{
if
(
this
.
currentPhase
===
GameServer
.
Phase
.
READY
)
if
(
this
.
currentPhase
===
GameServer
.
Phase
.
READY
)
{
{
this
.
endTime
=
Date
.
now
()
+
1
000
;
// 테스트용 10초
this
.
endTime
=
Date
.
now
()
+
5
000
;
// 테스트용 10초
this
.
announceToRoom
(
'
setRoomCount
'
,
this
.
announceToRoom
(
'
setRoomCount
'
,
{
{
isEnable
:
true
,
endTime
:
this
.
endTime
,
playerCount
:
this
.
currentPlayer
.
length
,
isEnable
:
true
,
endTime
:
this
.
endTime
,
playerCount
:
this
.
currentPlayer
.
length
,
...
@@ -172,17 +179,50 @@ class GameRoom
...
@@ -172,17 +179,50 @@ class GameRoom
{
{
for
(
let
j
=
i
+
1
;
j
<
this
.
currentPlayer
.
length
;
j
++
)
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
.
currentPlayer
.
splice
(
i
,
1
);
this
.
currentSocket
.
splice
(
i
,
1
);
this
.
currentSocket
.
splice
(
i
,
1
);
this
.
aliveCount
--
;
return
;
return
;
}
}
}
}
console
.
log
(
'
[ERR] No player who have
'
+
playerId
);
console
.
log
(
'
[ERR] No player who have
'
+
playerId
);
return
;
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
()
startRoom
()
{
{
...
@@ -204,6 +244,7 @@ class GameRoom
...
@@ -204,6 +244,7 @@ class GameRoom
this
.
announceToRoom
(
'
syncRoomData
'
,
toSync
);
this
.
announceToRoom
(
'
syncRoomData
'
,
toSync
);
console
.
log
(
'
[ROOM#
'
+
this
.
roomId
+
'
] Game Start with
'
+
this
.
currentPlayer
.
length
+
'
players
'
);
console
.
log
(
'
[ROOM#
'
+
this
.
roomId
+
'
] Game Start with
'
+
this
.
currentPlayer
.
length
+
'
players
'
);
console
.
table
(
this
.
currentPlayer
);
this
.
announceToRoom
(
'
startGame
'
);
this
.
announceToRoom
(
'
startGame
'
);
this
.
startTime
=
Date
.
now
();
this
.
startTime
=
Date
.
now
();
}
}
...
@@ -269,7 +310,7 @@ class GameRoom
...
@@ -269,7 +310,7 @@ class GameRoom
{
{
this
.
currentSocket
.
forEach
(
function
(
element
)
this
.
currentSocket
.
forEach
(
function
(
element
)
{
{
element
.
emit
(
_message
,
_data
);
if
(
element
.
playerData
.
playingData
.
isInThisRoom
)
element
.
emit
(
_message
,
_data
);
});
});
}
}
...
@@ -280,7 +321,7 @@ class GameRoom
...
@@ -280,7 +321,7 @@ class GameRoom
return
element
.
playerData
.
id
===
targetId
;
return
element
.
playerData
.
id
===
targetId
;
});
});
//console.log('send to ' + targetSocketIndex + ', receivable? ' + this.currentSocket[targetSocketIndex].playerData.isReceivable);
//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 +335,12 @@ class Player
...
@@ -294,8 +335,12 @@ class Player
this
.
nickname
=
playerData
.
nickname
;
this
.
nickname
=
playerData
.
nickname
;
this
.
playerImage
=
null
;
this
.
playerImage
=
null
;
this
.
position
=
null
;
this
.
position
=
null
;
this
.
killCount
=
0
;
this
.
earnedStrongHopae
=
0
;
this
.
attackSucceed
=
0
;
this
.
isAlive
=
true
;
this
.
isAlive
=
false
;
this
.
isInThisRoom
=
true
;
this
.
rank
=
-
1
;
this
.
rank
=
-
1
;
this
.
playerTyping
=
0
;
this
.
playerTyping
=
0
;
...
@@ -314,37 +359,40 @@ class Player
...
@@ -314,37 +359,40 @@ class Player
socket
.
playerData
.
isReceivable
=
false
;
socket
.
playerData
.
isReceivable
=
false
;
room
.
aliveCount
--
;
room
.
aliveCount
--
;
room
.
checkPhase
(
Date
.
now
());
if
(
room
.
aliveCount
>
0
)
if
(
this
.
lastAttacks
.
length
>
0
)
{
{
this
.
lastAttack
=
this
.
lastAttacks
[
this
.
lastAttacks
.
length
-
1
]
;
room
.
checkPhase
(
Date
.
now
())
;
if
(
Date
.
now
()
-
this
.
lastAttack
.
time
>
20000
)
this
.
lastAttack
=
null
;
else
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
;
if
(
Date
.
now
()
-
element
.
time
<
20000
)
else
if
(
element
.
wrongCount
===
player
.
lastAttack
.
wrongCount
&&
element
.
wordGrade
>
player
.
lastAttack
.
wordGrade
)
player
.
lastAttack
=
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
;
}
});
}
}
}
}
room
.
announceToRoom
(
'
defeat
'
,
this
);
room
.
announceToRoom
(
'
defeat
'
,
this
);
console
.
log
(
'
[
'
+
this
.
id
+
'
] defeated, rank:
'
+
this
.
rank
+
'
,
'
+
room
.
aliveCount
+
'
player left
'
);
console
.
log
(
'
[
'
+
this
.
id
+
'
] defeated, rank:
'
+
this
.
rank
+
'
,
'
+
room
.
aliveCount
+
'
player left
'
);
if
(
socket
.
playerData
.
currentRoom
.
aliveCount
===
1
)
if
(
socket
.
playerData
.
currentRoom
.
aliveCount
===
1
)
{
let
winner
=
room
.
currentPlayer
.
find
(
function
(
element
)
{
{
return
element
.
isAlive
;
let
winner
=
room
.
currentPlayer
.
find
(
function
(
element
)
});
{
room
.
announceToRoom
(
'
gameEnd
'
,
winner
);
return
element
.
isAlive
;
room
.
announceToTarget
(
winner
.
id
,
'
alert
'
,
'
gameWin
'
);
});
console
.
log
(
'
[
'
+
winner
.
id
+
'
]
'
+
'
winner!
'
+
winner
.
nickname
);
room
.
announceToRoom
(
'
gameEnd
'
,
winner
);
room
.
announceToTarget
(
winner
.
id
,
'
alert
'
,
'
gameWin
'
);
console
.
log
(
'
[
'
+
winner
.
id
+
'
]
'
+
'
winner!
'
+
winner
.
nickname
);
}
}
}
}
}
}
}
...
...
js/Client.js
View file @
7f8ade81
...
@@ -41,6 +41,11 @@ socket.on('enterRoom', function()
...
@@ -41,6 +41,11 @@ socket.on('enterRoom', function()
fbClient
.
updateUserData
(
'
recentHopae
'
,
PlayerData
.
currentHopae
);
fbClient
.
updateUserData
(
'
recentHopae
'
,
PlayerData
.
currentHopae
);
Audio
.
killSound
(
ScenesData
.
menuScene
,
'
login
'
);
Audio
.
killSound
(
ScenesData
.
menuScene
,
'
login
'
);
ScenesData
.
changeScene
(
'
roomScene
'
);
ScenesData
.
changeScene
(
'
roomScene
'
);
if
(
ScenesData
.
endCountTimer
!=
undefined
)
{
clearTimeout
(
ScenesData
.
endCountTimer
);
ScenesData
.
endCountTimer
=
undefined
;
}
});
});
socket
.
on
(
'
syncRoomScene
'
,
function
(
msg
)
socket
.
on
(
'
syncRoomScene
'
,
function
(
msg
)
{
{
...
@@ -162,7 +167,6 @@ socket.on('someoneAttacked', function(msg) // {Id attackerId, Id victimId}
...
@@ -162,7 +167,6 @@ socket.on('someoneAttacked', function(msg) // {Id attackerId, Id victimId}
});
});
socket
.
on
(
'
attacked
'
,
function
(
msg
)
// object attackData
socket
.
on
(
'
attacked
'
,
function
(
msg
)
// object attackData
{
{
//console.log('attacked by ' + msg.attacker.nickname);
let
attackedEvent
=
new
Cycle
(
function
()
let
attackedEvent
=
new
Cycle
(
function
()
{
{
if
(
!
WordSpace
.
isInvincible
)
if
(
!
WordSpace
.
isInvincible
)
...
@@ -190,8 +194,6 @@ socket.on('defeat', function(msg) // object player
...
@@ -190,8 +194,6 @@ socket.on('defeat', function(msg) // object player
RoomData
.
players
[
msg
.
index
].
nicknameText
=
nicknameText
;
RoomData
.
players
[
msg
.
index
].
nicknameText
=
nicknameText
;
RoomData
.
aliveCount
--
;
RoomData
.
aliveCount
--
;
console
.
log
(
msg
.
id
);
console
.
log
(
RoomData
.
findPlayer
(
msg
.
id
));
RoomData
.
findPlayer
(
msg
.
id
).
playerImage
.
play
(
WordSpace
.
pyeongminAnims
[
Enums
.
characterAnim
.
gameOver
]);
RoomData
.
findPlayer
(
msg
.
id
).
playerImage
.
play
(
WordSpace
.
pyeongminAnims
[
Enums
.
characterAnim
.
gameOver
]);
if
(
msg
.
lastAttack
!=
null
)
if
(
msg
.
lastAttack
!=
null
)
{
{
...
@@ -212,8 +214,6 @@ socket.on('defeat', function(msg) // object player
...
@@ -212,8 +214,6 @@ socket.on('defeat', function(msg) // object player
repeat
:
0
,
// -1: infinity
repeat
:
0
,
// -1: infinity
yoyo
:
false
,
yoyo
:
false
,
onComplete
:
function
()
{
onComplete
:
function
()
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
ScenesData
.
gameScene
.
tweens
.
add
({
ScenesData
.
gameScene
.
tweens
.
add
({
targets
:
itemBag
,
targets
:
itemBag
,
...
@@ -224,14 +224,13 @@ socket.on('defeat', function(msg) // object player
...
@@ -224,14 +224,13 @@ socket.on('defeat', function(msg) // object player
repeat
:
0
,
// -1: infinity
repeat
:
0
,
// -1: infinity
yoyo
:
false
});
yoyo
:
false
});
},
1500
);
},
1500
);
},
},
onCompleteScope
:
ScenesData
.
gameScene
onCompleteScope
:
ScenesData
.
gameScene
});
});
setTimeout
(
function
()
{
setTimeout
(
function
()
{
itemBag
.
destroy
();
itemBag
.
destroy
();
},
3000
);
},
3000
);
RoomData
.
myself
.
killCount
++
;
}
}
}
}
else
else
...
@@ -239,11 +238,21 @@ socket.on('defeat', function(msg) // object player
...
@@ -239,11 +238,21 @@ socket.on('defeat', function(msg) // object player
console
.
log
(
RoomData
.
findPlayer
(
msg
.
id
).
nickname
+
'
defeated
'
);
console
.
log
(
RoomData
.
findPlayer
(
msg
.
id
).
nickname
+
'
defeated
'
);
WordSpace
.
killLogForTest
+=
(
'
\n
--Suicide->
'
+
RoomData
.
findPlayer
(
msg
.
id
).
nickname
);
WordSpace
.
killLogForTest
+=
(
'
\n
--Suicide->
'
+
RoomData
.
findPlayer
(
msg
.
id
).
nickname
);
}
}
if
(
msg
.
id
==
RoomData
.
myself
.
id
)
{
RoomData
.
myself
=
RoomData
.
players
[
msg
.
index
];
backToMenu
(
false
);
}
});
});
socket
.
on
(
'
gameEnd
'
,
function
(
msg
)
// object player
socket
.
on
(
'
gameEnd
'
,
function
(
msg
)
// object player
{
{
console
.
log
(
msg
.
nickname
+
'
Win!!!!!!
'
);
console
.
log
(
msg
.
nickname
+
'
Win!!!!!!
'
);
if
(
msg
.
id
==
RoomData
.
myself
.
id
)
{
backToMenu
(
true
);
}
});
});
socket
.
on
(
'
attackSucceed
'
,
function
(
msg
)
socket
.
on
(
'
attackSucceed
'
,
function
(
msg
)
{
{
//console.log('client');
//console.log('client');
...
@@ -252,6 +261,7 @@ socket.on('attackSucceed', function(msg)
...
@@ -252,6 +261,7 @@ socket.on('attackSucceed', function(msg)
tempWord
.
physicsObj
.
setPosition
(
victimPos
.
x
,
victimPos
.
y
);
tempWord
.
physicsObj
.
setPosition
(
victimPos
.
x
,
victimPos
.
y
);
tempWord
.
wordObj
.
setPosition
(
tempWord
.
physicsObj
.
x
,
tempWord
.
physicsObj
.
y
);
tempWord
.
wordObj
.
setPosition
(
tempWord
.
physicsObj
.
x
,
tempWord
.
physicsObj
.
y
);
tempWord
.
destroy
();
tempWord
.
destroy
();
RoomData
.
myself
.
attackSucceed
+=
1
;
});
});
// out game
// out game
...
@@ -260,4 +270,89 @@ socket.on('userDisconnect', function(msg) // {num index , num id, str nickname}
...
@@ -260,4 +270,89 @@ socket.on('userDisconnect', function(msg) // {num index , num id, str nickname}
//console.log(msg.index + ' / ' + msg.id + ' / ' + msg.nickname + ' disconnected');
//console.log(msg.index + ' / ' + msg.id + ' / ' + msg.nickname + ' disconnected');
RoomData
.
players
[
msg
.
index
]
=
msg
;
RoomData
.
players
[
msg
.
index
]
=
msg
;
RoomData
.
aliveCount
--
;
RoomData
.
aliveCount
--
;
});
});
\ No newline at end of file
var
backToMenu
=
function
(
isWin
)
{
let
earnedMoney
=
0
;
if
(
isWin
)
earnedMoney
+=
20
;
earnedMoney
+=
RoomData
.
myself
.
killCount
*
3
;
earnedMoney
+=
parseInt
(
WordSpace
.
playerTypingRate
/
10
);
earnedMoney
+=
Math
.
max
(
20
,
Math
.
pow
(
RoomData
.
myself
.
attackSucceed
,
2
));
earnedMoney
+=
parseInt
(
20
*
(
1
-
(
RoomData
.
myself
.
rank
-
1
)
/
(
RoomData
.
players
.
length
-
1
)));
var
temp
=
function
(){
socket
.
emit
(
'
exitFromRoom
'
,
RoomData
.
myself
.
id
);
fbClient
.
updateUserData
(
'
killCount
'
,
RoomData
.
myself
.
killCount
);
fbClient
.
updateUserData
(
'
money
'
,
earnedMoney
);
ScenesData
.
changeScene
(
'
menuScene
'
);
}
ScenesData
.
gameScene
.
backToMenuDialog
=
ScenesData
.
gameScene
.
rexUI
.
add
.
dialog
({
x
:
game
.
config
.
width
/
2
,
y
:
game
.
config
.
height
/
2
,
background
:
ScenesData
.
gameScene
.
add
.
sprite
(
game
.
config
.
width
/
2
,
game
.
config
.
height
/
2
,
'
panel
'
).
setOrigin
(
0.5
,
0.5
),
content
:
ScenesData
.
gameScene
.
rexUI
.
add
.
dialog
({
x
:
game
.
config
.
width
/
2
,
y
:
game
.
config
.
height
/
2
,
choices
:
[
UIObject
.
createLabel
(
ScenesData
.
gameScene
,
game
.
config
.
width
/
2
-
100
,
game
.
config
.
height
/
2
-
100
,
0
,
'
playerStand
'
,
0.7
,
'
center
'
),
UIObject
.
createLabel
(
ScenesData
.
gameScene
,
game
.
config
.
width
/
2
+
120
,
game
.
config
.
height
/
2
-
150
,
0
,
'
button
'
,
1
,
'
center
'
,
'
등수 :
'
+
RoomData
.
myself
.
rank
+
'
등
'
,
30
).
layout
(),
UIObject
.
createLabel
(
ScenesData
.
gameScene
,
game
.
config
.
width
/
2
+
120
,
game
.
config
.
height
/
2
-
50
,
0
,
'
button
'
,
1
,
'
center
'
,
'
킬 수 :
'
+
RoomData
.
myself
.
killCount
+
'
킬
'
,
30
).
layout
(),
UIObject
.
createLabel
(
ScenesData
.
gameScene
,
game
.
config
.
width
/
2
+
120
,
game
.
config
.
height
/
2
+
50
,
0
,
'
button
'
,
1
,
'
center
'
,
'
획득 강호패 :
'
+
RoomData
.
myself
.
earnedStrongHopae
+
'
개
'
,
30
).
layout
(),
UIObject
.
createLabel
(
ScenesData
.
gameScene
,
game
.
config
.
width
/
2
+
120
,
game
.
config
.
height
/
2
+
150
,
0
,
'
button
'
,
1
,
'
center
'
,
'
획득 골드 :
'
+
earnedMoney
+
'
원
'
,
30
).
layout
()
],
align
:
{
choices
:
'
center
'
// 'center'|'left'|'right'
}
}),
actions
:
[
UIObject
.
createLabel
(
ScenesData
.
gameScene
,
game
.
config
.
width
/
2
-
120
,
game
.
config
.
height
/
2
+
300
,
10
,
'
button
'
,
1
,
'
center
'
,
'
나가기
'
).
layout
(),
UIObject
.
createLabel
(
ScenesData
.
gameScene
,
game
.
config
.
width
/
2
+
120
,
game
.
config
.
height
/
2
+
300
,
10
,
'
button
'
,
1
,
'
center
'
,
'
관전하기
'
).
layout
()
],
space
:
{
action
:
10
,
left
:
20
,
right
:
20
,
top
:
20
,
bottom
:
20
,
},
align
:
{
actions
:
'
center
'
// 'center'|'left'|'right'
}
}).
setDepth
(
10
);
ScenesData
.
gameScene
.
backToMenuDialog
.
on
(
'
button.click
'
,
function
(
button
,
groupName
,
index
)
{
if
(
index
==
0
)
{
temp
();
}
else
{
ScenesData
.
gameScene
.
backToMenuDialog
.
setVisible
(
false
);
ScenesData
.
gameScene
.
backToMenuBtn
=
UIObject
.
createButton
(
ScenesData
.
gameScene
,
UIObject
.
createLabel
(
ScenesData
.
gameScene
,
100
,
900
,
5
,
'
pyeongminThrow
'
,
0.5
,
'
center
'
),
1
,
0
,
2
,
function
()
{
temp
();
});
}
},
ScenesData
.
gameScene
)
.
on
(
'
button.over
'
,
function
(
button
,
groupName
,
index
)
{
//console.log('button over');
})
.
on
(
'
button.out
'
,
function
(
button
,
groupName
,
index
)
{
//console.log('button out');
});
}
\ No newline at end of file
js/FirebaseClient.js
View file @
7f8ade81
function
FirebaseClient
()
function
FirebaseClient
()
{
{
this
.
init
();
this
.
init
();
this
.
initEvent
();
this
.
initEvent
();
this
.
isGameStarted
=
false
;
}
}
FirebaseClient
.
prototype
.
init
=
function
()
FirebaseClient
.
prototype
.
init
=
function
()
...
@@ -69,6 +70,7 @@ FirebaseClient.prototype.setLogin = function()
...
@@ -69,6 +70,7 @@ FirebaseClient.prototype.setLogin = function()
.
then
(
function
()
.
then
(
function
()
{
{
game
=
new
Phaser
.
Game
(
config
);
game
=
new
Phaser
.
Game
(
config
);
fbClient
.
isGameStarted
=
true
;
});
});
document
.
getElementById
(
'
mainTitle
'
).
style
.
display
=
'
none
'
;
document
.
getElementById
(
'
mainTitle
'
).
style
.
display
=
'
none
'
;
...
@@ -77,7 +79,10 @@ FirebaseClient.prototype.setLogin = function()
...
@@ -77,7 +79,10 @@ FirebaseClient.prototype.setLogin = function()
FirebaseClient
.
prototype
.
setLogOut
=
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
()
FirebaseClient
.
prototype
.
onEmailBtnClick
=
function
()
...
@@ -225,6 +230,9 @@ FirebaseClient.prototype.updateUserData = function(key, valueChanged, replace =
...
@@ -225,6 +230,9 @@ FirebaseClient.prototype.updateUserData = function(key, valueChanged, replace =
if
(
beforeData
.
item
!=
null
)
beforeData
.
item
.
push
(
valueChanged
);
if
(
beforeData
.
item
!=
null
)
beforeData
.
item
.
push
(
valueChanged
);
else
beforeData
.
item
=
[
valueChanged
];
else
beforeData
.
item
=
[
valueChanged
];
break
;
break
;
case
'
killCount
'
:
beforeData
.
killCount
=
replace
?
(
valueChanged
)
:
(
beforeData
.
killCount
+
valueChanged
);
break
;
default
:
default
:
console
.
log
(
'
[ERROR] database has no key for
'
+
key
);
console
.
log
(
'
[ERROR] database has no key for
'
+
key
);
break
;
break
;
...
@@ -235,10 +243,22 @@ FirebaseClient.prototype.updateUserData = function(key, valueChanged, replace =
...
@@ -235,10 +243,22 @@ FirebaseClient.prototype.updateUserData = function(key, valueChanged, replace =
document
.
addEventListener
(
'
DOMContentLoaded
'
,
function
()
document
.
addEventListener
(
'
DOMContentLoaded
'
,
function
()
{
{
window
.
fbClient
=
new
FirebaseClient
();
window
.
fbClient
=
new
FirebaseClient
();
document
.
onkeydown
=
function
(
e
)
{
if
(
!
fbClient
.
isGameStarted
&&
e
.
keyCode
===
13
)
{
fbClient
.
onEmailBtnClick
();
}
}
console
.
log
(
'
done load
'
);
console
.
log
(
'
done load
'
);
});
});
document
.
onkeydown
=
function
(
e
)
{
if
(
fbClient
.
isGameStarted
&&
e
.
keyCode
===
27
)
fbClient
.
logOut
();
}
class
UserData
class
UserData
{
{
constructor
()
constructor
()
...
@@ -254,5 +274,6 @@ class UserData
...
@@ -254,5 +274,6 @@ class UserData
this
.
title
=
[];
this
.
title
=
[];
this
.
money
=
0
;
this
.
money
=
0
;
this
.
item
=
[];
this
.
item
=
[];
this
.
killCount
=
0
;
}
}
}
}
\ No newline at end of file
js/GameCycle.js
View file @
7f8ade81
...
@@ -38,33 +38,4 @@ class Cycle //앞으로 cycle은 이 클래스를 사용해서 구현할 것
...
@@ -38,33 +38,4 @@ class Cycle //앞으로 cycle은 이 클래스를 사용해서 구현할 것
if
(
this
.
currentCycle
!=
null
)
this
.
currentCycle
=
this
.
currentCycle
.
reset
(
option
);
if
(
this
.
currentCycle
!=
null
)
this
.
currentCycle
=
this
.
currentCycle
.
reset
(
option
);
else
this
.
currentCycle
=
scene
.
time
.
addEvent
(
option
);
else
this
.
currentCycle
=
scene
.
time
.
addEvent
(
option
);
}
}
}
}
\ No newline at end of file
//단어 생성 사이클
WordSpace
.
wordCycle
=
new
Cycle
(
function
()
{
WordSpace
.
genWordByProb
(
this
);
});
//게임 오버 사이클
WordSpace
.
gameOverCycle
=
new
Cycle
(
gameOver
);
//호패 생성 사이클
WordSpace
.
nameCycle
=
new
Cycle
(
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
()
{
socket
.
emit
(
'
setPlayerTyping
'
,
{
playerTyping
:
WordSpace
.
playerTyping
,
isWord
:
WordSpace
.
setPlayerTyping
.
writeWord
,
isAttackMode
:
Input
.
attackMode
}
);
WordSpace
.
setPlayerTyping
.
writeWord
=
false
;
});
// 공격받을때의 일회용 이벤트들
WordSpace
.
attackedEvents
=
[];
\ No newline at end of file
js/ScenesData.js
View file @
7f8ade81
...
@@ -344,16 +344,15 @@ var roomScene = new Phaser.Class(
...
@@ -344,16 +344,15 @@ var roomScene = new Phaser.Class(
{
{
this
.
peopleText
.
setText
(
this
.
peopleCount
+
'
/ 10
'
);
this
.
peopleText
.
setText
(
this
.
peopleCount
+
'
/ 10
'
);
if
(
this
.
isCounting
)
if
(
this
.
isCounting
&&
!
this
.
isCountEnd
)
{
{
this
.
countText
.
setText
(((
this
.
endTime
-
Date
.
now
())
/
1000
).
toFixed
(
1
));
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');
//console.log('end Count');
setTimeout
(()
=>
{
ScenesData
.
endCountTimer
=
setTimeout
(()
=>
{
socket
.
emit
(
'
endCount
'
);
socket
.
emit
(
'
endCount
'
);
},
(
Phaser
.
Math
.
Distance
.
Between
(
0
,
0
,
game
.
config
.
width
/
2
,
game
.
config
.
height
*
10
/
9
)
*
10
));
},
(
Phaser
.
Math
.
Distance
.
Between
(
0
,
0
,
game
.
config
.
width
/
2
,
game
.
config
.
height
*
10
/
9
)
*
3
));
this
.
isCounting
=
false
;
this
.
isCountEnd
=
true
;
this
.
isCountEnd
=
true
;
this
.
players
.
forEach
(
function
(
element
){
this
.
players
.
forEach
(
function
(
element
){
element
.
follower
=
{
t
:
0
,
vec
:
new
Phaser
.
Math
.
Vector2
()
};
element
.
follower
=
{
t
:
0
,
vec
:
new
Phaser
.
Math
.
Vector2
()
};
...
@@ -373,12 +372,21 @@ var roomScene = new Phaser.Class(
...
@@ -373,12 +372,21 @@ var roomScene = new Phaser.Class(
}
}
else
if
(
this
.
isCountEnd
)
else
if
(
this
.
isCountEnd
)
{
{
this
.
players
.
forEach
(
function
(
element
){
if
(
this
.
isCounting
)
element
.
path
.
getPoint
(
element
.
follower
.
t
,
element
.
follower
.
vec
);
{
element
.
sprite
.
setPosition
(
element
.
follower
.
vec
.
x
,
element
.
follower
.
vec
.
y
);
this
.
players
.
forEach
(
function
(
element
){
element
.
nickname
.
setPosition
(
element
.
sprite
.
x
-
game
.
config
.
width
/
128
,
element
.
sprite
.
y
-
game
.
config
.
height
/
12
);
element
.
path
.
getPoint
(
element
.
follower
.
t
,
element
.
follower
.
vec
);
});
element
.
sprite
.
setPosition
(
element
.
follower
.
vec
.
x
,
element
.
follower
.
vec
.
y
);
this
.
countText
.
setText
(
'
잠시만 기다려주세요...
'
);
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
else
{
{
...
@@ -411,6 +419,7 @@ var gameScene = new Phaser.Class(
...
@@ -411,6 +419,7 @@ var gameScene = new Phaser.Class(
url
:
'
https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/plugins/dist/rexbuttonplugin.min.js
'
,
url
:
'
https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/plugins/dist/rexbuttonplugin.min.js
'
,
sceneKey
:
'
button
'
sceneKey
:
'
button
'
});
});
WordSpace
.
resetGame
();
WordSpace
.
weightTextObjForTest
=
this
.
add
.
text
(
game
.
config
.
width
*
5
/
64
,
game
.
config
.
height
*
5
/
48
,
'
뇌의 무게: (현재) 0 /
'
+
this
.
brainCapacity
+
'
(전체)
'
).
setDepth
(
10
).
setColor
(
'
#000000
'
);
WordSpace
.
weightTextObjForTest
=
this
.
add
.
text
(
game
.
config
.
width
*
5
/
64
,
game
.
config
.
height
*
5
/
48
,
'
뇌의 무게: (현재) 0 /
'
+
this
.
brainCapacity
+
'
(전체)
'
).
setDepth
(
10
).
setColor
(
'
#000000
'
);
WordSpace
.
killLogTextForTest
=
this
.
add
.
text
(
game
.
config
.
width
*
25
/
32
,
game
.
config
.
height
*
5
/
72
,
WordSpace
.
killLogForTest
).
setDepth
(
10
).
setColor
(
'
#000000
'
).
setAlign
(
'
right
'
);
WordSpace
.
killLogTextForTest
=
this
.
add
.
text
(
game
.
config
.
width
*
25
/
32
,
game
.
config
.
height
*
5
/
72
,
WordSpace
.
killLogForTest
).
setDepth
(
10
).
setColor
(
'
#000000
'
).
setAlign
(
'
right
'
);
},
},
...
@@ -437,38 +446,33 @@ var gameScene = new Phaser.Class(
...
@@ -437,38 +446,33 @@ var gameScene = new Phaser.Class(
WordSpace
.
startCycle
(
this
);
WordSpace
.
startCycle
(
this
);
WordSpace
.
setPlayerTyping
.
initiate
(
this
);
WordSpace
.
setPlayerTyping
.
initiate
(
this
);
WordSpace
.
nameWordTextForTest
=
this
.
add
.
text
(
50
,
400
,
'
현재 가진 호패들 : 없음
'
).
setDepth
(
10
).
setColor
(
'
#000000
'
);
WordSpace
.
nameQueue
.
initiate
();
WordSpace
.
nameQueue
.
initiate
();
//WordSpace.attackGauge.add(11);
//WordSpace.attackGauge.add(11);
},
},
update
:
function
()
update
:
function
()
{
{
WordSpace
.
deltaTime
=
this
.
sys
.
game
.
loop
.
delta
;
if
(
ScenesData
.
currentScene
==
ScenesData
.
gameScene
&&
WordSpace
.
gameTimer
!=
null
)
WordSpace
.
wordForcedGroup
.
forEach
(
function
(
element
)
{
element
.
attract
();
});
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
element
.
attract
();
})
WordSpace
.
attackPaperGroup
.
forEach
(
function
(
element
){
element
.
moveObject
(
element
);
});
let
tempNames
=
''
;
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
{
//테스트용
WordSpace
.
deltaTime
=
this
.
sys
.
game
.
loop
.
delta
;
tempNames
+=
element
.
wordText
+
(
element
.
isStrong
?
'
[강]
'
:
''
)
+
'
\n
'
;
WordSpace
.
wordForcedGroup
.
forEach
(
function
(
element
)
});
{
element
.
attract
();
WordSpace
.
nameWordTextForTest
.
setText
(
'
현재 가진 호패들 :
\n
'
+
tempNames
);
});
WordSpace
.
weightTextObjForTest
.
setText
(
'
뇌의 무게: (현재)
'
+
WordSpace
.
totalWeight
+
'
/
'
+
WordSpace
.
brainCapacity
+
'
(전체)
'
);
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
WordSpace
.
killLogTextForTest
.
setText
(
WordSpace
.
killLogForTest
);
{
WordSpace
.
setPlayerTyping
.
add
(
''
);
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/WordObject.js
View file @
7f8ade81
...
@@ -210,6 +210,7 @@ class AttackWord extends WordObject
...
@@ -210,6 +210,7 @@ class AttackWord extends WordObject
attackerId
:
RoomData
.
myself
.
id
,
attackerId
:
RoomData
.
myself
.
id
,
victimId
:
this
.
attacker
.
id
,
victimId
:
this
.
attacker
.
id
,
text
:
this
.
wordText
,
text
:
this
.
wordText
,
multiple
:
1
,
grade
:
Math
.
min
(
3
,
this
.
wordGrade
+
1
),
grade
:
Math
.
min
(
3
,
this
.
wordGrade
+
1
),
attackOption
:
{
attackOption
:
{
isStrong
:
false
,
isStrong
:
false
,
...
@@ -236,6 +237,7 @@ class NameWord extends WordObject
...
@@ -236,6 +237,7 @@ class NameWord extends WordObject
this
.
wordWeight
=
2
;
this
.
wordWeight
=
2
;
this
.
isStrong
=
_isStrong
;
this
.
isStrong
=
_isStrong
;
this
.
isActive
=
true
;
this
.
isActive
=
true
;
if
(
_isStrong
)
RoomData
.
myself
.
earnedStrongHopae
++
;
//console.log('Name : ' + player.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight);
//console.log('Name : ' + player.nickname + ', Strong : ' + this.isStrong + ', Weight : ' + this.wordWeight);
}
}
instantiate
(
scene
,
lenRate
)
instantiate
(
scene
,
lenRate
)
...
...
js/WordSpace.js
View file @
7f8ade81
...
@@ -222,10 +222,6 @@ function gameOver()
...
@@ -222,10 +222,6 @@ function gameOver()
socket
.
emit
(
'
defeated
'
);
socket
.
emit
(
'
defeated
'
);
console
.
log
(
'
defeat
'
);
console
.
log
(
'
defeat
'
);
ScenesData
.
gameScene
.
add
.
text
(
game
.
config
.
width
/
2
,
game
.
config
.
height
/
2
,
'
패배
'
,
{
fontSize
:
'
30pt
'
})
.
setPadding
(
5
,
5
,
5
,
5
).
setOrigin
(
0.5
,
0.5
).
setDepth
(
10
)
.
setColor
(
'
#000000
'
).
setBackgroundColor
(
'
#ffffff
'
);
//alert('defeat');
}
}
//게임 오버 판정을 위한 타이머
//게임 오버 판정을 위한 타이머
...
@@ -348,6 +344,11 @@ WordSpace.setPlayerTyping =
...
@@ -348,6 +344,11 @@ WordSpace.setPlayerTyping =
initiate
:
function
(
scene
)
initiate
:
function
(
scene
)
{
{
this
.
text
=
scene
.
add
.
text
(
100
,
200
,
'
현재 타수 :
'
+
WordSpace
.
playerTyping
.
toFixed
(
1
)).
setDepth
(
10
).
setColor
(
'
#000000
'
);
this
.
text
=
scene
.
add
.
text
(
100
,
200
,
'
현재 타수 :
'
+
WordSpace
.
playerTyping
.
toFixed
(
1
)).
setDepth
(
10
).
setColor
(
'
#000000
'
);
},
reset
:
function
()
{
this
.
totalTyping
=
0
;
this
.
writeWord
=
false
;
}
}
}
}
...
@@ -487,3 +488,62 @@ WordSpace.nameQueue =
...
@@ -487,3 +488,62 @@ WordSpace.nameQueue =
this
.
shuffle
();
this
.
shuffle
();
}
}
}
}
WordSpace
.
resetGame
=
function
()
{
WordSpace
.
weightTextObjForTest
=
null
;
WordSpace
.
nameWordTextForTest
=
null
;
WordSpace
.
killLogTextForTest
=
null
;
WordSpace
.
killLogForTest
=
''
;
WordSpace
.
nextWordCode
=
0
;
WordSpace
.
totalWeight
=
0
;
//현재 단어 무게 총합
WordSpace
.
totalWordNum
=
0
;
WordSpace
.
brainCapacity
=
200
;
//수용 가능한 단어 무게 최대치
WordSpace
.
gameTimer
=
null
;
//현재 게임 플레이 시간 타이머
WordSpace
.
isTimerOn
=
false
;
WordSpace
.
isInvincible
=
false
;
WordSpace
.
pyeongminAnims
=
[];
WordSpace
.
wordGroup
=
[];
WordSpace
.
nameGroup
=
[];
WordSpace
.
attackPaperGroup
=
[];
WordSpace
.
wordForcedGroup
=
[];
WordSpace
.
wordPhysicsGroup
=
null
;
WordSpace
.
nameQueue
.
queue
=
[];
WordSpace
.
setPlayerTyping
.
reset
();
WordSpace
.
isTimerOn
=
false
;
WordSpace
.
attackGauge
.
resetValue
();
WordSpace
.
CurrentPhase
=
WordSpace
.
Phase
.
START
;
WordSpace
.
playerTyping
=
0
;
WordSpace
.
playerTypingRate
=
0
;
//단어 생성 사이클
WordSpace
.
wordCycle
=
new
Cycle
(
function
()
{
WordSpace
.
genWordByProb
(
this
);
});
//게임 오버 사이클
WordSpace
.
gameOverCycle
=
new
Cycle
(
gameOver
);
//호패 생성 사이클
WordSpace
.
nameCycle
=
new
Cycle
(
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
()
{
socket
.
emit
(
'
setPlayerTyping
'
,
{
playerTyping
:
WordSpace
.
playerTyping
,
isWord
:
WordSpace
.
setPlayerTyping
.
writeWord
,
isAttackMode
:
Input
.
attackMode
}
);
WordSpace
.
setPlayerTyping
.
writeWord
=
false
;
});
// 공격받을때의 일회용 이벤트들
WordSpace
.
attackedEvents
=
[];
}
\ No newline at end of file
js/main.js
View file @
7f8ade81
var
config
=
{
var
config
=
{
type
:
Phaser
.
AUTO
,
type
:
Phaser
.
CANVAS
,
width
:
1920
,
width
:
1920
,
height
:
1080
,
height
:
1080
,
scale
:
{
scale
:
{
...
...
server.js
View file @
7f8ade81
...
@@ -16,7 +16,7 @@ app.get('/', function(req, res) {
...
@@ -16,7 +16,7 @@ app.get('/', function(req, res) {
server
.
listen
(
80
,
function
()
{
server
.
listen
(
80
,
function
()
{
console
.
log
(
'
[SERVER] Listening on port
'
+
server
.
address
().
port
);
console
.
log
(
'
[SERVER] Listening on port
'
+
server
.
address
().
port
);
GameServer
.
serverNumber
=
Math
.
floor
(
Math
.
random
()
*
1000
+
1
);
GameServer
.
serverNumber
=
Math
.
floor
(
Math
.
random
()
*
1000
+
1
);
console
.
log
(
'
[SERVER] server number is
${GameServer.serverNumber}
'
);
console
.
log
(
'
[SERVER] server number is
'
+
GameServer
.
serverNumber
);
});
});
...
@@ -48,20 +48,15 @@ io.on('connection', function(socket)
...
@@ -48,20 +48,15 @@ io.on('connection', function(socket)
if
(
msg
.
length
<
1
)
socket
.
emit
(
'
alert
'
,
'
errNicknameEmpty
'
);
if
(
msg
.
length
<
1
)
socket
.
emit
(
'
alert
'
,
'
errNicknameEmpty
'
);
else
else
{
{
let
isAlreadyHave
=
false
;
socket
.
playerData
.
nickname
=
msg
;
GameServer
.
currentPlayer
.
forEach
(
function
(
element
)
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] nickname set to
'
+
msg
);
{
GameServer
.
enterEmptyRoom
(
socket
);
if
(
element
.
playerData
.
nickname
===
msg
)
isAlreadyHave
=
true
;
});
if
(
isAlreadyHave
)
socket
.
emit
(
'
alert
'
,
'
errNicknameOverlaped
'
);
else
{
socket
.
playerData
.
nickname
=
msg
;
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] nickname set to
'
+
msg
);
GameServer
.
enterEmptyRoom
(
socket
);
}
}
}
});
});
socket
.
on
(
'
exitFromRoom
'
,
function
(
msg
){
GameServer
.
findPlayerSocket
(
msg
).
playerData
.
playingData
.
isInThisRoom
=
false
;
});
socket
.
on
(
'
setPlayerTyping
'
,
function
(
msg
)
// number playerTyping
socket
.
on
(
'
setPlayerTyping
'
,
function
(
msg
)
// number playerTyping
{
{
...
@@ -89,15 +84,51 @@ io.on('connection', function(socket)
...
@@ -89,15 +84,51 @@ io.on('connection', function(socket)
socket
.
playerData
.
currentRoom
.
announceToRoom
(
'
attackMode
'
,
socket
.
playerData
.
id
);
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
.
on
(
'
endCount
'
,
function
()
{
{
socket
.
playerData
.
currentRoom
.
aliveCount
--
;
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
();
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 +179,24 @@ io.on('connection', function(socket)
...
@@ -148,18 +179,24 @@ io.on('connection', function(socket)
{
{
GameServer
.
disconnectCount
++
;
GameServer
.
disconnectCount
++
;
let
data
=
socket
.
playerData
;
let
data
=
socket
.
playerData
;
if
(
typeof
data
===
undefined
)
if
(
data
===
undefined
)
{
{
console
.
error
(
'
[ERROR] data is undefined
'
);
console
.
error
(
'
[ERROR] data is undefined
'
);
console
.
table
(
GameServer
.
currentPlayer
);
console
.
table
(
GameServer
.
currentPlayer
);
GameServer
.
disconnectCount
--
;
}
}
else
// data.id is not undefined
else
// data.id is not undefined
{
{
disconnectUser
(
data
,
reason
);
disconnectUser
(
data
,
reason
);
}
}
const
connectDiff
=
GameServer
.
connectCount
-
GameServer
.
disconnectCount
;
const
connectDiff
=
GameServer
.
connectCount
-
GameServer
.
disconnectCount
;
const
playerCount
=
GameServer
.
currentPlayer
.
length
const
playerCount
=
GameServer
.
currentPlayer
.
length
;
console
.
log
({
connectDiff
,
playerCount
});
if
(
connectDiff
!=
playerCount
)
{
console
.
log
({
connectDiff
,
playerCount
});
console
.
table
(
GameServer
.
currentPlayer
);
}
socket
.
disconnect
();
});
});
});
});
...
@@ -178,20 +215,6 @@ var disconnectUser = function(data, reason)
...
@@ -178,20 +215,6 @@ var disconnectUser = function(data, reason)
if
(
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
READY
||
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
COUNT
)
if
(
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
READY
||
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
COUNT
)
{
{
data
.
currentRoom
.
exitRoom
(
data
.
id
);
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
)
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