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
Expand all
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
가
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 @@
...
@@ -4,6 +4,7 @@
<meta
charset=
"utf-8"
/>
<meta
charset=
"utf-8"
/>
<script
src=
"/socket.io/socket.io.js"
></script>
<script
src=
"/socket.io/socket.io.js"
></script>
<script
src=
"js/phaser.js"
></script>
<script
src=
"js/phaser.js"
></script>
<script
src=
"js/ScenesData.js"
></script>
<script
src=
"js/Background.js"
></script>
<script
src=
"js/Background.js"
></script>
<script
src=
"js/Input.js"
></script>
<script
src=
"js/Input.js"
></script>
<script
src=
"js/WordSpace.js"
></script>
<script
src=
"js/WordSpace.js"
></script>
...
@@ -13,6 +14,7 @@
...
@@ -13,6 +14,7 @@
<script
src=
"js/SelectWord.js"
></script>
<script
src=
"js/SelectWord.js"
></script>
</head>
</head>
<body>
<body>
<script
src=
"js/Client.js"
></script>
<script
src=
"js/Main.js"
></script>
<script
src=
"js/Main.js"
></script>
</body>
</body>
</html>
</html>
\ No newline at end of file
js/Background.js
View file @
59dde809
var
BackGround
=
BackGround
||
{}
var
BackGround
=
BackGround
||
{}
BackGround
.
isImageLoaded
=
false
;
BackGround
.
brainGroup
=
null
;
BackGround
.
brainGroup
=
null
;
BackGround
.
loadImage
=
function
(
scene
)
BackGround
.
loadImage
=
function
(
scene
)
{
{
if
(
!
this
.
isImageLoaded
)
scene
.
load
.
image
(
'
brainGround
'
,
'
assets/placeholder/playback.png
'
);
{
scene
.
load
.
image
(
'
menuBackground
'
,
'
assets/placeholder/menuBackground.png
'
)
scene
.
load
.
image
(
'
brainGround0
'
,
'
assets/placeholder/playback.png
'
);
}
}
}
BackGround
.
drawBrain
=
function
(
scene
)
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) {
...
@@ -27,7 +27,7 @@ CSVParsing.CSVParse = function(scene) {
CSVParsing
.
gradeArray
.
grade2
.
push
(
allRows
[
singleRow
].
trim
());
CSVParsing
.
gradeArray
.
grade2
.
push
(
allRows
[
singleRow
].
trim
());
}
else
if
(
grade
==
1
)
{
}
else
if
(
grade
==
1
)
{
CSVParsing
.
gradeArray
.
grade1
.
push
(
allRows
[
singleRow
].
trim
());
CSVParsing
.
gradeArray
.
grade1
.
push
(
allRows
[
singleRow
].
trim
());
}
else
{
}
else
if
(
grade
==
0
)
{
CSVParsing
.
gradeArray
.
grade0
.
push
(
allRows
[
singleRow
].
trim
());
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 = [];
...
@@ -4,6 +4,7 @@ Input.input = [];
Input
.
convInput
=
''
;
// converted input
Input
.
convInput
=
''
;
// converted input
Input
.
isShifted
=
false
;
Input
.
isShifted
=
false
;
Input
.
isEntered
=
false
;
Input
.
pressCount
=
0
;
Input
.
pressCount
=
0
;
Input
.
justPressed
=
''
;
Input
.
justPressed
=
''
;
Input
.
maxInput
=
5
;
Input
.
maxInput
=
5
;
...
@@ -11,6 +12,34 @@ Input.maxInput = 5;
...
@@ -11,6 +12,34 @@ Input.maxInput = 5;
Input
.
attackMode
=
false
;
Input
.
attackMode
=
false
;
Input
.
attackOption
=
null
;
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
.
reset
=
function
()
{
{
Input
.
input
=
[];
Input
.
input
=
[];
...
@@ -275,7 +304,7 @@ Input.removeConVow = function(_wordText)
...
@@ -275,7 +304,7 @@ Input.removeConVow = function(_wordText)
Input
.
inputField
=
Input
.
inputField
=
{
{
generate
:
function
(
scene
)
generate
:
function
(
scene
,
enterCallback
)
{
{
this
.
background
=
scene
.
add
.
sprite
(
640
,
550
,
'
inputfield
'
).
setDepth
(
10
);
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
);
this
.
text
=
scene
.
add
.
text
(
640
,
550
,
"
안녕하세요
"
,
{
font
:
'
25pt 궁서
'
}).
setOrigin
(
0.5
,
0.5
).
setColor
(
'
#000000
'
).
setDepth
(
10
);
...
@@ -293,13 +322,8 @@ Input.inputField =
...
@@ -293,13 +322,8 @@ Input.inputField =
Input
.
inputField
.
text
.
setText
(
Input
.
convInput
);
Input
.
inputField
.
text
.
setText
(
Input
.
convInput
);
}
}
});
});
scene
.
input
.
keyboard
.
on
(
'
keydown-ENTER
'
,
function
()
scene
.
input
.
keyboard
.
on
(
'
keydown-ENTER
'
,
enterCallback
);
{
scene
.
input
.
keyboard
.
on
(
'
keyup-ENTER
'
,
function
(){
Input
.
isEntered
=
false
;})
if
(
Input
.
attackMode
)
WordSpace
.
attack
(
Input
.
convInput
,
Input
.
attackOption
.
wordGrade
);
else
WordSpace
.
findWord
(
Input
.
convInput
);
WordSpace
.
resetGameOverTimer
();
Input
.
reset
();
});
// upside 10 keys
// upside 10 keys
scene
.
input
.
keyboard
.
on
(
'
keydown-Q
'
,
function
()
{
Input
.
pushInput
(
'
ㅂ
'
)});
scene
.
input
.
keyboard
.
on
(
'
keydown-Q
'
,
function
()
{
Input
.
pushInput
(
'
ㅂ
'
)});
scene
.
input
.
keyboard
.
on
(
'
keydown-W
'
,
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
...
@@ -4,23 +4,33 @@ class WordObject
{
{
this
.
generationCode
=
WordSpace
.
nextWordCode
++
;
this
.
generationCode
=
WordSpace
.
nextWordCode
++
;
this
.
wordText
=
text
;
this
.
wordText
=
text
;
//this.wordText = Input.removeConVow(text);
this
.
wordTyping
=
WordReader
.
getWordTyping
(
this
.
wordText
);
this
.
wordTyping
=
WordReader
.
getWordTyping
(
this
.
wordText
);
this
.
wordGrade
=
WordReader
.
getWordGrade
(
this
.
wordTyping
);
this
.
wordGrade
=
WordReader
.
getWordGrade
(
this
.
wordTyping
);
this
.
wordWeight
=
WordReader
.
getWordWeight
(
this
.
wordGrade
);
this
.
wordWeight
=
WordReader
.
getWordWeight
(
this
.
wordGrade
);
//console.log("wordTyping : " + this.wordTyping + '\n' + "wordGrade : " + this.wordGrade + '\n' + "wordWeight : " + this.wordWeight + '\n');
//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
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
scale
=
((
p
[
1
].
y
-
p
[
0
].
y
)
/
(
p
[
1
].
x
-
p
[
0
].
x
))
*
(
this
.
wordWeight
-
p
[
0
].
x
)
+
p
[
0
].
y
;
let
fontscale
=
25
;
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
))
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
)
.
setMass
(
this
.
wordWeight
*
10
)
.
setScale
(
scale
);
.
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
,
this
.
wordObj
=
scene
.
add
.
text
(
random
.
x
,
random
.
y
,
this
.
wordText
,
{
{
...
@@ -29,6 +39,7 @@ class WordObject
...
@@ -29,6 +39,7 @@ class WordObject
fontStyle
:
(
this
.
wordWeight
>
5
?
'
bold
'
:
''
)
fontStyle
:
(
this
.
wordWeight
>
5
?
'
bold
'
:
''
)
}).
setColor
(
'
#000000
'
).
setOrigin
(
0.5
,
0.5
);
}).
setColor
(
'
#000000
'
).
setOrigin
(
0.5
,
0.5
);
WordSpace
.
totalWeight
+=
this
.
wordWeight
;
WordSpace
.
totalWeight
+=
this
.
wordWeight
;
WordSpace
.
totalWordNum
+=
1
;
WordSpace
.
setGameOverTimer
();
WordSpace
.
setGameOverTimer
();
//console.log("Total weight : " + WordSpace.totalWeight);
//console.log("Total weight : " + WordSpace.totalWeight);
}
}
...
@@ -37,6 +48,8 @@ class WordObject
...
@@ -37,6 +48,8 @@ class WordObject
{
{
console
.
log
(
this
.
generationCode
+
'
:
'
+
this
.
wordText
+
'
destroyed
'
);
console
.
log
(
this
.
generationCode
+
'
:
'
+
this
.
wordText
+
'
destroyed
'
);
WordSpace
.
totalWeight
-=
this
.
wordWeight
;
WordSpace
.
totalWeight
-=
this
.
wordWeight
;
WordSpace
.
totalWordNum
-=
1
;
WordSpace
.
resetGameOverTimer
();
this
.
wordObj
.
destroy
();
this
.
wordObj
.
destroy
();
const
groupIdx
=
WordSpace
.
wordGroup
.
findIndex
(
function
(
item
)
{
return
this
.
isEqualObject
(
item
.
generationCode
)},
this
);
const
groupIdx
=
WordSpace
.
wordGroup
.
findIndex
(
function
(
item
)
{
return
this
.
isEqualObject
(
item
.
generationCode
)},
this
);
if
(
groupIdx
>
-
1
)
WordSpace
.
wordGroup
.
splice
(
groupIdx
,
1
);
if
(
groupIdx
>
-
1
)
WordSpace
.
wordGroup
.
splice
(
groupIdx
,
1
);
...
@@ -45,13 +58,105 @@ class WordObject
...
@@ -45,13 +58,105 @@ class WordObject
WordSpace
.
wordPhysicsGroup
.
remove
(
this
.
physicsObj
,
true
,
true
);
WordSpace
.
wordPhysicsGroup
.
remove
(
this
.
physicsObj
,
true
,
true
);
}
}
attract
()
attract
()
{
{
var
dist
=
Phaser
.
Math
.
Distance
.
Between
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
,
WordSpace
.
gravityPoint
.
x
,
WordSpace
.
gravityPoint
.
y
);
if
(
!
this
.
moveStarted
)
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
);
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
);
this
.
wordObj
.
setPosition
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
);
}
}
isEqualObject
(
_generationCode
)
{
return
_generationCode
===
this
.
generationCode
;
}
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)
...
@@ -39,6 +39,7 @@ WordReader.getWordTyping = function(stringText)
var
temp
=
0
;
var
temp
=
0
;
for
(
var
i
=
0
;
i
<
stringText
.
length
;
i
++
)
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
));
temp
+=
parseFloat
(
firstSound
(
stringText
.
charAt
(
i
)))
+
middleSound
(
stringText
.
charAt
(
i
))
+
lastSound
(
stringText
.
charAt
(
i
));
}
}
return
temp
;
return
temp
;
...
@@ -47,9 +48,10 @@ WordReader.getWordTyping = function(stringText)
...
@@ -47,9 +48,10 @@ WordReader.getWordTyping = function(stringText)
//입력 받은 단어의 등급을 반환함
//입력 받은 단어의 등급을 반환함
WordReader
.
getWordGrade
=
function
(
_wordTyping
)
WordReader
.
getWordGrade
=
function
(
_wordTyping
)
{
{
return
2
<=
_wordTyping
&&
_wordTyping
<
7
?
3
:
return
4
<=
_wordTyping
&&
_wordTyping
<
7
?
3
:
7
<=
_wordTyping
&&
_wordTyping
<
12
?
2
:
7
<=
_wordTyping
&&
_wordTyping
<
12
?
2
:
12
<=
_wordTyping
&&
_wordTyping
<
17
?
1
:
0
;
12
<=
_wordTyping
&&
_wordTyping
<
17
?
1
:
17
<=
_wordTyping
&&
_wordTyping
<
26
?
0
:
-
1
;
}
}
WordReader
.
getWordWeight
=
function
(
_wordGrade
)
WordReader
.
getWordWeight
=
function
(
_wordGrade
)
...
...
js/WordSpace.js
View file @
59dde809
This diff is collapsed.
Click to expand it.
js/main.js
View file @
59dde809
...
@@ -9,44 +9,20 @@ var config = {
...
@@ -9,44 +9,20 @@ var config = {
}
}
},
},
backgroundColor
:
Phaser
.
Display
.
Color
.
GetColor
(
0
,
0
,
0
),
backgroundColor
:
Phaser
.
Display
.
Color
.
GetColor
(
0
,
0
,
0
),
scene
:
{
scene
:
[
menuScene
,
gameScene
]
preload
:
preload
,
create
:
create
,
update
:
update
}
};
};
var
game
=
new
Phaser
.
Game
(
config
)
var
game
=
new
Phaser
.
Game
(
config
)
// load assets
//플레이어 정보, 서버 통신시 필요할 듯
function
preload
()
//테스트용이므로 차후 수정 요망
{
var
PlayerData
=
PlayerData
||
{};
BackGround
.
loadImage
(
this
);
WordSpace
.
loadImage
(
this
);
Input
.
inputField
.
loadImage
(
this
);
CSVParsing
.
loadText
(
this
);
}
function
create
()
PlayerData
.
idNum
=
-
1
;
//플레이어 아이디, 고유 번호
{
PlayerData
.
nickname
=
'
홍길동
'
;
//플레이어 닉네임
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
);
}
function
update
()
// 현재 들어가있는 Game Room의 정보
{
var
RoomData
=
RoomData
||
{};
WordSpace
.
wordForcedGroup
.
forEach
(
function
(
element
)
{
element
.
attract
();
});
}
var
socket
=
io
.
connect
();
RoomData
.
roomNum
=
-
1
;
socket
.
on
(
'
hi
'
,
function
(
msg
)
{
RoomData
.
players
=
null
;
console
.
log
(
msg
);
\ No newline at end of file
});
socket
.
emit
(
'
hello
'
);
\ No newline at end of file
server.js
View file @
59dde809
...
@@ -2,6 +2,7 @@ var express = require('express');
...
@@ -2,6 +2,7 @@ var express = require('express');
var
app
=
express
();
var
app
=
express
();
var
server
=
require
(
'
http
'
).
Server
(
app
);
var
server
=
require
(
'
http
'
).
Server
(
app
);
var
io
=
require
(
'
socket.io
'
).
listen
(
server
);
var
io
=
require
(
'
socket.io
'
).
listen
(
server
);
var
GameServer
=
require
(
'
./GameServer
'
);
app
.
use
(
'
/css
'
,
express
.
static
(
__dirname
+
'
/css
'
));
app
.
use
(
'
/css
'
,
express
.
static
(
__dirname
+
'
/css
'
));
app
.
use
(
'
/js
'
,
express
.
static
(
__dirname
+
'
/js
'
));
app
.
use
(
'
/js
'
,
express
.
static
(
__dirname
+
'
/js
'
));
...
@@ -13,13 +14,66 @@ app.get('/', function(req, res) {
...
@@ -13,13 +14,66 @@ app.get('/', function(req, res) {
// http 기본 포트(80)에 서버 열기
// http 기본 포트(80)에 서버 열기
server
.
listen
(
80
,
function
()
{
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
)
{
io
.
on
(
'
connection
'
,
function
(
socket
)
socket
.
on
(
'
hello
'
,
function
()
{
{
console
.
log
(
'
client request
'
);
socket
.
on
(
'
idRequest
'
,
function
()
{
socket
.
emit
(
'
hi
'
,
'
Hello, Client!
'
);
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