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
e2b52595
Commit
e2b52595
authored
Jul 22, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'server'
parents
dcbdc78c
52aeaf6a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
126 additions
and
57 deletions
+126
-57
GameServer.js
GameServer.js
+12
-7
Client.js
js/Client.js
+46
-9
GameCycle.js
js/GameCycle.js
+12
-10
WordSpace.js
js/WordSpace.js
+33
-21
server.js
server.js
+23
-10
No files found.
GameServer.js
View file @
e2b52595
...
...
@@ -70,7 +70,6 @@ GameServer.getRoomNumber = function()
}
while
(
true
)
}
class
GameRoom
{
constructor
()
...
...
@@ -201,7 +200,6 @@ class GameRoom
this
.
announceToRoom
(
'
syncRoomData
'
,
toSync
);
console
.
log
(
'
[ROOM#
'
+
this
.
roomId
+
'
] Game Start with
'
+
this
.
currentPlayer
.
length
+
'
players
'
);
this
.
announceToRoom
(
'
changePhase
'
,
GameServer
.
Phase
.
START
);
this
.
announceToRoom
(
'
startGame
'
);
this
.
startTime
=
Date
.
now
();
}
...
...
@@ -213,6 +211,7 @@ class GameRoom
if
(
this
.
phaseChanger
<
0
&&
checkTime
-
this
.
startTime
>
60000
)
{
this
.
currentPhase
=
GameServer
.
Phase
.
MAIN
;
this
.
rateArrangePoint
=
150
;
this
.
announceToRoom
(
'
changePhase
'
,
GameServer
.
Phase
.
MAIN
);
}
else
if
(
this
.
phaseChanger
<
0
)
...
...
@@ -220,6 +219,7 @@ class GameRoom
this
.
phaseChanger
=
setTimeout
(
function
(
room
)
{
room
.
currentPhase
=
GameServer
.
Phase
.
MAIN
;
room
.
rateArrangePoint
=
150
;
room
.
announceToRoom
(
'
changePhase
'
,
GameServer
.
Phase
.
MAIN
);
room
.
phaseChanger
=
-
1
;
},
60000
-
(
checkTime
-
this
.
startTime
),
this
);
...
...
@@ -227,10 +227,11 @@ class GameRoom
}
else
if
(
this
.
currentPhase
===
GameServer
.
Phase
.
MAIN
)
{
let
playerLimit
=
Math
.
m
ax
(
this
.
currentPlayer
.
length
/
10
,
3
);
let
playerLimit
=
Math
.
m
in
(
Math
.
round
(
this
.
currentPlayer
.
length
/
5
)
,
3
);
if
(
this
.
aliveCount
<=
playerLimit
)
{
this
.
currentPhase
=
GameServer
.
Phase
.
MUSIC
;
this
.
rateArrangePoint
=
50
;
this
.
announceToRoom
(
'
changePhase
'
,
GameServer
.
Phase
.
MUSIC
);
}
}
...
...
@@ -292,7 +293,7 @@ class Player
this
.
rank
=
-
1
;
this
.
playerTyping
=
0
;
this
.
lastAttacks
=
[];
// { attackerId, word, wordGrade, time }
this
.
lastAttacks
=
[];
// { attackerId,
attacker, wrongCount,
word, wordGrade, time }
this
.
lastAttack
=
null
;
}
...
...
@@ -312,18 +313,22 @@ class Player
if
(
this
.
lastAttacks
.
length
>
0
)
{
this
.
lastAttack
=
this
.
lastAttacks
[
this
.
lastAttacks
.
length
-
1
];
if
(
Date
.
now
()
-
this
.
lastAttack
.
time
>
4
0000
)
this
.
lastAttack
=
null
;
if
(
Date
.
now
()
-
this
.
lastAttack
.
time
>
2
0000
)
this
.
lastAttack
=
null
;
else
{
this
.
lastAttacks
.
forEach
(
function
(
element
)
{
if
(
Date
.
now
()
-
element
.
time
<
40000
&&
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
.
currentPlayer
.
length
+
'
player left
'
);
console
.
log
(
'
[
'
+
this
.
id
+
'
] defeated, rank:
'
+
this
.
rank
+
'
,
'
+
room
.
aliveCount
+
'
player left
'
);
if
(
socket
.
playerData
.
currentRoom
.
aliveCount
===
1
)
{
...
...
js/Client.js
View file @
e2b52595
...
...
@@ -13,6 +13,8 @@ socket.on('alert', function(msg) // string errorcode
ScenesData
.
gameScene
.
add
.
text
(
640
,
360
,
'
승리!!!!
'
,
{
fontSize
:
'
30pt
'
})
.
setPadding
(
5
,
5
,
5
,
5
).
setOrigin
(
0.5
,
0.5
).
setDepth
(
11
)
.
setColor
(
'
#000000
'
).
setBackgroundColor
(
'
#ffffff
'
);
gameOver
();
}
//alert(toAlert);
});
...
...
@@ -22,6 +24,8 @@ socket.on('setId', function(msg) // {str, num playerNum}
console
.
log
(
msg
.
str
);
PlayerData
.
id
=
msg
.
num
;
});
// init game
socket
.
on
(
'
enterRoom
'
,
function
()
{
Audio
.
killSound
(
ScenesData
.
menuScene
,
'
login
'
);
...
...
@@ -82,8 +86,6 @@ socket.on('setRoomCount', function(msg)
}
},
200
);
});
// init game
socket
.
on
(
'
syncRoomData
'
,
function
(
msg
)
// {num roomNum, [] players}
{
//console.log(msg);
...
...
@@ -110,20 +112,56 @@ socket.on('changePhase', function(msg) // number Phase
{
console
.
log
(
'
phase changed from
'
+
WordSpace
.
CurrentPhase
+
'
to
'
+
msg
);
WordSpace
.
CurrentPhase
=
msg
;
WordSpace
.
pauseCycle
(
true
);
// 여기서 종이 드르륵 열면됨
ScenesData
.
gameScene
.
scene
.
pause
(
'
gameScene
'
);
setTimeout
(
function
()
{
ScenesData
.
gameScene
.
scene
.
resume
(
'
gameScene
'
);
// 여기서 종이 닫으면됨
WordSpace
.
pauseCycle
(
false
);
//console.log('start again');
},
5000
);
});
socket
.
on
(
'
setPlayerTypingRate
'
,
function
(
msg
)
// number playerTypingRate
{
WordSpace
.
PlayerTypingRate
=
msg
;
//console.log('rate: ' + msg);
});
socket
.
on
(
'
writeWord
'
,
function
(
msg
)
// number playerId
{
console
.
log
(
msg
+
'
write word
'
);
// msg의 id를 가진 사람이 writeWord한다.
});
socket
.
on
(
'
attackMode
'
,
function
(
msg
)
// number playerId
{
// if (msg's attackMode is false)
console
.
log
(
msg
+
'
is on attack Mode
'
);
// msg의 id를 가진 사람이 attack Mode이다.
});
socket
.
on
(
'
attack
'
,
function
(
msg
)
// {number attackerId, number targetId}
{
// 이때 위의 attack Mode인 사람(msg.attackerId)을 해제해주자.
console
.
log
(
msg
.
attackerId
+
'
attack to
'
+
msg
.
targetId
);
});
socket
.
on
(
'
attacked
'
,
function
(
msg
)
// object attackData
{
//console.log('attacked by ' + msg.attacker.nickname);
var
timeout
=
setTimeout
(
function
()
let
attackedEvent
=
new
Cycle
(
function
()
{
WordSpace
.
generateWord
.
Attack
(
ScenesData
.
gameScene
,
msg
.
text
,
msg
.
grade
,
msg
.
attacker
,
msg
.
isStrong
,
msg
.
isCountable
);
},
4000
);
console
.
log
(
timeout
);
for
(
let
i
=
0
;
i
<
msg
.
multiple
;
i
++
)
WordSpace
.
generateWord
.
Attack
(
ScenesData
.
gameScene
,
msg
.
text
,
msg
.
grade
,
msg
.
attacker
,
msg
.
isStrong
,
msg
.
isCountable
);
attackedEvent
.
currentCycle
.
destroy
();
WordSpace
.
attackedEvents
.
splice
(
WordSpace
.
attackedEvents
.
findIndex
(
function
(
element
)
{
return
element
.
cert
===
(
msg
.
text
+
msg
.
attacker
);
}),
1
);
});
attackedEvent
.
cert
=
msg
.
text
+
msg
.
attacker
;
attackedEvent
.
resetCycle
(
ScenesData
.
gameScene
,
4000
,
0
,
false
);
WordSpace
.
attackedEvents
.
push
(
attackedEvent
);
//console.log(timeout);
});
socket
.
on
(
'
defeat
'
,
function
(
msg
)
// object player
{
...
...
@@ -144,10 +182,9 @@ socket.on('gameEnd', function(msg) // object player
{
console
.
log
(
msg
.
nickname
+
'
Win!!!!!!
'
);
});
socket
.
on
(
'
attackSucceed
'
,
function
(
msg
)
{
console
.
log
(
'
client
'
);
//
console.log('client');
let
tempWord
=
WordSpace
.
generateWord
.
Name
(
ScenesData
.
gameScene
,
true
,
msg
.
victim
);
tempWord
.
destroy
();
});
...
...
@@ -155,7 +192,7 @@ socket.on('attackSucceed', function(msg)
// out game
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
.
aliveCount
--
;
});
\ No newline at end of file
js/GameCycle.js
View file @
e2b52595
...
...
@@ -3,10 +3,7 @@ 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
=
setInterval
(
function
()
{
socket
.
emit
(
'
setPlayerTyping
'
,
WordSpace
.
playerTyping
);
},
500
);
WordSpace
.
playerTypingCycle
.
resetCycle
(
scene
,
500
,
500
,
true
);
}
WordSpace
.
pauseCycle
=
function
(
isPause
)
...
...
@@ -15,11 +12,8 @@ WordSpace.pauseCycle = function(isPause)
WordSpace
.
nameCycle
.
currentCycle
.
paused
=
isPause
;
WordSpace
.
varAdjustCycle
.
currentCycle
.
paused
=
isPause
;
WordSpace
.
attackGauge
.
pauseCycle
(
isPause
);
if
(
isPause
)
clearInterval
(
WordSpace
.
playerTypingCycle
);
else
WordSpace
.
playerTypingCycle
=
setInterval
(
function
()
{
socket
.
emit
(
'
setPlayerTyping
'
,
WordSpace
.
playerTyping
);
},
500
);
WordSpace
.
playerTypingCycle
.
currentCycle
.
paused
=
isPause
;
WordSpace
.
attackedEvents
.
forEach
(
function
(
element
)
{
element
.
currentCycle
.
paused
=
isPause
});
}
class
Cycle
//앞으로 cycle은 이 클래스를 사용해서 구현할 것
...
...
@@ -65,4 +59,12 @@ WordSpace.varAdjustCycle = new Cycle(function()
//WordSpace.GetPhase();
//WordSpace.GetPlayerTypingRate();
WordSpace
.
AdjustVarByPhase
(
WordSpace
.
playerTypingRate
,
WordSpace
.
CurrentPhase
);
});
\ No newline at end of file
});
// 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/WordSpace.js
View file @
e2b52595
...
...
@@ -21,7 +21,7 @@ WordSpace.wordPhysicsGroup = null;
WordSpace
.
GradeProb
=
[
0.35
,
0.6
,
0.8
];
WordSpace
.
Phase
=
{
READY
:
0
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
WordSpace
.
CurrentPhase
=
WordSpace
.
Phase
.
READY
;
WordSpace
.
CurrentPhase
=
WordSpace
.
Phase
.
START
;
WordSpace
.
playerTyping
=
0
;
WordSpace
.
playerTypingRate
=
0
;
...
...
@@ -65,16 +65,7 @@ WordSpace.spaceInitiate = function(scene)
WordSpace
.
AdjustVarByPhase
=
function
(
typingRate
,
phase
)
{
if
(
phase
==
WordSpace
.
Phase
.
READY
)
{
WordSpace
.
delay
.
WordSpawn
=
10000
;
WordSpace
.
delay
.
NameSpawn
=
10000
;
WordSpace
.
NameSpawnReduce
=
0
;
WordSpace
.
GradeProb
[
0
]
=
1
;
WordSpace
.
GradeProb
[
1
]
=
1
;
WordSpace
.
GradeProb
[
2
]
=
1
;
}
else
if
(
phase
==
WordSpace
.
Phase
.
START
)
if
(
phase
==
WordSpace
.
Phase
.
START
)
{
WordSpace
.
delay
.
WordSpawn
=
3000
;
WordSpace
.
delay
.
NameSpawn
=
15000
;
...
...
@@ -359,7 +350,8 @@ WordSpace.findWord = function(wordText)
{
roomNum
:
RoomData
.
roomId
,
victim
:
RoomData
.
myself
,
target
:
element
.
attacker
.
id
target
:
element
.
attacker
.
id
,
word
:
element
.
wordText
}
socket
.
emit
(
'
defenseFailed
'
,
victimData
);
return
true
;
...
...
@@ -372,11 +364,13 @@ WordSpace.findWord = function(wordText)
WordSpace
.
setPlayerTyping
=
{
totalTyping
:
0
,
writeWord
:
false
,
add
:
function
(
wordText
)
{
this
.
totalTyping
+=
wordText
!=
null
?
WordReader
.
getWordTyping
(
wordText
)
:
0
;
WordSpace
.
playerTyping
=
this
.
totalTyping
/
WordSpace
.
gameTimer
.
now
*
60
*
1000
;
this
.
text
.
setText
(
'
현재 타수 :
'
+
WordSpace
.
playerTyping
.
toFixed
(
1
));
this
.
writeWord
=
wordText
!=
''
?
true
:
false
;
},
initiate
:
function
(
scene
)
{
...
...
@@ -390,22 +384,40 @@ WordSpace.attack = function(wordText, grade)
if
(
wordText
!=
''
)
{
console
.
log
(
'
attack
'
+
wordText
+
'
, grade:
'
+
grade
);
let
toSend
=
[];
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
//console.log(RoomData.myself);
let
attackData
=
let
targetId
=
element
.
ownerId
;
let
sendIdx
=
toSend
.
findIndex
(
function
(
element
)
{
return
element
.
target
===
targetId
;
});
if
(
sendIdx
!==
-
1
)
{
toSend
[
sendIdx
].
multiple
++
;
}
else
{
roomNum
:
RoomData
.
roomId
,
attacker
:
RoomData
.
myself
,
target
:
element
.
ownerId
,
text
:
wordText
,
grade
:
grade
,
isStrong
:
element
.
isStrong
let
attackData
=
{
roomNum
:
RoomData
.
roomId
,
attacker
:
RoomData
.
myself
,
target
:
element
.
ownerId
,
text
:
wordText
,
grade
:
grade
,
isStrong
:
element
.
isStrong
,
multiple
:
1
}
toSend
.
push
(
attackData
);
}
socket
.
emit
(
'
attack
'
,
attackData
);
element
.
physicsObj
.
destroy
();
element
.
wordObj
.
destroy
();
});
toSend
.
forEach
(
function
(
element
)
{
socket
.
emit
(
'
attack
'
,
element
);
});
WordSpace
.
generateWord
.
Name
(
ScenesData
.
gameScene
,
false
,
null
);
WordSpace
.
generateWord
.
Name
(
ScenesData
.
gameScene
,
false
,
null
);
WordSpace
.
nameGroup
=
[];
...
...
server.js
View file @
e2b52595
...
...
@@ -58,22 +58,29 @@ io.on('connection', function(socket)
{
try
{
socket
.
playerData
.
playingData
.
playerTyping
=
msg
;
if
(
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
.
playerTyping
<
msg
)
socket
.
playerData
.
playingData
.
playerTyping
=
msg
.
playerTyping
;
if
(
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
.
playerTyping
<
msg
.
playerTyping
)
{
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
=
socket
.
playerData
.
playingData
;
}
if
(
socket
.
playerData
.
currentRoom
.
minTypingPlayer
.
playerTyping
>
msg
)
if
(
socket
.
playerData
.
currentRoom
.
minTypingPlayer
.
playerTyping
>
msg
.
playerTyping
)
{
socket
.
playerData
.
currentRoom
.
minTypingPlayer
=
socket
.
playerData
.
playingData
;
}
let
playerTypingRate
=
(
msg
-
(
socket
.
playerData
.
currentRoom
.
minTypingPlayer
.
playerTyping
-
socket
.
playerData
.
currentRoom
.
rateArrangePoint
))
/
let
playerTypingRate
=
(
msg
.
playerTyping
-
(
socket
.
playerData
.
currentRoom
.
minTypingPlayer
.
playerTyping
-
socket
.
playerData
.
currentRoom
.
rateArrangePoint
))
/
(
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
.
playerTyping
-
socket
.
playerData
.
currentRoom
.
minTypingPlayer
.
playerTyping
+
socket
.
playerData
.
currentRoom
.
rateArrangePoint
*
2
);
socket
.
emit
(
'
setPlayerTypingRate
'
,
playerTypingRate
);
if
(
msg
.
isWord
)
{
socket
.
playerData
.
currentRoom
.
announceToRoom
(
'
writeWord
'
,
socket
.
playerData
.
id
);
}
if
(
msg
.
isAttackMode
)
{
socket
.
playerData
.
currentRoom
.
announceToRoom
(
'
attackMode
'
,
socket
.
playerData
.
id
);
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
'
[ERR] error catched on setPlayerTyping
'
)}
});
socket
.
on
(
'
endCount
'
,
function
()
...
...
@@ -88,6 +95,7 @@ io.on('connection', function(socket)
socket
.
on
(
'
attack
'
,
function
(
msg
)
{
socket
.
playerData
.
currentRoom
.
announceToTarget
(
msg
.
target
,
'
attacked
'
,
msg
);
socket
.
playerData
.
currentRoom
.
announceToRoom
(
'
attack
'
,
{
attackerId
:
msg
.
attacker
.
id
,
targetId
:
msg
.
target
});
//console.log('attack ' + msg.target + ' by ' + msg.attacker.id + ' with ' + msg.text);
setTimeout
(
function
()
{
...
...
@@ -98,16 +106,16 @@ io.on('connection', function(socket)
{
attackerId
:
msg
.
attacker
.
id
,
attacker
:
msg
.
attacker
.
nickname
,
wrongCount
:
0
,
word
:
msg
.
text
,
wordGrade
:
msg
.
grade
,
time
:
Date
.
now
()
}
if
(
target
.
playerData
.
playingData
.
lastAttacks
.
length
<
5
)
target
.
playerData
.
playingData
.
lastAttacks
.
push
(
dataToPush
);
else
target
.
playerData
.
playingData
.
lastAttacks
.
push
(
dataToPush
);
while
(
target
.
playerData
.
playingData
.
lastAttacks
[
0
].
time
+
20000
<
Date
.
now
())
{
target
.
playerData
.
playingData
.
lastAttacks
.
splice
(
0
,
1
);
target
.
playerData
.
playingData
.
lastAttacks
.
push
(
dataToPush
);
}
}
},
4000
);
...
...
@@ -121,6 +129,11 @@ io.on('connection', function(socket)
socket
.
on
(
'
defenseFailed
'
,
function
(
msg
)
{
socket
.
playerData
.
currentRoom
.
announceToTarget
(
msg
.
target
,
'
attackSucceed
'
,
msg
);
let
wrongCountIndex
=
socket
.
playerData
.
playingData
.
lastAttacks
.
findIndex
(
function
(
element
)
{
return
(
element
.
word
===
msg
.
word
)
&&
(
element
.
attackerId
===
msg
.
target
);
});
if
(
wrongCountIndex
!==
-
1
)
socket
.
playerData
.
playingData
.
lastAttacks
[
wrongCountIndex
].
wrongCount
++
;
});
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
...
...
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