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
59dde809
Commit
59dde809
authored
Jul 08, 2019
by
18류지석
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'wordspace' into release
parents
303a919d
475a5d19
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
700 additions
and
130 deletions
+700
-130
GameServer.js
GameServer.js
+131
-0
KKUTU_word.txt
assets/KKUTU_word.txt
+0
-0
background_main.png
assets/image/background/background_main.png
+0
-0
menuBackground.png
assets/placeholder/menuBackground.png
+0
-0
index.html
index.html
+2
-0
Background.js
js/Background.js
+8
-7
CSVParsing.js
js/CSVParsing.js
+1
-1
Client.js
js/Client.js
+36
-0
Input.js
js/Input.js
+32
-8
ScenesData.js
js/ScenesData.js
+81
-0
WordObject.js
js/WordObject.js
+115
-10
WordReader.js
js/WordReader.js
+5
-3
WordSpace.js
js/WordSpace.js
+220
-62
main.js
js/main.js
+10
-34
server.js
server.js
+59
-5
No files found.
GameServer.js
0 → 100644
View file @
59dde809
var
GameServer
=
GameServer
||
{};
GameServer
.
Phase
=
{
READY
:
0
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
startCount
=
1
;
GameServer
.
currentPlayer
=
[];
GameServer
.
playingRoom
=
[];
GameServer
.
getPlayerNumber
=
function
()
{
do
{
var
num
=
Math
.
floor
(
Math
.
random
()
*
1000
+
1
);
if
(
!
this
.
currentPlayer
.
includes
(
num
))
return
num
;
}
while
(
true
)
}
GameServer
.
findPlayer
=
function
(
playerId
)
{
var
idx
=
this
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
socket
;
});
if
(
idx
!=
-
1
)
return
this
.
currentPlayer
[
idx
];
else
{
console
.
log
(
'
[ERR] wrong playerId to find
'
);
return
null
;
}
}
GameServer
.
nextRoomNumber
=
0
;
GameServer
.
makeRoom
=
function
()
{
var
roomOption
=
{
roomNum
:
GameServer
.
nextRoomNumber
++
,
maxPlayer
:
5
,
nextRank
:
5
,
currentPlayer
:
[],
currentSocket
:
[],
currentPhase
:
GameServer
.
Phase
.
READY
,
rateArrangePoint
:
300
,
maxTypingPlayer
:
null
,
minTypingPlayer
:
null
}
this
.
playingRoom
.
push
(
roomOption
);
console
.
log
(
'
[SERVER] new room #
'
+
roomOption
.
roomNum
+
'
made, roomCount:
'
+
this
.
playingRoom
.
length
);
return
this
.
playingRoom
.
length
-
1
;
}
GameServer
.
findRoomIndex
=
function
(
roomNum
)
{
return
GameServer
.
playingRoom
.
findIndex
(
function
(
element
)
{
return
element
.
roomNum
===
roomNum
;
});
}
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
{
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
&&
this
.
playingRoom
[
i
].
currentPhase
==
this
.
Phase
.
READY
)
{
toEnter
=
i
;
break
;
}
}
if
(
toEnter
===
-
1
)
{
toEnter
=
this
.
makeRoom
();
}
return
this
.
enterRoom
(
toEnter
,
playerData
);
}
GameServer
.
startRoom
=
function
(
roomIdx
)
{
let
room
=
this
.
playingRoom
[
roomIdx
];
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
,
'
changePhase
'
,
this
.
Phase
.
START
);
this
.
announceToRoom
(
roomIdx
,
'
startGame
'
);
}
GameServer
.
announceToRoom
=
function
(
roomIdx
,
_message
,
_data
=
null
)
{
this
.
playingRoom
[
roomIdx
].
currentSocket
.
forEach
(
function
(
element
)
{
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
assets/KKUTU_word.txt
View file @
59dde809
B
가
assets/image/background/background_main.png
0 → 100644
View file @
59dde809
419 KB
assets/placeholder/menuBackground.png
0 → 100644
View file @
59dde809
130 KB
index.html
View file @
59dde809
...
...
@@ -4,6 +4,7 @@
<meta
charset=
"utf-8"
/>
<script
src=
"/socket.io/socket.io.js"
></script>
<script
src=
"js/phaser.js"
></script>
<script
src=
"js/ScenesData.js"
></script>
<script
src=
"js/Background.js"
></script>
<script
src=
"js/Input.js"
></script>
<script
src=
"js/WordSpace.js"
></script>
...
...
@@ -13,6 +14,7 @@
<script
src=
"js/SelectWord.js"
></script>
</head>
<body>
<script
src=
"js/Client.js"
></script>
<script
src=
"js/Main.js"
></script>
</body>
</html>
\ No newline at end of file
js/Background.js
View file @
59dde809
var
BackGround
=
BackGround
||
{}
BackGround
.
isImageLoaded
=
false
;
BackGround
.
brainGroup
=
null
;
BackGround
.
loadImage
=
function
(
scene
)
{
if
(
!
this
.
isImageLoaded
)
{
scene
.
load
.
image
(
'
brainGround0
'
,
'
assets/placeholder/playback.png
'
);
}
scene
.
load
.
image
(
'
brainGround
'
,
'
assets/placeholder/playback.png
'
);
scene
.
load
.
image
(
'
menuBackground
'
,
'
assets/placeholder/menuBackground.png
'
)
}
BackGround
.
drawBrain
=
function
(
scene
)
{
brains
=
scene
.
add
.
sprite
(
640
,
360
,
'
brainGround0
'
).
setDisplaySize
(
1282
,
722
).
setDepth
(
1
);
brains
=
scene
.
add
.
sprite
(
640
,
360
,
'
brainGround
'
).
setDisplaySize
(
1282
,
722
).
setDepth
(
1
);
}
BackGround
.
drawMenu
=
function
(
scene
)
{
scene
.
add
.
sprite
(
640
,
360
,
'
menuBackground
'
).
setDisplaySize
(
1282
,
722
).
setDepth
(
1
);
}
\ No newline at end of file
js/CSVParsing.js
View file @
59dde809
...
...
@@ -27,7 +27,7 @@ CSVParsing.CSVParse = function(scene) {
CSVParsing
.
gradeArray
.
grade2
.
push
(
allRows
[
singleRow
].
trim
());
}
else
if
(
grade
==
1
)
{
CSVParsing
.
gradeArray
.
grade1
.
push
(
allRows
[
singleRow
].
trim
());
}
else
{
}
else
if
(
grade
==
0
)
{
CSVParsing
.
gradeArray
.
grade0
.
push
(
allRows
[
singleRow
].
trim
());
}
}
...
...
js/Client.js
0 → 100644
View file @
59dde809
var
socket
=
io
.
connect
();
socket
.
emit
(
'
idRequest
'
);
socket
.
on
(
'
setId
'
,
function
(
msg
)
// {str, num playerNum}
{
console
.
log
(
msg
.
str
);
PlayerData
.
idNum
=
msg
.
num
;
});
socket
.
on
(
'
setPlayerTypingRate
'
,
function
(
msg
)
// number playerTypingRate
{
WordSpace
.
PlayerTypingRate
=
msg
;
console
.
log
(
'
rate:
'
+
msg
);
});
socket
.
on
(
'
syncRoomData
'
,
function
(
msg
)
// {num roomNum, [] players}
{
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 index , num id, str nickname}
{
console
.
log
(
msg
.
index
+
'
/
'
+
msg
.
id
+
'
/
'
+
msg
.
nickname
+
'
disconnected
'
);
RoomData
.
players
[
msg
.
index
].
isAlive
=
false
;
});
\ No newline at end of file
js/Input.js
View file @
59dde809
...
...
@@ -4,6 +4,7 @@ Input.input = [];
Input
.
convInput
=
''
;
// converted input
Input
.
isShifted
=
false
;
Input
.
isEntered
=
false
;
Input
.
pressCount
=
0
;
Input
.
justPressed
=
''
;
Input
.
maxInput
=
5
;
...
...
@@ -11,6 +12,34 @@ Input.maxInput = 5;
Input
.
attackMode
=
false
;
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
()
{
Input
.
convInput
=
Input
.
removeConVow
(
Input
.
convInput
);
if
(
Input
.
convInput
.
length
>
0
)
{
socket
.
emit
(
'
setNickname
'
,
Input
.
convInput
);
PlayerData
.
nickname
=
Input
.
convInput
;
Input
.
reset
();
game
.
scene
.
remove
(
'
menuScene
'
);
}
else
{
alert
(
'
정확한 가명을 입력해주세요.
'
);
Input
.
reset
();
}
}
Input
.
reset
=
function
()
{
Input
.
input
=
[];
...
...
@@ -275,7 +304,7 @@ Input.removeConVow = function(_wordText)
Input
.
inputField
=
{
generate
:
function
(
scene
)
generate
:
function
(
scene
,
enterCallback
)
{
this
.
background
=
scene
.
add
.
sprite
(
640
,
550
,
'
inputfield
'
).
setDepth
(
10
);
this
.
text
=
scene
.
add
.
text
(
640
,
550
,
"
안녕하세요
"
,
{
font
:
'
25pt 궁서
'
}).
setOrigin
(
0.5
,
0.5
).
setColor
(
'
#000000
'
).
setDepth
(
10
);
...
...
@@ -293,13 +322,8 @@ Input.inputField =
Input
.
inputField
.
text
.
setText
(
Input
.
convInput
);
}
});
scene
.
input
.
keyboard
.
on
(
'
keydown-ENTER
'
,
function
()
{
if
(
Input
.
attackMode
)
WordSpace
.
attack
(
Input
.
convInput
,
Input
.
attackOption
.
wordGrade
);
else
WordSpace
.
findWord
(
Input
.
convInput
);
WordSpace
.
resetGameOverTimer
();
Input
.
reset
();
});
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/ScenesData.js
0 → 100644
View file @
59dde809
var
menuScene
=
new
Phaser
.
Class
(
{
Extends
:
Phaser
.
Scene
,
initialize
:
function
menuScene
()
{
Phaser
.
Scene
.
call
(
this
,
{
key
:
'
menuScene
'
});
},
preload
:
function
()
{
Input
.
inputField
.
loadImage
(
this
);
BackGround
.
loadImage
(
this
);
},
create
:
function
()
{
Input
.
inputField
.
generate
(
this
,
Input
.
menuSceneEnterReaction
);
BackGround
.
drawMenu
(
this
);
}
});
var
gameScene
=
new
Phaser
.
Class
(
{
Extends
:
Phaser
.
Scene
,
initialize
:
function
gameScene
()
{
Phaser
.
Scene
.
call
(
this
,
{
key
:
'
gameScene
'
});
},
preload
:
function
()
{
BackGround
.
loadImage
(
this
);
WordSpace
.
loadImage
(
this
);
Input
.
inputField
.
loadImage
(
this
);
CSVParsing
.
loadText
(
this
);
},
create
:
function
()
{
CSVParsing
.
CSVParse
(
this
);
BackGround
.
drawBrain
(
this
);
WordSpace
.
wordPhysicsGroup
=
this
.
physics
.
add
.
group
();
Input
.
inputField
.
generate
(
this
,
Input
.
gameSceneEnterReaction
);
WordSpace
.
attackGauge
.
generate
(
this
);
WordSpace
.
spaceInitiate
(
this
);
WordSpace
.
attackGauge
.
resetCycle
(
this
);
WordSpace
.
wordCycle
.
resetCycle
(
this
,
3000
,
0
,
true
);
WordSpace
.
nameCycle
.
resetCycle
(
this
,
3000
,
0
,
true
);
WordSpace
.
varAdjustCycle
.
resetCycle
(
this
,
100
,
0
,
true
);
WordSpace
.
setPlayerTyping
.
initiate
(
this
);
WordSpace
.
nameWordTextForTest
=
WordSpace
.
gameSceneForTest
.
add
.
text
(
50
,
400
,
'
현재 가진 호패들 : 없음
'
).
setDepth
(
10
).
setColor
(
'
#000000
'
);
},
update
:
function
()
{
WordSpace
.
wordForcedGroup
.
forEach
(
function
(
element
)
{
element
.
attract
();
});
let
tempNames
=
''
;
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
tempNames
+=
element
.
wordText
+
'
\n
'
;
});
WordSpace
.
nameWordTextForTest
.
setText
(
'
현재 가진 호패들 :
\n
'
+
tempNames
);
WordSpace
.
weightTextObjForTest
.
setText
(
'
뇌의 무게: (현재)
'
+
WordSpace
.
totalWeight
+
'
/
'
+
WordSpace
.
brainCapacity
+
'
(전체)
'
);
WordSpace
.
setPlayerTyping
.
add
(
''
);
}
});
\ No newline at end of file
js/WordObject.js
View file @
59dde809
...
...
@@ -4,23 +4,33 @@ class WordObject
{
this
.
generationCode
=
WordSpace
.
nextWordCode
++
;
this
.
wordText
=
text
;
//this.wordText = Input.removeConVow(text);
this
.
wordTyping
=
WordReader
.
getWordTyping
(
this
.
wordText
);
this
.
wordGrade
=
WordReader
.
getWordGrade
(
this
.
wordTyping
);
this
.
wordWeight
=
WordReader
.
getWordWeight
(
this
.
wordGrade
);
//console.log("wordTyping : " + this.wordTyping + '\n' + "wordGrade : " + this.wordGrade + '\n' + "wordWeight : " + this.wordWeight + '\n');
this
.
wordSpeed
=
1
;
this
.
wordSpeed
=
0.5
;
}
instantiate
(
scene
)
instantiate
(
scene
,
lenRate
)
{
let
p
=
[{
x
:
3
,
y
:
0.7
},
{
x
:
20
,
y
:
1.8
}];
let
scale
=
((
p
[
1
].
y
-
p
[
0
].
y
)
/
(
p
[
1
].
x
-
p
[
0
].
x
))
*
(
this
.
wordWeight
-
p
[
0
].
x
)
+
p
[
0
].
y
;
let
fontscale
=
25
;
var
random
=
WordSpace
.
getSpawnPoint
();
var
random
=
WordSpace
.
getSpawnPoint
(
lenRate
);
this
.
physicsObj
=
scene
.
physics
.
add
.
sprite
(
random
.
x
,
random
.
y
,
'
wordBgr
'
+
this
.
wordGrade
+
'
_
'
+
Math
.
min
(
Math
.
max
(
2
,
this
.
wordText
.
length
),
6
))
.
setMass
(
this
.
wordWeight
)
.
setScale
(
scale
);
.
setMass
(
this
.
wordWeight
*
10
)
.
setScale
(
scale
)
.
setFrictionX
(
0
)
.
setFrictionY
(
0
)
.
setBounce
(
0.5
);
let
dist
=
Phaser
.
Math
.
Distance
.
Between
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
,
WordSpace
.
gravityPoint
.
x
,
WordSpace
.
gravityPoint
.
y
);
let
angle
=
Phaser
.
Math
.
Angle
.
Between
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
,
WordSpace
.
gravityPoint
.
x
,
WordSpace
.
gravityPoint
.
y
);
//임시땜빵
this
.
moveStarted
=
false
;
this
.
initSpeed
=
{
x
:
Math
.
max
(
0
,
200
-
WordSpace
.
totalWeight
)
*
Math
.
cos
(
angle
),
y
:
Math
.
max
(
0
,
200
-
WordSpace
.
totalWeight
)
*
Math
.
sin
(
angle
)};
this
.
wordObj
=
scene
.
add
.
text
(
random
.
x
,
random
.
y
,
this
.
wordText
,
{
...
...
@@ -29,6 +39,7 @@ class WordObject
fontStyle
:
(
this
.
wordWeight
>
5
?
'
bold
'
:
''
)
}).
setColor
(
'
#000000
'
).
setOrigin
(
0.5
,
0.5
);
WordSpace
.
totalWeight
+=
this
.
wordWeight
;
WordSpace
.
totalWordNum
+=
1
;
WordSpace
.
setGameOverTimer
();
//console.log("Total weight : " + WordSpace.totalWeight);
}
...
...
@@ -37,6 +48,8 @@ class WordObject
{
console
.
log
(
this
.
generationCode
+
'
:
'
+
this
.
wordText
+
'
destroyed
'
);
WordSpace
.
totalWeight
-=
this
.
wordWeight
;
WordSpace
.
totalWordNum
-=
1
;
WordSpace
.
resetGameOverTimer
();
this
.
wordObj
.
destroy
();
const
groupIdx
=
WordSpace
.
wordGroup
.
findIndex
(
function
(
item
)
{
return
this
.
isEqualObject
(
item
.
generationCode
)},
this
);
if
(
groupIdx
>
-
1
)
WordSpace
.
wordGroup
.
splice
(
groupIdx
,
1
);
...
...
@@ -45,13 +58,105 @@ class WordObject
WordSpace
.
wordPhysicsGroup
.
remove
(
this
.
physicsObj
,
true
,
true
);
}
attract
()
{
var
dist
=
Phaser
.
Math
.
Distance
.
Between
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
,
WordSpace
.
gravityPoint
.
x
,
WordSpace
.
gravityPoint
.
y
);
var
angle
=
Phaser
.
Math
.
Angle
.
Between
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
,
WordSpace
.
gravityPoint
.
x
,
WordSpace
.
gravityPoint
.
y
);
this
.
physicsObj
.
setVelocity
(
dist
*
Math
.
cos
(
angle
)
*
this
.
wordSpeed
,
dist
*
Math
.
sin
(
angle
)
*
this
.
wordSpeed
);
if
(
!
this
.
moveStarted
)
{
this
.
moveStarted
=
true
;
this
.
physicsObj
.
setVelocity
(
this
.
initSpeed
.
x
,
this
.
initSpeed
.
y
);
}
let
gravityScale
=
0.8
,
velocityLimit
;
let
accel
=
{
x
:
this
.
physicsObj
.
body
.
velocity
.
x
,
y
:
this
.
physicsObj
.
body
.
velocity
.
y
};
let
dist
,
angle
;
let
vel
;
dist
=
Phaser
.
Math
.
Distance
.
Between
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
,
WordSpace
.
gravityPoint
.
x
,
WordSpace
.
gravityPoint
.
y
);
angle
=
Phaser
.
Math
.
Angle
.
Between
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
,
WordSpace
.
gravityPoint
.
x
,
WordSpace
.
gravityPoint
.
y
);
velocityLimit
=
dist
*
0.9
;
accel
.
x
+=
gravityScale
*
Math
.
cos
(
angle
);
accel
.
y
+=
gravityScale
*
Math
.
sin
(
angle
);
vel
=
Phaser
.
Math
.
Distance
.
Between
(
accel
.
x
,
accel
.
y
,
0
,
0
);
if
(
vel
>
velocityLimit
)
{
accel
.
x
*=
velocityLimit
/
vel
;
accel
.
y
*=
velocityLimit
/
vel
;
}
this
.
physicsObj
.
setVelocity
(
accel
.
x
,
accel
.
y
);
this
.
wordObj
.
setPosition
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
);
}
isEqualObject
(
_generationCode
)
{
return
_generationCode
===
this
.
generationCode
;
}
}
\ No newline at end of file
}
class
NormalWord
extends
WordObject
{
constructor
(
text
)
{
super
(
text
);
}
destroy
()
{
switch
(
this
.
wordGrade
)
{
case
0
:
WordSpace
.
attackGauge
.
add
(
2.5
);
break
;
case
1
:
WordSpace
.
attackGauge
.
add
(
1.5
);
break
;
case
2
:
WordSpace
.
attackGauge
.
add
(
0.9
);
break
;
case
3
:
WordSpace
.
attackGauge
.
add
(
0.5
);
break
;
default
:
console
.
log
(
'
[ERR] wrong grade of word
'
);
break
;
}
super
.
destroy
();
}
}
class
AttackWord
extends
WordObject
{
constructor
(
text
,
_wordGrade
,
_attacker
,
isStrong
)
{
super
(
text
);
this
.
wordGrade
=
_wordGrade
;
this
.
wordWeight
=
WordReader
.
getWordWeight
(
this
.
wordGrade
);
if
(
WordReader
.
getWordTyping
(
_attacker
)
<=
9
)
this
.
wordWeight
+=
this
.
wordWeight
*
0.2
*
(
WordReader
.
getWordTyping
(
PlayerData
.
nickname
)
-
9
);
this
.
wordWeight
*=
isStrong
?
3
:
2
;
this
.
attacker
=
_attacker
;
//서버 사용하게 되면 PlayerTyping을 피격자의 것으로 바꿔야 함
this
.
counterTime
=
WordSpace
.
gameTimer
.
now
+
1000
*
(
this
.
wordTyping
<=
(
5
-
_wordGrade
)
*
2.5
?
this
.
wordTyping
*
(
WordSpace
.
playerTyping
/
60
)
*
2
:
((
5
-
_wordGrade
)
*
2.5
+
(
this
.
wordTyping
-
(
5
-
_wordGrade
)
*
2.5
)
*
3
)
*
(
WordSpace
.
playerTyping
/
60
)
*
2
);
console
.
log
(
'
Attack text :
'
+
text
+
'
, Attacker :
'
+
this
.
attacker
+
'
, Weight :
'
+
this
.
wordWeight
);
console
.
log
(
'
Counter time :
'
+
this
.
counterTime
);
}
destroy
()
{
switch
(
this
.
wordGrade
)
{
case
0
:
WordSpace
.
attackGauge
.
add
(
2.5
);
break
;
case
1
:
WordSpace
.
attackGauge
.
add
(
1.5
);
break
;
case
2
:
WordSpace
.
attackGauge
.
add
(
0.9
);
break
;
case
3
:
WordSpace
.
attackGauge
.
add
(
0.5
);
break
;
default
:
console
.
log
(
'
[ERR] wrong grade of word
'
);
break
;
}
if
(
WordSpace
.
gameTimer
.
now
<
this
.
counterTime
)
WordSpace
.
generateWord
.
Name
(
WordSpace
.
gameSceneForTest
,
true
);
super
.
destroy
();
}
}
class
NameWord
extends
WordObject
{
constructor
(
text
,
_isStrong
=
false
)
{
super
(
text
);
this
.
wordWeight
=
2
;
this
.
isStrong
=
_isStrong
;
console
.
log
(
'
Name :
'
+
text
+
'
, Strong :
'
+
this
.
isStrong
+
'
, Weight :
'
+
this
.
wordWeight
);
}
destroy
()
{
WordSpace
.
attackGauge
.
add
(
this
.
wordTyping
*
0.1
);
WordSpace
.
nameGroup
.
push
(
this
);
super
.
destroy
();
}
}
js/WordReader.js
View file @
59dde809
...
...
@@ -39,6 +39,7 @@ WordReader.getWordTyping = function(stringText)
var
temp
=
0
;
for
(
var
i
=
0
;
i
<
stringText
.
length
;
i
++
)
{
if
(
stringText
.
charCodeAt
(
i
)
<
parseInt
(
'
0xac00
'
,
16
)
||
stringText
.
charCodeAt
(
i
)
>
parseInt
(
'
0xd7af
'
,
16
))
return
-
1
;
temp
+=
parseFloat
(
firstSound
(
stringText
.
charAt
(
i
)))
+
middleSound
(
stringText
.
charAt
(
i
))
+
lastSound
(
stringText
.
charAt
(
i
));
}
return
temp
;
...
...
@@ -47,9 +48,10 @@ WordReader.getWordTyping = function(stringText)
//입력 받은 단어의 등급을 반환함
WordReader
.
getWordGrade
=
function
(
_wordTyping
)
{
return
2
<=
_wordTyping
&&
_wordTyping
<
7
?
3
:
7
<=
_wordTyping
&&
_wordTyping
<
12
?
2
:
12
<=
_wordTyping
&&
_wordTyping
<
17
?
1
:
0
;
return
4
<=
_wordTyping
&&
_wordTyping
<
7
?
3
:
7
<=
_wordTyping
&&
_wordTyping
<
12
?
2
:
12
<=
_wordTyping
&&
_wordTyping
<
17
?
1
:
17
<=
_wordTyping
&&
_wordTyping
<
26
?
0
:
-
1
;
}
WordReader
.
getWordWeight
=
function
(
_wordGrade
)
...
...
js/WordSpace.js
View file @
59dde809
...
...
@@ -3,44 +3,179 @@ var WordSpace = WordSpace || {};
// for test
WordSpace
.
gameSceneForTest
=
null
;
WordSpace
.
weightTextObjForTest
=
null
;
WordSpace
.
nameWordTextForTest
=
null
;
WordSpace
.
isImageLoaded
=
false
;
WordSpace
.
nextWordCode
=
0
;
WordSpace
.
totalWeight
=
0
;
//현재 단어 무게 총합
WordSpace
.
brainCapacity
=
100
;
//수용 가능한 단어 무게 최대치
WordSpace
.
defeatTime
=
5000
;
WordSpace
.
game
OverTimer
=
null
;
//게임 오버 판정
타이머
WordSpace
.
totalWordNum
=
0
;
WordSpace
.
brainCapacity
=
200
;
//수용 가능한 단어 무게 최대치
WordSpace
.
game
Timer
=
null
;
//현재 게임 플레이 시간
타이머
WordSpace
.
isTimerOn
=
false
;
WordSpace
.
wordGroup
=
[];
WordSpace
.
nameGroup
=
[];
WordSpace
.
wordForcedGroup
=
[];
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
.
playerTyping
=
0
;
WordSpace
.
playerTypingRate
=
0
;
WordSpace
.
delay
=
{
WordSpawn
:
3000
,
NameSpawn
:
3000
,
GameOver
:
5000
,
}
WordSpace
.
NameSpawnReduce
=
1000
;
WordSpace
.
gravityPoint
=
{
x
:
640
,
y
:
300
};
WordSpace
.
getSpawnPoint
=
function
()
class
Cycle
//앞으로 cycle은 이 클래스를 사용해서 구현할 것
{
constructor
(
_callback
)
{
this
.
delay
=
0
;
this
.
currentCycle
=
null
;
this
.
callbackFunction
=
_callback
;
}
resetCycle
(
scene
,
_delay
,
_startAt
,
_loop
)
{
this
.
delay
=
_delay
;
var
option
=
{
startAt
:
_startAt
,
delay
:
_delay
,
callback
:
this
.
callbackFunction
,
callbackScope
:
scene
,
loop
:
_loop
};
if
(
this
.
currentCycle
!=
null
)
this
.
currentCycle
=
this
.
currentCycle
.
reset
(
option
);
else
this
.
currentCycle
=
scene
.
time
.
addEvent
(
option
);
}
}
//단어 생성 사이클
WordSpace
.
wordCycle
=
new
Cycle
(
function
()
{
WordSpace
.
genWordByProb
(
this
);
});
//게임 오버 사이클
WordSpace
.
gameOverCycle
=
new
Cycle
(
gameOver
);
//호패 생성 사이클
WordSpace
.
nameCycle
=
new
Cycle
(
function
()
{
WordSpace
.
generateWord
.
Name
(
WordSpace
.
gameSceneForTest
,
false
);
});
//이건 뭐지
WordSpace
.
varAdjustCycle
=
new
Cycle
(
function
()
{
//나중에는 메세지 분석해서 Phase랑 playerTypingRate 받겠지만 일단 이렇게 해둠
//WordSpace.GetPhase();
//WordSpace.GetPlayerTypingRate();
WordSpace
.
AdjustVarByPhase
(
WordSpace
.
playerTypingRate
,
WordSpace
.
CurrentPhase
);
});
WordSpace
.
getSpawnPoint
=
function
(
_lenRate
)
{
let
xLen
=
600
;
let
yLen
=
300
;
let
lenRate
=
1
;
if
(
typeof
_lenRate
==
'
number
'
)
lenRate
=
_lenRate
;
let
xLen
=
550
*
lenRate
;
let
yLen
=
350
*
lenRate
;
const
angle
=
Math
.
random
()
*
Math
.
PI
*
2
;
let
_x
=
xLen
*
Math
.
cos
(
angle
)
+
this
.
gravityPoint
.
x
;
let
_y
=
yLen
*
Math
.
sin
(
angle
)
+
this
.
gravityPoint
.
y
;
return
{
x
:
_x
,
y
:
_y
};
}
WordSpace
.
spaceInitiate
=
function
(
scene
)
{
let
arr
=
[
2
,
1
,
3
,
3
,
2
,
2
,
3
,
3
,
2
,
3
]
let
lenRate
=
1
;
arr
.
forEach
(
function
(
element
)
{
WordSpace
.
generateWord
.
Normal
(
scene
,
element
,
lenRate
);
//WordSpace.generateWord(scene, SelectWord.selectWord(element),'',lenRate);
lenRate
+=
0.2
;
});
}
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
)
{
WordSpace
.
delay
.
WordSpawn
=
3000
;
WordSpace
.
delay
.
NameSpawn
=
6000
;
WordSpace
.
NameSpawnReduce
=
1000
;
WordSpace
.
GradeProb
[
0
]
=
0.35
;
WordSpace
.
GradeProb
[
1
]
=
1
-
0.4
*
typingRate
;
WordSpace
.
GradeProb
[
2
]
=
1
;
}
else
if
(
phase
==
WordSpace
.
Phase
.
MAIN
)
{
WordSpace
.
delay
.
WordSpawn
=
3000
-
typingRate
*
1000
;
WordSpace
.
delay
.
NameSpawn
=
6000
;
WordSpace
.
NameSpawnReduce
=
1000
;
WordSpace
.
GradeProb
[
0
]
=
0.4
-
0.4
*
typingRate
;
WordSpace
.
GradeProb
[
1
]
=
0.8
-
0.4
*
typingRate
;
WordSpace
.
GradeProb
[
2
]
=
1
-
0.2
*
typingRate
;
}
else
if
(
phase
==
WordSpace
.
Phase
.
MUSIC
)
{
WordSpace
.
delay
.
WordSpawn
=
1500
;
WordSpace
.
delay
.
NameSpawn
=
4000
;
WordSpace
.
NameSpawnReduce
=
500
;
WordSpace
.
GradeProb
[
0
]
=
0.2
-
0.2
*
typingRate
;
WordSpace
.
GradeProb
[
1
]
=
0.8
-
0.5
*
typingRate
;
WordSpace
.
GradeProb
[
2
]
=
0.9
-
0.2
*
typingRate
;
}
WordSpace
.
wordCycle
.
resetCycle
(
WordSpace
.
gameSceneForTest
,
WordSpace
.
delay
.
WordSpawn
,
WordSpace
.
wordCycle
.
currentCycle
.
getElapsed
(),
true
);
WordSpace
.
nameCycle
.
resetCycle
(
WordSpace
.
gameSceneForTest
,
WordSpace
.
delay
.
NameSpawn
,
WordSpace
.
nameCycle
.
currentCycle
.
getElapsed
(),
true
);
}
WordSpace
.
attackGauge
=
{
value
:
0
,
gradeColor
:
[
'
#111124
'
,
'
#EBB435
'
,
'
#A42FFF
'
,
'
#1D22EB
'
,
'
#83947F
'
],
setRect
:
function
()
{
this
.
rectUI
.
setSize
(
20
*
this
.
value
,
11
);
this
.
rectUI
.
setPosition
(
640
-
10
*
this
.
value
,
597
);
let
tmp
=
this
.
getAttackOption
();
this
.
rectUI
.
setFillStyle
(
Phaser
.
Display
.
Color
.
HexStringToColor
(
this
.
gradeColor
[
tmp
.
wordGrade
+
1
]).
color
);
},
generate
:
function
(
scene
)
{
//console.log("created");
this
.
rectUI
=
scene
.
add
.
rectangle
(
640
,
600
,
0
,
11
).
setDepth
(
11
);
},
add
:
function
(
plus
)
{
if
(
this
.
value
+
plus
>
11
)
this
.
value
=
11
;
else
this
.
value
+=
plus
;
this
.
setRect
();
this
.
text
.
setText
(
'
게이지:
'
+
this
.
value
.
toFixed
(
1
));
},
sub
:
function
(
minus
)
{
if
(
this
.
value
-
minus
<
0
)
this
.
value
=
0
;
else
this
.
value
-=
minus
;
this
.
setRect
();
this
.
text
.
setText
(
'
게이지:
'
+
this
.
value
.
toFixed
(
1
));
},
resetValue
:
function
()
{
this
.
value
=
0
;},
...
...
@@ -59,6 +194,7 @@ WordSpace.attackGauge =
this
.
currentCycle
=
scene
.
time
.
addEvent
(
option
);
this
.
text
=
scene
.
add
.
text
(
100
,
100
,
'
게이지:
'
+
this
.
value
.
toFixed
(
1
)).
setDepth
(
10
).
setColor
(
'
#000000
'
);
//this.rectUI.setColor(this.gradeColor[0]);
},
pauseCycle
:
function
(
bool
)
{
this
.
currentCycle
.
paused
=
bool
;},
// showValue: 아래쪽에 바의 길이로 게이지 표시, 색으로 게이지의 강도 표현
...
...
@@ -72,33 +208,14 @@ WordSpace.attackGauge =
}
}
WordSpace
.
wordCycle
=
WordSpace
.
genWordByProb
=
function
(
scene
)
{
delay
:
0
,
currentCycle
:
null
,
resetCycle
:
function
(
scene
,
_delay
)
{
this
.
delay
=
_delay
;
var
option
=
{
delay
:
_delay
,
callback
:
function
()
{
let
wordIdx
=
Math
.
floor
(
Math
.
random
()
*
4
);
WordSpace
.
generateWord
(
this
,
SelectWord
.
selectWord
(
wordIdx
));
},
callbackScope
:
scene
,
loop
:
true
};
if
(
this
.
currentCycle
!=
null
)
{
this
.
currentCycle
=
this
.
currentCycle
.
reset
(
option
);
}
else
{
this
.
currentCycle
=
scene
.
time
.
addEvent
(
option
);
}
},
let
wordRnd
=
Math
.
random
();
let
wordIdx
=
wordRnd
<
WordSpace
.
GradeProb
[
0
]
?
3
:
wordRnd
<
WordSpace
.
GradeProb
[
1
]
?
2
:
wordRnd
<
WordSpace
.
GradeProb
[
2
]
?
1
:
0
;
WordSpace
.
generateWord
.
Normal
(
scene
,
wordIdx
);
//WordSpace.generateWord(scene, SelectWord.selectWord(wordIdx));
}
WordSpace
.
loadImage
=
function
(
scene
)
...
...
@@ -112,36 +229,53 @@ WordSpace.loadImage = function(scene)
scene
.
load
.
image
((
'
wordBgr
'
+
i
+
'
_
'
+
j
),
(
'
assets/placeholder/
'
+
i
+
'
_
'
+
j
+
'
.png
'
));
}
}
for
(
let
i
=
0
;
i
<
4
;
i
++
)
{
scene
.
load
.
image
(
'
attackAlert
'
+
i
,
'
assets/placeholder/attackalert
'
+
(
i
+
1
)
+
'
.png
'
);
}
}
WordSpace
.
gameSceneForTest
=
scene
;
// for test
WordSpace
.
weightTextObjForTest
=
scene
.
add
.
text
(
100
,
75
,
'
뇌의 무게: (현재) 0 / 100 (전체)
'
).
setDepth
(
10
).
setColor
(
'
#000000
'
);
}
WordSpace
.
generateWord
=
function
(
scene
,
wordText
,
grade
)
WordSpace
.
generateWord
=
{
word
=
new
WordObject
(
wordText
);
if
(
typeof
grade
!=
'
undefined
'
)
Normal
:
function
(
scene
,
grade
,
lenRate
)
{
word
.
wordGrade
=
grade
;
word
.
wordWeight
=
WordReader
.
getWordWeight
(
grade
);
word
=
new
NormalWord
(
SelectWord
.
selectWord
(
grade
));
WordSpace
.
pushWord
(
scene
,
word
,
lenRate
);
},
Attack
:
function
(
scene
,
wordText
,
grade
,
attacker
,
isStrong
,
lenRate
)
{
word
=
new
AttackWord
(
wordText
,
grade
,
attacker
,
isStrong
);
WordSpace
.
pushWord
(
scene
,
word
,
lenRate
);
},
Name
:
function
(
scene
,
isStrong
,
lenRate
)
{
//To do
word
=
new
NameWord
(
PlayerData
.
nickname
,
isStrong
);
WordSpace
.
pushWord
(
scene
,
word
,
lenRate
);
}
word
.
instantiate
(
scene
);
}
WordSpace
.
pushWord
=
function
(
scene
,
word
,
lenRate
)
{
word
.
instantiate
(
scene
,
lenRate
);
WordSpace
.
wordGroup
.
push
(
word
);
WordSpace
.
wordForcedGroup
.
push
(
word
);
word
.
physicsObj
.
topObj
=
word
;
scene
.
physics
.
add
.
collider
(
word
.
physicsObj
,
WordSpace
.
wordPhysicsGroup
,
function
(
object1
)
{
object1
.
topObj
.
wordSpeed
=
0.1
;
//
object1.topObj.wordSpeed = 0.1;
object1
.
topObj
.
attract
();
});
WordSpace
.
wordPhysicsGroup
.
add
(
word
.
physicsObj
);
WordSpace
.
weightTextObjForTest
.
setText
(
'
뇌의 무게: (현재)
'
+
WordSpace
.
totalWeight
+
'
/ 100 (전체)
'
);
}
function
gameOver
()
{
WordSpace
.
wordCycle
.
currentCycle
.
remove
();
WordSpace
.
nameCycle
.
currentCycle
.
remove
();
//To Do
console
.
log
(
'
defeat
'
);
}
...
...
@@ -152,25 +286,20 @@ WordSpace.setGameOverTimer = function()
//만약 현재 단어 무게 총합이 뇌 용량보다 크다면 타이머를 시작함
if
(
this
.
brainCapacity
<
this
.
totalWeight
&&
!
this
.
isTimerOn
)
{
var
timer
=
{
delay
:
this
.
defeatTime
,
callback
:
function
()
{
gameOver
();
},
callbackScope
:
WordSpace
.
gameSceneForTest
,
loop
:
false
}
this
.
isTimerOn
=
true
;
this
.
gameOverTimer
=
WordSpace
.
gameSceneForTest
.
time
.
addEvent
(
timer
);
WordSpace
.
gameOverCycle
.
resetCycle
(
WordSpace
.
gameSceneForTest
,
WordSpace
.
delay
.
gameOver
,
0
,
false
);
console
.
log
(
'
Game over timer On
'
);
}
}
WordSpace
.
resetGameOverTimer
=
function
()
{
if
(
this
.
brainCapacity
>=
this
.
totalWeight
&&
this
.
isTimerOn
)
this
.
gameOverTimer
.
remove
();
{
this
.
isTimerOn
=
false
;
WordSpace
.
gameOverCycle
.
currentCycle
.
paused
=
true
;
console
.
log
(
'
Game over timer Off
'
);
}
}
WordSpace
.
findWord
=
function
(
wordText
)
...
...
@@ -186,23 +315,24 @@ WordSpace.findWord = function(wordText)
{
if
(
weightest
.
wordWeight
<
element
.
wordWeight
)
weightest
=
element
;
});
switch
(
weightest
.
wordGrade
)
// 이부분 나중에 더 효율적으로 바꿀수있지 않을까
weightest
.
destroy
();
WordSpace
.
nameCycle
.
resetCycle
(
WordSpace
.
gameSceneForTest
,
WordSpace
.
delay
.
NameSpawn
,
WordSpace
.
nameCycle
.
currentCycle
.
getElapsed
()
+
WordSpace
.
NameSpawnReduce
,
true
);
while
(
WordSpace
.
totalWordNum
<
5
)
{
case
0
:
WordSpace
.
attackGauge
.
add
(
2.5
);
break
;
case
1
:
WordSpace
.
attackGauge
.
add
(
1.5
);
break
;
case
2
:
WordSpace
.
attackGauge
.
add
(
0.9
);
break
;
case
3
:
WordSpace
.
attackGauge
.
add
(
0.5
);
break
;
default
:
console
.
log
(
'
[ERR] wrong grade of word
'
);
break
;
WordSpace
.
genWordByProb
(
WordSpace
.
gameSceneForTest
);
WordSpace
.
wordCycle
.
resetCycle
(
WordSpace
.
gameSceneForTest
,
WordSpace
.
delay
.
WordSpawn
,
0
);
}
weightest
.
destroy
(
);
WordSpace
.
setPlayerTyping
.
add
(
wordText
);
}
else
if
(
wordText
===
'
공격
'
&&
WordSpace
.
attackGauge
.
value
>
3
)
// 공격모드 진입.
else
if
(
wordText
===
'
공격
'
&&
WordSpace
.
attackGauge
.
value
>
=
3
)
// 공격모드 진입.
{
console
.
log
(
'
attack mode
'
);
Input
.
attackOption
=
this
.
attackGauge
.
getAttackOption
();
Input
.
maxInput
=
Input
.
attackOption
.
wordCount
;
Input
.
attackMode
=
true
;
WordSpace
.
attackGauge
.
pauseCycle
(
true
);
WordSpace
.
setPlayerTyping
.
add
(
wordText
);
}
else
{
...
...
@@ -210,15 +340,43 @@ WordSpace.findWord = function(wordText)
}
}
WordSpace
.
setPlayerTyping
=
{
totalTyping
:
0
,
add
:
function
(
wordText
)
{
this
.
totalTyping
+=
wordText
!=
null
?
WordReader
.
getWordTyping
(
wordText
)
:
0
;
WordSpace
.
playerTyping
=
this
.
totalTyping
/
WordSpace
.
gameTimer
.
now
*
60
*
1000
;
socket
.
emit
(
'
setPlayerTyping
'
,
WordSpace
.
playerTyping
);
this
.
text
.
setText
(
'
현재 타수 :
'
+
WordSpace
.
playerTyping
.
toFixed
(
1
));
},
initiate
:
function
(
scene
)
{
WordSpace
.
gameTimer
=
new
Phaser
.
Time
.
Clock
(
scene
);
WordSpace
.
gameTimer
.
start
();
this
.
text
=
scene
.
add
.
text
(
100
,
200
,
'
현재 타수 :
'
+
WordSpace
.
playerTyping
.
toFixed
(
1
)).
setDepth
(
10
).
setColor
(
'
#000000
'
);
}
}
WordSpace
.
attack
=
function
(
wordText
,
grade
)
{
wordText
=
Input
.
removeConVow
(
wordText
);
if
(
wordText
!=
''
)
{
console
.
log
(
'
attack
'
+
wordText
+
'
, grade:
'
+
grade
);
WordSpace
.
generateWord
(
WordSpace
.
gameSceneForTest
,
wordText
,
grade
);
// for test
//호패에 따른 isStrong 구분 필요함
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
WordSpace
.
generateWord
.
Attack
(
WordSpace
.
gameSceneForTest
,
wordText
,
grade
,
PlayerData
.
nickname
,
element
.
isStrong
);
});
WordSpace
.
nameGroup
=
[];
//WordSpace.generateWord(WordSpace.gameSceneForTest, wordText, grade, undefined, true); // for test
// 이부분에서 게이지에 따라 급수 결정
// 이걸 서버로 공격을 보내야 함
// 이부분은 서버 잘써야함
WordSpace
.
attackGauge
.
resetValue
();
WordSpace
.
setPlayerTyping
.
add
(
wordText
);
}
else
{
...
...
js/main.js
View file @
59dde809
...
...
@@ -9,44 +9,20 @@ var config = {
}
},
backgroundColor
:
Phaser
.
Display
.
Color
.
GetColor
(
0
,
0
,
0
),
scene
:
{
preload
:
preload
,
create
:
create
,
update
:
update
}
scene
:
[
menuScene
,
gameScene
]
};
var
game
=
new
Phaser
.
Game
(
config
)
// load assets
function
preload
()
{
BackGround
.
loadImage
(
this
);
WordSpace
.
loadImage
(
this
);
Input
.
inputField
.
loadImage
(
this
);
CSVParsing
.
loadText
(
this
);
}
//플레이어 정보, 서버 통신시 필요할 듯
//테스트용이므로 차후 수정 요망
var
PlayerData
=
PlayerData
||
{};
function
create
()
{
BackGround
.
drawBrain
(
this
);
Input
.
inputField
.
generate
(
this
);
WordSpace
.
wordPhysicsGroup
=
this
.
physics
.
add
.
group
();
WordSpace
.
wordCycle
.
resetCycle
(
this
,
3000
);
WordSpace
.
attackGauge
.
resetCycle
(
this
);
CSVParsing
.
CSVParse
(
this
);
}
PlayerData
.
idNum
=
-
1
;
//플레이어 아이디, 고유 번호
PlayerData
.
nickname
=
'
홍길동
'
;
//플레이어 닉네임
function
update
()
{
WordSpace
.
wordForcedGroup
.
forEach
(
function
(
element
)
{
element
.
attract
();
});
}
// 현재 들어가있는 Game Room의 정보
var
RoomData
=
RoomData
||
{};
var
socket
=
io
.
connect
();
socket
.
on
(
'
hi
'
,
function
(
msg
)
{
console
.
log
(
msg
);
});
socket
.
emit
(
'
hello
'
);
\ No newline at end of file
RoomData
.
roomNum
=
-
1
;
RoomData
.
players
=
null
;
\ No newline at end of file
server.js
View file @
59dde809
...
...
@@ -2,6 +2,7 @@ var express = require('express');
var
app
=
express
();
var
server
=
require
(
'
http
'
).
Server
(
app
);
var
io
=
require
(
'
socket.io
'
).
listen
(
server
);
var
GameServer
=
require
(
'
./GameServer
'
);
app
.
use
(
'
/css
'
,
express
.
static
(
__dirname
+
'
/css
'
));
app
.
use
(
'
/js
'
,
express
.
static
(
__dirname
+
'
/js
'
));
...
...
@@ -13,13 +14,66 @@ app.get('/', function(req, res) {
// http 기본 포트(80)에 서버 열기
server
.
listen
(
80
,
function
()
{
console
.
log
(
'
Listening on port
'
+
server
.
address
().
port
);
console
.
log
(
'
[SERVER]
Listening on port
'
+
server
.
address
().
port
);
});
// 클라이언트 요청에 대한 콜백 정의
io
.
on
(
'
connection
'
,
function
(
socket
)
{
socket
.
on
(
'
hello
'
,
function
()
{
console
.
log
(
'
client request
'
);
socket
.
emit
(
'
hi
'
,
'
Hello, Client!
'
);
io
.
on
(
'
connection
'
,
function
(
socket
)
{
socket
.
on
(
'
idRequest
'
,
function
()
{
socket
.
playerData
=
{
id
:
GameServer
.
getPlayerNumber
(),
nickname
:
'
게스트
'
,
socketId
:
socket
,
currentRoom
:
null
,
playerTyping
:
0
};
GameServer
.
currentPlayer
.
push
(
socket
.
playerData
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client request
'
);
socket
.
emit
(
'
idSet
'
,
{
str
:
'
your number is
'
+
socket
.
playerData
.
id
,
num
:
socket
.
playerData
.
id
});
});
socket
.
on
(
'
setNickname
'
,
function
(
msg
)
// string new_nickname
{
socket
.
playerData
.
nickname
=
msg
;
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] nickname set to
'
+
msg
);
GameServer
.
enterEmptyRoom
(
socket
.
playerData
);
});
socket
.
on
(
'
setPlayerTyping
'
,
function
(
msg
)
// number playerTyping
{
socket
.
playerData
.
playerTyping
=
msg
;
//console.log(socket.playerData.currentRoom);
//console.log(socket.playerData.currentRoom.currentPlayer.length);
//let playerTypingRate = (msg - (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);
});
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
{
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
socket
.
playerData
.
id
;
});
if
(
idxToDel
!=
-
1
)
{
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client disconnected, reason:
'
+
reason
);
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
// 룸에서도 제거
if
(
socket
.
playerData
.
currentRoom
!=
null
)
{
socket
.
playerData
.
playingData
.
isAlive
=
false
;
socket
.
playerData
.
playingData
.
rank
=
socket
.
playerData
.
currentRoom
.
nextRank
--
;
socket
.
playerData
.
currentRoom
.
currentSocket
.
splice
(
socket
.
playerData
.
playingData
.
index
,
1
);
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
socket
.
playerData
.
currentRoom
.
roomNum
),
'
userDisconnect
'
,
socket
.
playerData
.
playingData
);
}
}
});
});
\ 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