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
80a36517
Commit
80a36517
authored
Jul 09, 2019
by
18류지석
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'wordspace'
parents
150bcf6c
682e7530
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
180 additions
and
54 deletions
+180
-54
GameServer.js
GameServer.js
+9
-1
Client.js
js/Client.js
+16
-6
ScenesData.js
js/ScenesData.js
+11
-1
WordObject.js
js/WordObject.js
+12
-9
WordReader.js
js/WordReader.js
+4
-4
WordSpace.js
js/WordSpace.js
+108
-26
main.js
js/main.js
+3
-1
server.js
server.js
+17
-6
No files found.
GameServer.js
View file @
80a36517
var
GameServer
=
GameServer
||
{};
var
GameServer
=
GameServer
||
{};
GameServer
.
Phase
=
{
READY
:
0
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
Phase
=
{
READY
:
0
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
startCount
=
1
;
GameServer
.
startCount
=
3
;
GameServer
.
currentPlayer
=
[];
GameServer
.
currentPlayer
=
[];
GameServer
.
playingRoom
=
[];
GameServer
.
playingRoom
=
[];
...
@@ -112,6 +112,14 @@ GameServer.announceToRoom = function(roomIdx, _message, _data = null)
...
@@ -112,6 +112,14 @@ GameServer.announceToRoom = function(roomIdx, _message, _data = null)
element
.
socketId
.
emit
(
_message
,
_data
);
element
.
socketId
.
emit
(
_message
,
_data
);
});
});
}
}
GameServer
.
announceToTarget
=
function
(
roomIdx
,
targetNum
,
_message
,
_data
=
null
)
{
let
targetSocket
=
this
.
playingRoom
[
roomIdx
].
currentSocket
.
find
(
function
(
element
)
{
return
element
.
id
===
targetNum
;
}).
socketId
;
targetSocket
.
emit
(
_message
,
_data
);
}
// 데이터 동기화 함수 만들기
// 데이터 동기화 함수 만들기
// 동기화할것: 유저리스트(id - nickname 쌍)
// 동기화할것: 유저리스트(id - nickname 쌍)
...
...
js/Client.js
View file @
80a36517
var
socket
=
io
.
connect
();
var
socket
=
io
.
connect
();
// init account
socket
.
emit
(
'
idRequest
'
);
socket
.
emit
(
'
idRequest
'
);
socket
.
on
(
'
setId
'
,
function
(
msg
)
// {str, num playerNum}
socket
.
on
(
'
setId
'
,
function
(
msg
)
// {str, num playerNum}
{
{
console
.
log
(
msg
.
str
);
console
.
log
(
msg
.
str
);
PlayerData
.
idNum
=
msg
.
num
;
PlayerData
.
idNum
=
msg
.
num
;
});
});
socket
.
on
(
'
setPlayerTypingRate
'
,
function
(
msg
)
// number playerTypingRate
{
WordSpace
.
PlayerTypingRate
=
msg
;
console
.
log
(
'
rate:
'
+
msg
);
});
// init game
socket
.
on
(
'
syncRoomData
'
,
function
(
msg
)
// {num roomNum, [] players}
socket
.
on
(
'
syncRoomData
'
,
function
(
msg
)
// {num roomNum, [] players}
{
{
console
.
log
(
msg
);
console
.
log
(
msg
);
RoomData
.
roomNum
=
msg
.
roomNum
;
RoomData
.
roomNum
=
msg
.
roomNum
;
RoomData
.
players
=
msg
.
players
;
RoomData
.
players
=
msg
.
players
;
RoomData
.
aliveCount
=
msg
.
players
.
length
;
});
});
socket
.
on
(
'
startGame
'
,
function
()
socket
.
on
(
'
startGame
'
,
function
()
{
{
game
.
scene
.
start
(
'
gameScene
'
);
game
.
scene
.
start
(
'
gameScene
'
);
});
});
// in game
socket
.
on
(
'
changePhase
'
,
function
(
msg
)
// number Phase
socket
.
on
(
'
changePhase
'
,
function
(
msg
)
// number Phase
{
{
console
.
log
(
'
phase changed from
'
+
WordSpace
.
CurrentPhase
+
'
to
'
+
msg
);
console
.
log
(
'
phase changed from
'
+
WordSpace
.
CurrentPhase
+
'
to
'
+
msg
);
WordSpace
.
CurrentPhase
=
msg
;
WordSpace
.
CurrentPhase
=
msg
;
});
});
socket
.
on
(
'
setPlayerTypingRate
'
,
function
(
msg
)
// number playerTypingRate
{
WordSpace
.
PlayerTypingRate
=
msg
;
//console.log('rate: ' + msg);
});
socket
.
on
(
'
attacked
'
,
function
(
msg
)
// object attackData
{
WordSpace
.
generateWord
.
Attack
(
WordSpace
.
gameSceneForTest
,
msg
.
text
,
msg
.
grade
,
msg
.
attacker
,
msg
.
isStrong
);
});
// out game
socket
.
on
(
'
userDisconnect
'
,
function
(
msg
)
// {num index , num id, str nickname}
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
].
isAlive
=
false
;
RoomData
.
players
[
msg
.
index
].
isAlive
=
false
;
RoomData
.
aliveCount
--
;
});
});
\ No newline at end of file
js/ScenesData.js
View file @
80a36517
...
@@ -60,6 +60,16 @@ var gameScene = new Phaser.Class(
...
@@ -60,6 +60,16 @@ var gameScene = new Phaser.Class(
WordSpace
.
setPlayerTyping
.
initiate
(
this
);
WordSpace
.
setPlayerTyping
.
initiate
(
this
);
WordSpace
.
nameWordTextForTest
=
WordSpace
.
gameSceneForTest
.
add
.
text
(
50
,
400
,
'
현재 가진 호패들 : 없음
'
).
setDepth
(
10
).
setColor
(
'
#000000
'
);
WordSpace
.
nameWordTextForTest
=
WordSpace
.
gameSceneForTest
.
add
.
text
(
50
,
400
,
'
현재 가진 호패들 : 없음
'
).
setDepth
(
10
).
setColor
(
'
#000000
'
);
WordSpace
.
nameQueue
.
initiate
();
RoomData
.
players
.
forEach
(
function
(
element
)
{
if
(
element
.
nickname
==
PlayerData
.
nickname
)
{
RoomData
.
myself
=
element
;
return
;
}
});
console
.
log
(
RoomData
.
myself
);
},
},
update
:
function
()
update
:
function
()
...
@@ -71,7 +81,7 @@ var gameScene = new Phaser.Class(
...
@@ -71,7 +81,7 @@ var gameScene = new Phaser.Class(
let
tempNames
=
''
;
let
tempNames
=
''
;
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
{
tempNames
+=
element
.
wordText
+
'
\n
'
;
tempNames
+=
element
.
wordText
+
element
.
isStrong
+
'
\n
'
;
});
});
WordSpace
.
nameWordTextForTest
.
setText
(
'
현재 가진 호패들 :
\n
'
+
tempNames
);
WordSpace
.
nameWordTextForTest
.
setText
(
'
현재 가진 호패들 :
\n
'
+
tempNames
);
...
...
js/WordObject.js
View file @
80a36517
...
@@ -114,19 +114,19 @@ class NormalWord extends WordObject
...
@@ -114,19 +114,19 @@ class NormalWord extends WordObject
class
AttackWord
extends
WordObject
class
AttackWord
extends
WordObject
{
{
constructor
(
text
,
_wordGrade
,
_
attacker
,
isStrong
)
constructor
(
text
,
_wordGrade
,
_
playerData
,
isStrong
)
{
{
super
(
text
);
super
(
text
);
this
.
wordGrade
=
_wordGrade
;
this
.
wordGrade
=
_wordGrade
;
this
.
wordWeight
=
WordReader
.
getWordWeight
(
this
.
wordGrade
);
this
.
wordWeight
=
WordReader
.
getWordWeight
(
this
.
wordGrade
);
if
(
WordReader
.
getWordTyping
(
_
attacker
)
<=
9
)
if
(
WordReader
.
getWordTyping
(
_
playerData
.
nickname
)
<=
9
)
this
.
wordWeight
+=
this
.
wordWeight
*
0.2
*
(
WordReader
.
getWordTyping
(
P
layerData
.
nickname
)
-
9
);
this
.
wordWeight
+=
this
.
wordWeight
*
0.2
*
(
WordReader
.
getWordTyping
(
_p
layerData
.
nickname
)
-
9
);
this
.
wordWeight
*=
isStrong
?
3
:
2
;
this
.
wordWeight
*=
isStrong
?
3
:
2
;
this
.
attacker
=
_
attacker
;
this
.
attacker
=
_
playerData
;
//서버 사용하게 되면 PlayerTyping을 피격자의 것으로 바꿔야 함
//서버 사용하게 되면 PlayerTyping을 피격자의 것으로 바꿔야 함
this
.
counterTime
=
WordSpace
.
gameTimer
.
now
+
1000
*
(
this
.
wordTyping
<=
(
5
-
_wordGrade
)
*
2.5
?
this
.
wordTyping
*
(
WordSpace
.
playerTyping
/
60
)
*
2
:
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
);
((
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
(
'
Attack text :
'
+
text
+
'
, Attacker :
'
+
this
.
attacker
.
nickname
+
'
, Weight :
'
+
this
.
wordWeight
);
console
.
log
(
'
Counter time :
'
+
this
.
counterTime
);
console
.
log
(
'
Counter time :
'
+
this
.
counterTime
);
}
}
destroy
()
destroy
()
...
@@ -139,19 +139,22 @@ class AttackWord extends WordObject
...
@@ -139,19 +139,22 @@ class AttackWord extends WordObject
case
3
:
WordSpace
.
attackGauge
.
add
(
0.5
);
break
;
case
3
:
WordSpace
.
attackGauge
.
add
(
0.5
);
break
;
default
:
console
.
log
(
'
[ERR] wrong grade of word
'
);
break
;
default
:
console
.
log
(
'
[ERR] wrong grade of word
'
);
break
;
}
}
if
(
WordSpace
.
gameTimer
.
now
<
this
.
counterTime
)
WordSpace
.
generateWord
.
Name
(
WordSpace
.
gameSceneForTest
,
true
);
if
(
WordSpace
.
gameTimer
.
now
<
this
.
counterTime
)
WordSpace
.
nameGroup
.
push
(
new
NameWord
(
this
.
attacker
,
true
));
//강호패 넣기 구현해야됨
//WordSpace.generateWord.Name(WordSpace.gameSceneForTest, true);
super
.
destroy
();
super
.
destroy
();
}
}
}
}
class
NameWord
extends
WordObject
class
NameWord
extends
WordObject
{
{
constructor
(
text
,
_isStrong
=
false
)
constructor
(
player
,
_isStrong
=
false
)
{
{
super
(
text
);
super
(
player
.
nickname
);
this
.
ownerId
=
player
.
id
;
this
.
wordWeight
=
2
;
this
.
wordWeight
=
2
;
this
.
isStrong
=
_isStrong
;
this
.
isStrong
=
_isStrong
;
console
.
log
(
'
Name :
'
+
text
+
'
, Strong :
'
+
this
.
isStrong
+
'
, Weight :
'
+
this
.
wordWeight
);
console
.
log
(
'
Name :
'
+
player
.
nickname
+
'
, Strong :
'
+
this
.
isStrong
+
'
, Weight :
'
+
this
.
wordWeight
);
}
}
destroy
()
destroy
()
{
{
...
...
js/WordReader.js
View file @
80a36517
var
WordReader
=
WordReader
||
{};
var
WordReader
=
WordReader
||
{};
//초성의 타수를 반환함
//초성의 타수를 반환함
function
firstSound
(
charText
)
WordReader
.
firstSound
=
function
(
charText
)
{
{
var
r
=
parseInt
(((
charText
.
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
/
28
)
/
21
);
var
r
=
parseInt
(((
charText
.
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
/
28
)
/
21
);
//쌍자음일 경우
//쌍자음일 경우
...
@@ -10,7 +10,7 @@ function firstSound(charText)
...
@@ -10,7 +10,7 @@ function firstSound(charText)
}
}
//중성의 타수를 반환함
//중성의 타수를 반환함
function
middleSound
(
charText
)
WordReader
.
middleSound
=
function
(
charText
)
{
{
var
r
=
parseInt
(((
charText
.
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
/
28
)
%
21
);
var
r
=
parseInt
(((
charText
.
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
/
28
)
%
21
);
//'ㅒ' 또는 'ㅖ'일 경우
//'ㅒ' 또는 'ㅖ'일 경우
...
@@ -21,7 +21,7 @@ function middleSound(charText)
...
@@ -21,7 +21,7 @@ function middleSound(charText)
}
}
//종성의 타수를 반환함
//종성의 타수를 반환함
function
lastSound
(
charText
)
WordReader
.
lastSound
=
function
(
charText
)
{
{
var
r
=
parseInt
((
charText
.
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
%
28
);
var
r
=
parseInt
((
charText
.
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
%
28
);
//쌍자음일 경우
//쌍자음일 경우
...
@@ -40,7 +40,7 @@ WordReader.getWordTyping = function(stringText)
...
@@ -40,7 +40,7 @@ WordReader.getWordTyping = function(stringText)
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
;
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
(
WordReader
.
firstSound
(
stringText
.
charAt
(
i
)))
+
WordReader
.
middleSound
(
stringText
.
charAt
(
i
))
+
WordReader
.
lastSound
(
stringText
.
charAt
(
i
));
}
}
return
temp
;
return
temp
;
}
}
...
...
js/WordSpace.js
View file @
80a36517
...
@@ -120,7 +120,7 @@ WordSpace.AdjustVarByPhase = function(typingRate, phase)
...
@@ -120,7 +120,7 @@ WordSpace.AdjustVarByPhase = function(typingRate, phase)
else
if
(
phase
==
WordSpace
.
Phase
.
START
)
else
if
(
phase
==
WordSpace
.
Phase
.
START
)
{
{
WordSpace
.
delay
.
WordSpawn
=
3000
;
WordSpace
.
delay
.
WordSpawn
=
3000
;
WordSpace
.
delay
.
NameSpawn
=
6
000
;
WordSpace
.
delay
.
NameSpawn
=
15
000
;
WordSpace
.
NameSpawnReduce
=
1000
;
WordSpace
.
NameSpawnReduce
=
1000
;
WordSpace
.
GradeProb
[
0
]
=
0.35
;
WordSpace
.
GradeProb
[
0
]
=
0.35
;
WordSpace
.
GradeProb
[
1
]
=
1
-
0.4
*
typingRate
;
WordSpace
.
GradeProb
[
1
]
=
1
-
0.4
*
typingRate
;
...
@@ -129,20 +129,20 @@ WordSpace.AdjustVarByPhase = function(typingRate, phase)
...
@@ -129,20 +129,20 @@ WordSpace.AdjustVarByPhase = function(typingRate, phase)
else
if
(
phase
==
WordSpace
.
Phase
.
MAIN
)
else
if
(
phase
==
WordSpace
.
Phase
.
MAIN
)
{
{
WordSpace
.
delay
.
WordSpawn
=
3000
-
typingRate
*
1000
;
WordSpace
.
delay
.
WordSpawn
=
3000
-
typingRate
*
1000
;
WordSpace
.
delay
.
NameSpawn
=
6
000
;
WordSpace
.
delay
.
NameSpawn
=
12
000
;
WordSpace
.
NameSpawnReduce
=
1000
;
WordSpace
.
NameSpawnReduce
=
1000
;
WordSpace
.
GradeProb
[
0
]
=
0.
4
-
0.4
*
typingRate
;
WordSpace
.
GradeProb
[
0
]
=
0.
5
-
0.5
*
typingRate
;
WordSpace
.
GradeProb
[
1
]
=
0.8
-
0.4
*
typingRate
;
WordSpace
.
GradeProb
[
1
]
=
1
-
0.5
*
typingRate
;
WordSpace
.
GradeProb
[
2
]
=
1
-
0.
2
*
typingRate
;
WordSpace
.
GradeProb
[
2
]
=
1
-
0.
15
*
typingRate
;
}
}
else
if
(
phase
==
WordSpace
.
Phase
.
MUSIC
)
else
if
(
phase
==
WordSpace
.
Phase
.
MUSIC
)
{
{
WordSpace
.
delay
.
WordSpawn
=
1500
;
WordSpace
.
delay
.
WordSpawn
=
1500
;
WordSpace
.
delay
.
NameSpawn
=
4
000
;
WordSpace
.
delay
.
NameSpawn
=
8
000
;
WordSpace
.
NameSpawnReduce
=
5
00
;
WordSpace
.
NameSpawnReduce
=
4
00
;
WordSpace
.
GradeProb
[
0
]
=
0.2
-
0.2
*
typingRate
;
WordSpace
.
GradeProb
[
0
]
=
0.2
-
0.2
*
typingRate
;
WordSpace
.
GradeProb
[
1
]
=
0.8
-
0.5
*
typingRate
;
WordSpace
.
GradeProb
[
1
]
=
0.8
-
0.
4
5
*
typingRate
;
WordSpace
.
GradeProb
[
2
]
=
0.9
-
0.
2
*
typingRate
;
WordSpace
.
GradeProb
[
2
]
=
0.9
-
0.
15
*
typingRate
;
}
}
WordSpace
.
wordCycle
.
resetCycle
(
WordSpace
.
gameSceneForTest
,
WordSpace
.
delay
.
WordSpawn
,
WordSpace
.
wordCycle
.
currentCycle
.
getElapsed
(),
true
);
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
.
nameCycle
.
resetCycle
(
WordSpace
.
gameSceneForTest
,
WordSpace
.
delay
.
NameSpawn
,
WordSpace
.
nameCycle
.
currentCycle
.
getElapsed
(),
true
);
...
@@ -252,8 +252,8 @@ WordSpace.generateWord =
...
@@ -252,8 +252,8 @@ WordSpace.generateWord =
},
},
Name
:
function
(
scene
,
isStrong
,
lenRate
)
Name
:
function
(
scene
,
isStrong
,
lenRate
)
{
{
//To do
word
=
new
NameWord
(
WordSpace
.
nameQueue
.
pop
(),
isStrong
);
word
=
new
NameWord
(
PlayerData
.
nickname
,
isStrong
);
//word = new NameWord(RoomData.myself, false
);
WordSpace
.
pushWord
(
scene
,
word
,
lenRate
);
WordSpace
.
pushWord
(
scene
,
word
,
lenRate
);
}
}
}
}
...
@@ -276,6 +276,7 @@ function gameOver()
...
@@ -276,6 +276,7 @@ function gameOver()
{
{
WordSpace
.
wordCycle
.
currentCycle
.
remove
();
WordSpace
.
wordCycle
.
currentCycle
.
remove
();
WordSpace
.
nameCycle
.
currentCycle
.
remove
();
WordSpace
.
nameCycle
.
currentCycle
.
remove
();
WordSpace
.
varAdjustCycle
.
currentCycle
.
remove
();
//To Do
//To Do
console
.
log
(
'
defeat
'
);
console
.
log
(
'
defeat
'
);
}
}
...
@@ -288,7 +289,6 @@ WordSpace.setGameOverTimer = function()
...
@@ -288,7 +289,6 @@ WordSpace.setGameOverTimer = function()
{
{
this
.
isTimerOn
=
true
;
this
.
isTimerOn
=
true
;
WordSpace
.
gameOverCycle
.
resetCycle
(
WordSpace
.
gameSceneForTest
,
WordSpace
.
delay
.
gameOver
,
0
,
false
);
WordSpace
.
gameOverCycle
.
resetCycle
(
WordSpace
.
gameSceneForTest
,
WordSpace
.
delay
.
gameOver
,
0
,
false
);
console
.
log
(
'
Game over timer On
'
);
}
}
}
}
...
@@ -298,7 +298,6 @@ WordSpace.resetGameOverTimer = function()
...
@@ -298,7 +298,6 @@ WordSpace.resetGameOverTimer = function()
{
{
this
.
isTimerOn
=
false
;
this
.
isTimerOn
=
false
;
WordSpace
.
gameOverCycle
.
currentCycle
.
paused
=
true
;
WordSpace
.
gameOverCycle
.
currentCycle
.
paused
=
true
;
console
.
log
(
'
Game over timer Off
'
);
}
}
}
}
...
@@ -334,9 +333,28 @@ WordSpace.findWord = function(wordText)
...
@@ -334,9 +333,28 @@ WordSpace.findWord = function(wordText)
WordSpace
.
attackGauge
.
pauseCycle
(
true
);
WordSpace
.
attackGauge
.
pauseCycle
(
true
);
WordSpace
.
setPlayerTyping
.
add
(
wordText
);
WordSpace
.
setPlayerTyping
.
add
(
wordText
);
}
}
else
else
// 오타 체크
{
{
// 오타 체크
let
minDist
=
WordReader
.
getWordTyping
(
wordText
)
/
2
+
1
,
tempDist
=
0
;
let
attackWords
=
[];
WordSpace
.
wordGroup
.
forEach
(
function
(
element
)
{
if
(
element
instanceof
AttackWord
)
{
tempDist
=
WordSpace
.
getEditDistance
(
wordText
,
element
.
wordText
);
attackWords
.
push
(
element
);
if
(
tempDist
<=
minDist
)
minDist
=
tempDist
;
}
});
attackWords
.
forEach
(
function
(
element
)
{
if
(
WordSpace
.
getEditDistance
(
wordText
,
element
.
wordText
)
==
minDist
)
{
//강호패 보내야 함
console
.
log
(
'
Attack word :
'
+
element
.
wordText
+
'
of
'
+
element
.
attacker
.
nickname
+
'
오타임
'
);
}
});
this
.
attackGauge
.
sub
(
2
);
}
}
}
}
...
@@ -364,25 +382,89 @@ WordSpace.attack = function(wordText, grade)
...
@@ -364,25 +382,89 @@ WordSpace.attack = function(wordText, grade)
if
(
wordText
!=
''
)
if
(
wordText
!=
''
)
{
{
console
.
log
(
'
attack
'
+
wordText
+
'
, grade:
'
+
grade
);
console
.
log
(
'
attack
'
+
wordText
+
'
, grade:
'
+
grade
);
//호패에 따른 isStrong 구분 필요함
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
{
WordSpace
.
generateWord
.
Attack
(
WordSpace
.
gameSceneForTest
,
wordText
,
grade
,
PlayerData
.
nickname
,
element
.
isStrong
);
let
attackData
=
{
roomNum
:
RoomData
.
roomNum
,
attacker
:
PlayerData
,
target
:
element
.
ownerId
,
text
:
wordText
,
grade
:
grade
,
isStrong
:
element
.
isStrong
}
socket
.
emit
(
'
attack
'
,
attackData
);
});
});
//테스트용, 자기 자신에게 공격함
//WordSpace.generateWord.Attack(WordSpace.gameSceneForTest, wordText, grade, PlayerData, false);
WordSpace
.
nameGroup
=
[];
WordSpace
.
nameGroup
=
[];
//WordSpace.generateWord(WordSpace.gameSceneForTest, wordText, grade, undefined, true); // for test
// 이부분에서 게이지에 따라 급수 결정
// 이걸 서버로 공격을 보내야 함
// 이부분은 서버 잘써야함
WordSpace
.
attackGauge
.
resetValue
();
WordSpace
.
attackGauge
.
resetValue
();
WordSpace
.
setPlayerTyping
.
add
(
wordText
);
WordSpace
.
setPlayerTyping
.
add
(
wordText
);
}
}
else
else
WordSpace
.
attackGauge
.
cutValue
(
0.3
);
{
WordSpace
.
attackGauge
.
cutValue
(
0.3
);
}
Input
.
maxInput
=
6
;
Input
.
maxInput
=
6
;
Input
.
attackMode
=
false
;
Input
.
attackMode
=
false
;
WordSpace
.
attackGauge
.
pauseCycle
(
false
);
WordSpace
.
attackGauge
.
pauseCycle
(
false
);
}
WordSpace
.
nameQueue
=
{
queue
:
[],
shuffle
:
function
()
{
let
tempIdx
,
tempElement
,
tempLength
;
let
tempQueue
=
RoomData
.
players
;
for
(
tempLength
=
tempQueue
.
length
;
tempLength
;
tempLength
-=
1
)
{
tempIdx
=
Math
.
floor
(
Math
.
random
()
*
tempLength
);
tempElement
=
tempQueue
[
tempLength
-
1
];
tempQueue
[
tempLength
-
1
]
=
tempQueue
[
tempIdx
];
tempQueue
[
tempIdx
]
=
tempElement
;
}
tempQueue
.
forEach
(
function
(
element
){
if
(
element
.
ownerId
!=
PlayerData
.
idNum
&&
element
.
isAlive
)
WordSpace
.
nameQueue
.
queue
.
push
(
element
);
});
},
pop
:
function
()
{
let
tempElement
=
WordSpace
.
nameQueue
.
queue
.
shift
();
if
(
WordSpace
.
nameQueue
.
queue
.
length
<=
RoomData
.
aliveCount
)
this
.
shuffle
();
return
tempElement
;
},
initiate
:
function
()
{
this
.
shuffle
();
this
.
shuffle
();
}
}
WordSpace
.
getEditDistance
=
function
(
input
,
check
)
{
var
inputWords
=
[],
checkWords
=
[]
for
(
let
i
=
0
;
i
<
input
.
length
;
i
++
)
{
inputWords
.
push
(
parseInt
(((
input
[
i
].
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
/
28
)
/
21
)
+
parseInt
(
'
0x1100
'
,
16
));
inputWords
.
push
(
parseInt
(((
input
[
i
].
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
/
28
)
%
21
)
+
parseInt
(
'
0x1161
'
,
16
));
inputWords
.
push
(
parseInt
((
input
[
i
].
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
%
28
)
+
parseInt
(
'
0x11A8
'
)
-
1
);
}
for
(
let
i
=
0
;
i
<
check
.
length
;
i
++
)
{
checkWords
.
push
(
parseInt
(((
check
[
i
].
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
/
28
)
/
21
)
+
parseInt
(
'
0x1100
'
,
16
));
checkWords
.
push
(
parseInt
(((
check
[
i
].
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
/
28
)
%
21
)
+
parseInt
(
'
0x1161
'
,
16
));
checkWords
.
push
(
parseInt
((
check
[
i
].
charCodeAt
(
0
)
-
parseInt
(
'
0xac00
'
,
16
))
%
28
)
+
parseInt
(
'
0x11A8
'
)
-
1
);
}
var
matrix
=
[];
var
i
,
j
;
for
(
i
=
0
;
i
<=
checkWords
.
length
;
i
++
)
// increment along the first column of each row
matrix
[
i
]
=
[
i
];
for
(
j
=
0
;
j
<=
inputWords
.
length
;
j
++
)
// increment each column in the first row
matrix
[
0
][
j
]
=
j
;
for
(
i
=
1
;
i
<=
checkWords
.
length
;
i
++
)
// Fill in the rest of the matrix
for
(
j
=
1
;
j
<=
inputWords
.
length
;
j
++
){
if
(
checkWords
[
i
-
1
]
==
inputWords
[
j
-
1
])
matrix
[
i
][
j
]
=
matrix
[
i
-
1
][
j
-
1
];
else
matrix
[
i
][
j
]
=
Math
.
min
(
matrix
[
i
-
1
][
j
-
1
]
+
1
,
// substitution
Math
.
min
(
matrix
[
i
][
j
-
1
]
+
1
,
// insertion
matrix
[
i
-
1
][
j
]
+
1
));
// deletion
}
return
matrix
[
checkWords
.
length
][
inputWords
.
length
];
}
}
\ No newline at end of file
js/main.js
View file @
80a36517
...
@@ -25,4 +25,6 @@ PlayerData.nickname = '홍길동'; //플레이어 닉네임
...
@@ -25,4 +25,6 @@ PlayerData.nickname = '홍길동'; //플레이어 닉네임
var
RoomData
=
RoomData
||
{};
var
RoomData
=
RoomData
||
{};
RoomData
.
roomNum
=
-
1
;
RoomData
.
roomNum
=
-
1
;
RoomData
.
players
=
null
;
RoomData
.
myself
=
null
;
\ No newline at end of file
RoomData
.
players
=
null
;
RoomData
.
aliveCount
=
-
1
;
\ No newline at end of file
server.js
View file @
80a36517
...
@@ -48,12 +48,23 @@ io.on('connection', function(socket)
...
@@ -48,12 +48,23 @@ io.on('connection', function(socket)
socket
.
on
(
'
setPlayerTyping
'
,
function
(
msg
)
// number playerTyping
socket
.
on
(
'
setPlayerTyping
'
,
function
(
msg
)
// number playerTyping
{
{
socket
.
playerData
.
playerTyping
=
msg
;
socket
.
playerData
.
playingData
.
playerTyping
=
msg
;
//console.log(socket.playerData.currentRoom);
if
(
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
.
playerTyping
<
msg
)
//console.log(socket.playerData.currentRoom.currentPlayer.length);
{
//let playerTypingRate = (msg - (socket.playerData.currentRoom.minTypingPlayer.playerTyping - socket.playerData.currentRoom.rateArrangePoint)) /
socket
.
playerData
.
currentRoom
.
maxTypingPlayer
=
socket
.
playerData
.
playingData
;
//(socket.playerData.currentRoom.maxTypingPlayer.playerTyping - socket.playerData.currentRoom.minTypingPlayer.playerTyping + socket.playerData.currentRoom.rateArrangePoint * 2);
}
//socket.emit('setPlayerTypingRate', playerTypingRate);
if
(
socket
.
playerData
.
currentRoom
.
minTypingPlayer
.
playerTyping
>
msg
)
{
socket
.
playerData
.
currentRoom
.
minTypingPlayer
=
socket
.
playerData
.
playingData
;
}
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
(
'
attack
'
,
function
(
msg
)
{
GameServer
.
announceToTarget
(
GameServer
.
findRoomIndex
(
msg
.
roomNum
),
msg
.
target
,
'
attacked
'
,
msg
);
});
});
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
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