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
11a48a49
Commit
11a48a49
authored
Jul 18, 2019
by
18신대성
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'wordspace'
parents
61daf001
164931b7
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
464 additions
and
226 deletions
+464
-226
GameServer.js
GameServer.js
+229
-148
index.html
index.html
+1
-0
Background.js
js/Background.js
+7
-1
Client.js
js/Client.js
+65
-7
Enums.js
js/Enums.js
+3
-1
ScenesData.js
js/ScenesData.js
+43
-12
WordObject.js
js/WordObject.js
+55
-10
WordReader.js
js/WordReader.js
+3
-6
WordSpace.js
js/WordSpace.js
+28
-17
main.js
js/main.js
+2
-2
server.js
server.js
+28
-22
No files found.
GameServer.js
View file @
11a48a49
var
GameServer
=
GameServer
||
{};
GameServer
.
Phase
=
{
READY
:
0
,
COUNT
:
-
1
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
startCount
=
2
;
GameServer
.
currentPlayer
=
[];
GameServer
.
playingRoom
=
[];
GameServer
.
getPlayerNumber
=
function
(
)
GameServer
.
findRoom
=
function
(
roomId
)
{
do
for
(
let
i
=
0
;
i
<
GameServer
.
playingRoom
.
length
;
i
++
)
{
var
num
=
Math
.
floor
(
Math
.
random
()
*
1000
+
1
)
;
if
(
!
this
.
currentPlayer
.
includes
(
num
))
return
num
;
}
while
(
true
)
if
(
GameServer
.
playingRoom
[
i
].
roomId
===
roomId
)
return
GameServer
.
playingRoom
[
i
]
;
}
console
.
log
(
'
[ERR] no room with num
'
+
roomId
);
}
GameServer
.
findPlayer
=
function
(
playerId
)
GameServer
.
findPlayer
Socket
=
function
(
playerId
)
{
var
idx
=
this
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
playerId
;
return
element
.
playerData
.
id
===
playerId
;
});
if
(
idx
!=
-
1
)
return
this
.
currentPlayer
[
idx
];
else
...
...
@@ -27,192 +26,235 @@ GameServer.findPlayer = function(playerId)
return
null
;
}
}
GameServer
.
nextRoomNumber
=
0
;
GameServer
.
makeRoom
=
function
()
GameServer
.
enterEmptyRoom
=
function
(
playerSocket
)
{
// 나중에 room 삭제시 생긴 null에 채워넣는식으로 만들것, 룸의 인덱스를 고정
var
roomOption
=
{
roomNum
:
GameServer
.
nextRoomNumber
++
,
maxPlayer
:
100
,
nextRank
:
100
,
currentPlayer
:
[],
aliveCount
:
0
,
currentSocket
:
[],
currentPhase
:
GameServer
.
Phase
.
READY
,
endTime
:
0
,
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
nextIdx
=
-
1
;
for
(
let
i
=
0
;
i
<
room
.
currentPlayer
.
length
;
i
++
)
let
emptyRoomIndex
=
-
1
;
for
(
let
i
=
0
;
i
<
this
.
playingRoom
.
length
;
i
++
)
{
if
(
room
.
currentPlayer
[
i
]
===
null
)
if
(
(
this
.
playingRoom
[
i
].
currentPhase
===
this
.
Phase
.
READY
||
this
.
playingRoom
[
i
].
currentPhase
===
this
.
Phase
.
COUNT
)
&&
this
.
playingRoom
[
i
].
maxPlayer
>
this
.
playingRoom
[
i
].
currentPlayer
.
length
)
{
nextId
x
=
i
;
break
emptyRoomInde
x
=
i
;
break
;
}
}
let
player
=
new
Player
((
nextIdx
!=
-
1
?
nextIdx
:
room
.
currentPlayer
.
length
),
playerData
);
if
(
nextIdx
!=
-
1
)
if
(
emptyRoomIndex
!=
-
1
)
{
room
.
currentPlayer
[
nextIdx
]
=
player
;
room
.
currentSocket
[
nextIdx
]
=
playerData
;
this
.
playingRoom
[
emptyRoomIndex
].
enterRoom
(
playerSocket
);
}
else
{
room
.
currentPlayer
.
push
(
player
);
room
.
currentSocket
.
push
(
playerData
);
let
newRoom
=
new
GameRoom
(
);
newRoom
.
enterRoom
(
playerSocket
);
}
playerData
.
playingData
=
player
;
playerData
.
currentRoom
=
room
;
room
.
aliveCount
++
;
}
GameServer
.
getPlayerNumber
=
function
()
{
do
{
var
num
=
Math
.
floor
(
Math
.
random
()
*
1000
+
1
);
if
(
this
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
num
;
})
===
-
1
)
return
num
;
}
while
(
true
)
}
GameServer
.
getRoomNumber
=
function
()
{
do
{
var
num
=
Math
.
floor
(
Math
.
random
()
*
1000
+
1
);
if
(
this
.
playingRoom
.
findIndex
(
function
(
element
)
{
return
element
.
roomId
===
num
;
})
===
-
1
)
return
num
;
}
while
(
true
)
}
console
.
log
(
'
[
'
+
playerData
.
id
+
'
] entered to room #
'
+
room
.
roomNum
);
playerData
.
socketId
.
emit
(
'
enterRoom
'
);
if
(
room
.
currentPlayer
.
length
>=
this
.
startCount
)
class
GameRoom
{
constructor
(
)
{
if
(
room
.
currentPhase
===
this
.
Phase
.
READY
)
// start count
this
.
roomId
=
GameServer
.
getRoomNumber
();
this
.
roomIndex
=
-
1
;
this
.
startCount
=
3
;
this
.
maxPlayer
=
100
;
this
.
nextRank
=
100
;
this
.
currentPlayer
=
[];
this
.
aliveCount
=
0
;
this
.
currentSocket
=
[];
this
.
currentPhase
=
GameServer
.
Phase
.
READY
;
this
.
countEndTime
=
0
;
this
.
rateArrangePoint
=
300
;
this
.
maxTypingPlayer
=
null
;
this
.
minTypingPlayer
=
null
;
for
(
let
i
=
0
;
i
<
GameServer
.
playingRoom
.
length
;
i
++
)
{
if
(
GameServer
.
playingRoom
[
i
]
===
null
)
{
this
.
roomIndex
=
i
;
break
;
}
}
if
(
this
.
roomIndex
===
-
1
)
{
room
.
endTime
=
Date
.
now
()
+
15000
;
// 테스트로 15초로 남겨둠
this
.
announceToRoom
(
room
.
roomNum
,
'
setCount
'
,
{
isEnable
:
true
,
endTime
:
room
.
endTime
});
room
.
currentPhase
=
this
.
Phase
.
COUNT
;
this
.
roomIndex
=
GameServer
.
playingRoom
.
length
;
GameServer
.
playingRoom
.
push
(
this
);
}
else
if
(
room
.
currentPhase
===
this
.
Phase
.
COUNT
)
// countinue count
else
{
playerData
.
socketId
.
emit
(
'
setCount
'
,
{
isEnable
:
true
,
endTime
:
room
.
endTime
})
;
GameServer
.
playingRoom
[
this
.
roomIndex
]
=
this
;
}
console
.
log
(
'
[LOG] new room #
'
+
this
.
roomId
+
'
made, roomCount:
'
+
GameServer
.
playingRoom
.
length
);
}
else
// stop count
enterRoom
(
playerSocket
)
{
this
.
announceToRoom
(
room
.
roomNum
,
'
setCount
'
,
{
isEnable
:
false
,
endTime
:
0
});
room
.
currentPhase
=
this
.
Phase
.
READY
;
let
playerInst
=
new
Player
(
this
,
playerSocket
.
playerData
);
playerSocket
.
playerData
.
playingData
=
playerInst
;
playerSocket
.
playerData
.
currentRoom
=
this
;
playerSocket
.
playerData
.
isReceivable
=
true
;
playerSocket
.
emit
(
'
enterRoom
'
);
this
.
currentSocket
.
push
(
playerSocket
);
this
.
announceToTarget
(
playerInst
.
id
,
'
syncRoomScene
'
,
this
.
currentPlayer
);
this
.
currentPlayer
.
push
(
playerInst
);
console
.
log
(
'
[
'
+
playerInst
.
id
+
'
] entered to room #
'
+
this
.
roomId
);
this
.
aliveCount
++
;
if
(
this
.
currentPlayer
.
length
>=
this
.
startCount
)
{
if
(
this
.
currentPhase
===
GameServer
.
Phase
.
READY
)
{
this
.
endTime
=
Date
.
now
()
+
5000
;
// 테스트용 10초
this
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
true
,
endTime
:
this
.
endTime
,
playerCount
:
this
.
currentPlayer
.
length
,
isEnter
:
true
,
player
:
playerInst
// 나중에는 플레이어의 외양데이터도 보내야됨
});
this
.
currentPhase
=
GameServer
.
Phase
.
COUNT
;
}
else
if
(
this
.
currentPhase
===
GameServer
.
Phase
.
COUNT
)
{
this
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
true
,
endTime
:
this
.
endTime
,
playerCount
:
this
.
currentPlayer
.
length
,
isEnter
:
true
,
player
:
playerInst
});
}
}
else
{
this
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
false
,
endTime
:
0
,
playerCount
:
this
.
currentPlayer
.
length
,
isEnter
:
true
,
player
:
playerInst
});
this
.
currentPhase
=
GameServer
.
Phase
.
READY
;
}
}
return
room
;
}
GameServer
.
enterEmptyRoom
=
function
(
playerData
)
{
var
toEnter
=
-
1
;
for
(
let
i
=
0
;
i
<
this
.
playingRoom
.
length
;
i
++
)
exitRoom
(
playerId
)
{
if
(
this
.
playingRoom
[
i
].
currentPlayer
.
length
<
this
.
playingRoom
[
i
].
maxPlayer
&&
(
this
.
playingRoom
[
i
].
currentPhase
==
this
.
Phase
.
READY
||
this
.
playingRoom
[
i
].
currentPhase
==
this
.
Phase
.
COUNT
)
)
for
(
let
i
=
0
;
i
<
this
.
currentPlayer
.
length
;
i
++
)
{
toEnter
=
i
;
break
;
if
(
this
.
currentPlayer
[
i
].
id
===
playerId
)
{
for
(
let
j
=
i
+
1
;
j
<
this
.
currentPlayer
.
length
;
j
++
)
{
this
.
currentPlayer
[
i
].
index
--
;
}
this
.
currentPlayer
.
splice
(
i
,
1
);
this
.
currentSocket
.
splice
(
i
,
1
);
this
.
aliveCount
--
;
return
;
}
}
console
.
log
(
'
[ERR] No player who have
'
+
playerId
);
return
;
}
if
(
toEnter
===
-
1
)
startRoom
()
{
toEnter
=
this
.
makeRoom
();
this
.
currentPhase
=
GameServer
.
Phase
.
START
;
this
.
maxTypingPlayer
=
this
.
currentPlayer
[
0
];
this
.
minTypingPlayer
=
this
.
currentPlayer
[
0
];
this
.
nextRank
=
this
.
currentPlayer
.
length
;
this
.
aliveCount
=
this
.
currentPlayer
.
length
;
this
.
currentSocket
.
forEach
(
function
(
element
)
{
element
.
playerData
.
isReceivable
=
true
;
});
let
toSync
=
{
roomId
:
this
.
roomId
,
players
:
this
.
currentPlayer
};
this
.
announceToRoom
(
'
syncRoomData
'
,
toSync
);
console
.
log
(
'
[ROOM#
'
+
this
.
roomId
+
'
] Game Start with
'
+
this
.
currentPlayer
.
length
+
'
players
'
);
this
.
announceToRoom
(
'
changePhase
'
,
GameServer
.
Phase
.
START
);
this
.
announceToRoom
(
'
startGame
'
);
}
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
];
room
.
currentSocket
.
forEach
(
function
(
element
)
{
if
(
element
!=
null
)
element
.
isReceivable
=
true
;
});
let
syncPlayers
=
[];
room
.
currentPlayer
.
forEach
(
function
(
element
)
{
if
(
element
!=
null
)
syncPlayers
.
push
(
element
);
});
room
.
nextRank
=
syncPlayers
.
length
;
room
.
aliveCount
=
syncPlayers
.
length
;
// sync roomData
let
toSync
=
endRoom
()
{
roomNum
:
room
.
roomNum
,
players
:
syncPlayers
};
//console.log(toSync);
this
.
announceToRoom
(
roomIdx
,
'
syncRoomData
'
,
toSync
);
console
.
log
(
'
[ROOM#
'
+
room
.
roomNum
+
'
] Game Start with
'
+
syncPlayers
.
length
+
'
players
'
);
this
.
announceToRoom
(
roomIdx
,
'
changePhase
'
,
this
.
Phase
.
START
);
this
.
announceToRoom
(
roomIdx
,
'
startGame
'
);
}
GameServer
.
playerDefeat
=
function
(
playerData
)
{
playerData
.
playingData
.
isAlive
=
false
;
playerData
.
playingData
.
rank
=
playerData
.
currentRoom
.
nextRank
--
;
playerData
.
isReceivable
=
false
;
playerData
.
currentRoom
.
aliveCount
--
;
if
(
playerData
.
playingData
.
lastAttacks
.
length
>
0
)
{
playerData
.
playingData
.
lastAttack
=
playerData
.
playingData
.
lastAttacks
[
playerData
.
playingData
.
lastAttacks
.
length
-
1
];
if
(
Date
.
now
()
-
playerData
.
playingData
.
lastAttack
.
time
>
40000
)
playerData
.
playingData
.
lastAttack
=
null
;
}
destroyRoom
()
{
if
(
this
.
aliveCount
>
0
)
{
console
.
log
(
'
[ERR] can not destroy room#
'
+
this
.
roomId
+
'
, cause player left
'
);
}
else
{
playerData
.
playingData
.
lastAttacks
.
forEach
(
function
(
element
)
let
idx
=
GameServer
.
playingRoom
.
findIndex
(
function
(
element
)
{
return
element
.
roomId
===
this
.
roomId
;
});
if
(
idx
!=
-
1
)
{
if
(
Date
.
now
()
-
element
.
time
<
40000
&&
element
.
wordGrade
>
playerData
.
playingData
.
lastAttack
.
wordGrade
)
playerData
.
playingData
.
lastAttack
=
element
;
}
);
GameServer
.
playingRoom
[
idx
]
=
null
;
}
}
}
GameServer
.
announceToRoom
(
this
.
findRoomIndex
(
playerData
.
currentRoom
.
roomNum
),
'
defeat
'
,
playerData
.
playingData
);
console
.
log
(
'
[
'
+
playerData
.
id
+
'
]
'
+
'
defeated, rank:
'
+
playerData
.
playingData
.
rank
);
if
(
playerData
.
currentRoom
.
aliveCount
===
1
)
announceToRoom
(
_message
,
_data
=
null
)
{
let
winner
=
playerData
.
currentRoom
.
currentPlayer
.
find
(
function
(
element
)
this
.
currentSocket
.
forEach
(
function
(
element
)
{
return
element
!=
null
&&
element
.
isAlive
;
element
.
emit
(
_message
,
_data
)
;
});
GameServer
.
announceToRoom
(
this
.
findRoomIndex
(
playerData
.
currentRoom
.
roomNum
),
'
gameEnd
'
,
winner
);
GameServer
.
announceToTarget
(
this
.
findRoomIndex
(
playerData
.
currentRoom
.
roomNum
),
winner
.
id
,
'
alert
'
,
'
gameWin
'
);
console
.
log
(
'
[
'
+
winner
.
id
+
'
]
'
+
'
winner!
'
+
winner
.
nickname
);
}
}
GameServer
.
announceToRoom
=
function
(
roomIdx
,
_message
,
_data
=
null
)
{
this
.
playingRoom
[
roomIdx
].
currentSocket
.
forEach
(
function
(
element
)
{
if
(
element
!=
null
)
element
.
socketId
.
emit
(
_message
,
_data
);
});
}
GameServer
.
announceToTarget
=
function
(
roomIdx
,
targetNum
,
_message
,
_data
=
null
)
{
let
targetSocket
=
this
.
playingRoom
[
roomIdx
].
currentSocket
.
find
(
function
(
element
)
announceToTarget
(
targetId
,
_message
,
_data
=
null
)
{
return
(
element
!=
null
&&
element
.
id
===
targetNum
);
});
if
(
targetSocket
!=
undefined
&&
targetSocket
.
isReceivable
)
targetSocket
.
socketId
.
emit
(
_message
,
_data
);
let
targetSocketIndex
=
this
.
currentSocket
.
findIndex
(
function
(
element
)
{
return
element
.
playerData
.
id
===
targetId
;
});
//console.log('send to ' + targetSocketIndex + ', receivable? ' + this.currentSocket[targetSocketIndex].playerData.isReceivable);
if
(
this
.
currentSocket
[
targetSocketIndex
].
playerData
.
isReceivable
)
this
.
currentSocket
[
targetSocketIndex
].
emit
(
_message
,
_data
);
}
}
// 데이터 동기화 함수 만들기
// 동기화할것: 유저리스트(id - nickname 쌍)
class
Player
{
constructor
(
index
,
playerData
)
constructor
(
gameRoom
,
playerData
)
{
this
.
index
=
index
;
this
.
id
=
playerData
.
id
;
this
.
gameRoomId
=
gameRoom
.
roomId
;
this
.
index
=
gameRoom
.
currentPlayer
.
length
;
this
.
nickname
=
playerData
.
nickname
;
this
.
isAlive
=
true
;
this
.
rank
=
-
1
;
...
...
@@ -220,6 +262,45 @@ class Player
this
.
lastAttacks
=
[];
// { attackerId, word, wordGrade, time }
this
.
lastAttack
=
null
;
}
defeat
()
{
let
player
=
this
;
let
room
=
GameServer
.
findRoom
(
this
.
gameRoomId
);
let
socket
=
GameServer
.
findPlayerSocket
(
this
.
id
);
this
.
isAlive
=
false
;
this
.
rank
=
room
.
nextRank
--
;
socket
.
playerData
.
isReceivable
=
false
;
room
.
aliveCount
--
;
if
(
this
.
lastAttacks
.
length
>
0
)
{
this
.
lastAttack
=
this
.
lastAttacks
[
this
.
lastAttacks
.
length
-
1
];
if
(
Date
.
now
()
-
this
.
lastAttack
.
time
>
40000
)
this
.
lastAttack
=
null
;
else
{
this
.
lastAttacks
.
forEach
(
function
(
element
)
{
if
(
Date
.
now
()
-
element
.
time
<
40000
&&
element
.
wordGrade
>
player
.
lastAttack
.
wordGrade
)
player
.
lastAttack
=
element
;
});
}
}
room
.
announceToRoom
(
'
defeat
'
,
this
);
console
.
log
(
'
[
'
+
this
.
id
+
'
] defeated, rank:
'
+
this
.
rank
);
if
(
socket
.
playerData
.
currentRoom
.
aliveCount
===
1
)
{
let
winner
=
room
.
currentPlayer
.
find
(
function
(
element
)
{
return
element
.
isAlive
;
});
room
.
announceToRoom
(
'
gameEnd
'
,
winner
);
room
.
announceToTarget
(
winner
.
id
,
'
alert
'
,
'
gameWin
'
);
console
.
log
(
'
[
'
+
winner
.
id
+
'
]
'
+
'
winner!
'
+
winner
.
nickname
);
}
}
}
module
.
exports
=
GameServer
;
\ No newline at end of file
index.html
View file @
11a48a49
...
...
@@ -13,6 +13,7 @@
<script
src=
"js/CSVParsing.js"
></script>
<script
src=
"js/SelectWord.js"
></script>
<script
src=
"js/BGMsound.js"
></script>
<script
src=
"js/Enums.js"
></script>
</head>
<body>
<script
src=
"js/Client.js"
></script>
...
...
js/Background.js
View file @
11a48a49
...
...
@@ -6,7 +6,8 @@ BackGround.myCharacter = null;
BackGround
.
loadImage
=
function
(
scene
)
{
scene
.
load
.
image
(
'
brainGround
'
,
'
assets/image/background/background_brain.png
'
);
scene
.
load
.
image
(
'
menuBackground
'
,
'
assets/placeholder/menuBackground.png
'
)
scene
.
load
.
image
(
'
menuBackground
'
,
'
assets/placeholder/menuBackground.png
'
);
scene
.
load
.
image
(
'
roomBackground
'
,
'
assets/placeholder/roomBackground.png
'
);
}
BackGround
.
drawCharacter
=
function
(
scene
)
...
...
@@ -22,4 +23,9 @@ BackGround.drawBrain = function(scene)
BackGround
.
drawMenu
=
function
(
scene
)
{
scene
.
add
.
sprite
(
640
,
360
,
'
menuBackground
'
).
setDisplaySize
(
1282
,
722
).
setDepth
(
1
);
}
BackGround
.
drawRoom
=
function
(
scene
)
{
scene
.
add
.
sprite
(
640
,
360
,
'
roomBackground
'
).
setDisplaySize
(
1282
,
722
).
setDepth
(
1
);
}
\ No newline at end of file
js/Client.js
View file @
11a48a49
...
...
@@ -14,27 +14,84 @@ socket.on('alert', function(msg) // string errorcode
socket
.
on
(
'
setId
'
,
function
(
msg
)
// {str, num playerNum}
{
console
.
log
(
msg
.
str
);
PlayerData
.
id
Num
=
msg
.
num
;
PlayerData
.
id
=
msg
.
num
;
});
socket
.
on
(
'
enterRoom
'
,
function
()
{
Audio
.
killSound
(
ScenesData
.
menuScene
,
'
login
'
);
game
.
scene
.
remove
(
'
menuScene
'
);
game
.
scene
.
start
(
'
roomScene
'
);
});
socket
.
on
(
'
s
etCount
'
,
function
(
msg
)
socket
.
on
(
'
s
yncRoomScene
'
,
function
(
msg
)
{
ScenesData
.
roomScene
.
isCounting
=
msg
.
isEnable
;
ScenesData
.
roomScene
.
endTime
=
msg
.
endTime
;
setTimeout
(
function
()
{
for
(
let
i
=
0
;
i
<
msg
.
length
;
i
++
)
{
let
randX
=
Math
.
random
()
*
1120
+
80
;
let
randY
=
Math
.
random
()
*
380
+
100
;
var
playerSet
=
{
sprite
:
ScenesData
.
roomScene
.
add
.
sprite
(
randX
,
randY
,
'
playerStand
'
).
setOrigin
(
0.5
,
0.5
).
setScale
(
0.2
,
0.2
),
nickname
:
ScenesData
.
roomScene
.
add
.
text
(
randX
-
10
,
randY
-
60
,
msg
[
i
].
nickname
).
setOrigin
(
0.5
,
0.5
).
setColor
(
'
#000000
'
).
setPadding
(
0.5
,
0.5
,
0.5
,
0.5
),
id
:
msg
[
i
].
id
}
ScenesData
.
roomScene
.
players
.
push
(
playerSet
);
}
},
100
);
});
socket
.
on
(
'
setRoomCount
'
,
function
(
msg
)
{
setTimeout
(
function
()
{
ScenesData
.
roomScene
.
isCounting
=
msg
.
isEnable
;
ScenesData
.
roomScene
.
endTime
=
msg
.
endTime
;
ScenesData
.
roomScene
.
peopleCount
=
msg
.
playerCount
;
if
(
msg
.
isEnter
)
// generate charactor
{
let
randX
=
Math
.
random
()
*
1120
+
80
;
let
randY
=
Math
.
random
()
*
380
+
100
;
var
playerSet
=
{
sprite
:
ScenesData
.
roomScene
.
add
.
sprite
(
randX
,
randY
,
'
playerStand
'
).
setOrigin
(
0.5
,
0.5
).
setScale
(
0.2
,
0.2
),
nickname
:
ScenesData
.
roomScene
.
add
.
text
(
randX
-
10
,
randY
-
60
,
msg
.
player
.
nickname
).
setOrigin
(
0.5
,
0.5
).
setColor
(
'
#000000
'
).
setPadding
(
0.5
,
0.5
,
0.5
,
0.5
),
id
:
msg
.
player
.
id
}
ScenesData
.
roomScene
.
players
.
push
(
playerSet
);
}
else
// remove charactor
{
let
idx
=
ScenesData
.
roomScene
.
players
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
msg
.
player
.
id
;
});
if
(
idx
!=
-
1
)
{
ScenesData
.
roomScene
.
players
[
idx
].
sprite
.
destroy
();
ScenesData
.
roomScene
.
players
[
idx
].
nickname
.
destroy
();
ScenesData
.
roomScene
.
players
.
splice
(
idx
,
1
);
}
}
},
200
);
});
// init game
socket
.
on
(
'
syncRoomData
'
,
function
(
msg
)
// {num roomNum, [] players}
{
console
.
log
(
msg
);
RoomData
.
room
Num
=
msg
.
roomNum
;
//
console.log(msg);
RoomData
.
room
Id
=
msg
.
roomId
;
RoomData
.
players
=
msg
.
players
;
RoomData
.
aliveCount
=
msg
.
players
.
length
;
RoomData
.
players
.
forEach
(
function
(
element
)
{
if
(
element
.
id
===
PlayerData
.
id
)
{
RoomData
.
myself
=
element
;
return
;
}
});
});
socket
.
on
(
'
startGame
'
,
function
()
{
...
...
@@ -55,9 +112,10 @@ socket.on('setPlayerTypingRate', function(msg) // number playerTypingRate
});
socket
.
on
(
'
attacked
'
,
function
(
msg
)
// object attackData
{
//console.log('attacked by ' + msg.attacker.nickname);
setTimeout
(
function
()
{
WordSpace
.
generateWord
.
Attack
(
ScenesData
.
gameScene
,
msg
.
text
,
msg
.
grade
,
msg
.
attacker
,
msg
.
isStrong
);
WordSpace
.
generateWord
.
Attack
(
ScenesData
.
gameScene
,
msg
.
text
,
msg
.
grade
,
msg
.
attacker
,
msg
.
isStrong
,
msg
.
isCountable
);
},
4000
);
});
socket
.
on
(
'
defeat
'
,
function
(
msg
)
// object player
...
...
js/Enums.js
View file @
11a48a49
var
Enums
=
Enums
||
{};
\ No newline at end of file
var
Enums
=
Enums
||
{};
Enums
.
characterAnim
=
{
write
:
0
,
attackWrite
:
1
,
throw
:
2
,
hit
:
3
}
\ No newline at end of file
js/ScenesData.js
View file @
11a48a49
...
...
@@ -42,29 +42,64 @@ var roomScene = new Phaser.Class(
preload
:
function
()
{
ScenesData
.
roomScene
=
this
;
BackGround
.
loadImage
(
this
);
this
.
load
.
image
(
'
playerStand
'
,
'
assets/image/character/pyeongmin/pyeong_stand.png
'
);
},
create
:
function
()
{
BackGround
.
drawRoom
(
this
);
this
.
players
=
[];
this
.
isCounting
=
false
;
this
.
isCountEnd
=
false
;
this
.
endTime
=
0
;
this
.
peopleCount
=
1
;
this
.
countText
=
this
.
add
.
text
(
640
,
360
,
'
사람들을 위해 대기중입니다...
'
).
setOrigin
(
0.5
,
0.5
).
setColor
(
'
#000000
'
);
this
.
peopleText
=
this
.
add
.
text
(
640
,
100
,
'
1 / 10
'
).
setOrigin
(
0.5
,
0.5
).
setColor
(
'
#000000
'
);
this
.
countText
=
this
.
add
.
text
(
640
,
360
,
'
사람들을 위해 대기중입니다...
'
).
setOrigin
(
0.5
,
0.5
).
setColor
(
'
#000000
'
)
.
setBackgroundColor
(
'
#ffffff
'
).
setDepth
(
10
).
setPadding
(
5
,
5
,
5
,
5
)
;
this
.
peopleText
=
this
.
add
.
text
(
640
,
80
,
'
1 / 10
'
).
setOrigin
(
0.5
,
0.5
).
setColor
(
'
#000000
'
).
setBackgroundColor
(
'
#ffffff
'
).
setDepth
(
10
);
},
update
:
function
()
{
this
.
peopleText
.
setText
(
this
.
peopleCount
+
'
/ 10
'
);
if
(
this
.
isCounting
)
{
this
.
countText
.
setText
(((
this
.
endTime
-
Date
.
now
())
/
1000
).
toFixed
(
1
));
if
(
this
.
endTime
-
Date
.
now
()
<
0
)
if
(
this
.
endTime
<
Date
.
now
()
)
{
socket
.
emit
(
'
endCount
'
);
//console.log('end Count');
setTimeout
(()
=>
{
socket
.
emit
(
'
endCount
'
);
},
(
Phaser
.
Math
.
Distance
.
Between
(
0
,
0
,
640
,
800
)
*
3
));
this
.
isCounting
=
false
;
this
.
isCountEnd
=
true
;
this
.
players
.
forEach
(
function
(
element
){
element
.
follower
=
{
t
:
0
,
vec
:
new
Phaser
.
Math
.
Vector2
()
};
element
.
path
=
new
Phaser
.
Curves
.
Line
([
element
.
sprite
.
x
,
element
.
sprite
.
y
,
640
,
800
]);
ScenesData
.
roomScene
.
tweens
.
add
({
targets
:
element
.
follower
,
t
:
1
,
ease
:
'
Linear
'
,
duration
:
Phaser
.
Math
.
Distance
.
Between
(
element
.
sprite
.
x
,
element
.
sprite
.
y
,
640
,
800
)
*
3
,
repeat
:
0
});
});
}
}
else
if
(
this
.
isCountEnd
)
{
this
.
players
.
forEach
(
function
(
element
){
element
.
path
.
getPoint
(
element
.
follower
.
t
,
element
.
follower
.
vec
);
element
.
sprite
.
setPosition
(
element
.
follower
.
vec
.
x
,
element
.
follower
.
vec
.
y
);
element
.
nickname
.
setPosition
(
element
.
sprite
.
x
-
10
,
element
.
sprite
.
y
-
60
);
});
this
.
countText
.
setText
(
'
잠시만 기다려주세요...
'
);
}
else
{
this
.
countText
.
setText
(
'
사람들을 위해 대기중입니다...
'
);
...
...
@@ -95,6 +130,8 @@ var gameScene = new Phaser.Class(
create
:
function
()
{
WordSpace
.
gameTimer
=
new
Phaser
.
Time
.
Clock
(
this
);
WordSpace
.
gameTimer
.
start
();
WordSpace
.
loadAnimation
(
this
);
CSVParsing
.
CSVParse
(
this
);
BackGround
.
drawBrain
(
this
);
...
...
@@ -119,14 +156,8 @@ var gameScene = new Phaser.Class(
WordSpace
.
nameWordTextForTest
=
ScenesData
.
gameScene
.
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
;
}
});
// for test
WordSpace
.
attackGauge
.
add
(
11
);
},
...
...
js/WordObject.js
View file @
11a48a49
class
WordObject
{
constructor
(
text
,
isNameWord
=
false
)
{
this
.
generationCode
=
WordSpace
.
nextWordCode
++
;
this
.
wordText
=
text
;
this
.
wordTyping
=
WordReader
.
getWordTyping
(
this
.
wordText
);
this
.
wordGrade
=
WordReader
.
getWordGrade
(
this
.
wordTyping
);
this
.
wordWeight
=
WordReader
.
getWordWeight
(
this
.
wordGrade
)
;
this
.
wordWeight
=
WordReader
.
normalWeight
[
3
-
this
.
wordGrade
]
;
//console.log("wordTyping : " + this.wordTyping + '\n' + "wordGrade : " + this.wordGrade + '\n' + "wordWeight : " + this.wordWeight + '\n');
this
.
wordSpeed
=
0.5
;
this
.
isNameWord
=
isNameWord
;
...
...
@@ -49,10 +50,11 @@ class WordObject
{
fontSize
:
(
this
.
scale
*
this
.
fontScale
)
+
'
pt
'
,
fontFamily
:
'
"궁서", 궁서체, serif
'
,
fontStyle
:
(
this
.
wordWeight
>
5
?
'
bold
'
:
''
)
//
fontStyle: (this.wordWeight > 5 ? 'bold' : '')
});
if
(
!
this
.
isNameWord
)
this
.
wordObj
.
setColor
(
'
#000000
'
).
setOrigin
(
0.5
,
0.5
);
else
this
.
wordObj
.
setColor
(
'
#ffffff
'
).
setOrigin
(
0.45
,
0.5
);
this
.
createdTime
=
WordSpace
.
gameTimer
.
now
;
WordSpace
.
totalWeight
+=
this
.
wordWeight
;
WordSpace
.
totalWordNum
+=
1
;
WordSpace
.
setGameOverTimer
();
...
...
@@ -79,7 +81,7 @@ class WordObject
this
.
wordObj
.
destroy
();
this
.
physicsObj
.
destroy
();
}
BackGround
.
myCharacter
.
play
(
WordSpace
.
pyeongminAnims
[
0
]);
BackGround
.
myCharacter
.
play
(
WordSpace
.
pyeongminAnims
[
Enums
.
characterAnim
.
write
]);
}
attract
()
...
...
@@ -136,20 +138,50 @@ class NormalWord extends WordObject
class
AttackWord
extends
WordObject
{
constructor
(
text
,
_wordGrade
,
_playerData
,
isStrong
)
constructor
(
text
,
_wordGrade
,
_playerData
,
_isStrong
,
_isCountable
=
true
,
lenRate
)
{
super
(
text
);
this
.
wordGrade
=
_wordGrade
;
this
.
wordWeight
=
WordReader
.
getWordWeight
(
this
.
wordGrade
)
;
this
.
wordWeight
=
_isStrong
?
WordReader
.
strongAttackWeight
[
3
-
this
.
wordGrade
]
:
WordReader
.
attackWeight
[
3
-
this
.
wordGrade
]
;
if
(
WordReader
.
getWordTyping
(
_playerData
.
nickname
)
>
9
)
this
.
wordWeight
+=
this
.
wordWeight
*
0.2
*
(
WordReader
.
getWordTyping
(
_playerData
.
nickname
)
-
9
);
this
.
wordWeight
*=
isStrong
?
3
:
2
;
this
.
attacker
=
_playerData
;
this
.
counterTime
=
WordSpace
.
gameTimer
.
now
+
1000
*
(
this
.
wordTyping
<=
(
5
-
_wordGrade
)
*
2.5
?
this
.
wordTyping
/
(
Math
.
max
(
200
,
WordSpace
.
playerTyping
)
/
60
)
*
1.5
:
if
(
!
_isCountable
)
this
.
counterTime
=
0
;
else
this
.
counterTime
=
WordSpace
.
gameTimer
.
now
+
1000
*
(
this
.
wordTyping
<=
(
5
-
_wordGrade
)
*
2.5
?
this
.
wordTyping
/
(
Math
.
max
(
200
,
WordSpace
.
playerTyping
)
/
60
)
*
1.5
:
((
5
-
_wordGrade
)
*
3
+
(
this
.
wordTyping
-
(
5
-
_wordGrade
)
*
2.5
)
*
2.5
)
/
(
Math
.
max
(
200
,
WordSpace
.
playerTyping
)
/
60
)
*
1.5
);
console
.
log
(
'
Attack text :
'
+
text
+
'
, Attacker :
'
+
this
.
attacker
.
nickname
+
'
, Weight :
'
+
this
.
wordWeight
);
console
.
log
(
'
Counter time :
'
+
this
.
counterTime
);
}
instantiate
(
scene
,
lenRate
)
{
super
.
instantiate
(
scene
,
lenRate
);
this
.
maskBackground
=
scene
.
physics
.
add
.
sprite
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
,
'
wordBgr
'
+
this
.
wordGrade
+
'
_
'
+
Math
.
min
(
Math
.
max
(
2
,
this
.
wordText
.
length
),
6
))
.
setTint
(
Phaser
.
Display
.
Color
.
GetColor
(
120
,
120
,
120
)).
setScale
(
this
.
scale
);
this
.
maskBackground
.
alpha
=
0.5
;
this
.
shape
=
scene
.
make
.
graphics
();
var
rect
=
new
Phaser
.
Geom
.
Rectangle
(
0
,
0
,
this
.
maskBackground
.
width
*
this
.
scale
,
this
.
maskBackground
.
height
*
this
.
scale
);
this
.
shape
.
fillStyle
(
0xffffff
).
fillRectShape
(
rect
);
this
.
mask
=
this
.
shape
.
createGeometryMask
();
this
.
maskBackground
.
setMask
(
this
.
mask
);
this
.
maskStart
=
this
.
physicsObj
.
x
;
this
.
maskEnd
=
this
.
physicsObj
.
x
-
this
.
physicsObj
.
width
*
this
.
scale
;
}
attract
()
{
super
.
attract
();
if
(
WordSpace
.
gameTimer
.
now
<
this
.
counterTime
)
{
this
.
maskBackground
.
setPosition
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
);
this
.
shape
.
x
=
this
.
physicsObj
.
x
+
(
this
.
maskEnd
-
this
.
maskStart
)
*
((
WordSpace
.
gameTimer
.
now
-
this
.
createdTime
)
/
(
this
.
counterTime
-
this
.
createdTime
))
-
this
.
physicsObj
.
width
*
this
.
scale
/
2
;
this
.
shape
.
y
=
this
.
physicsObj
.
y
-
this
.
physicsObj
.
height
*
this
.
scale
/
2
;
}
else
if
(
this
.
maskBackground
!=
null
)
this
.
maskBackground
.
destroy
();
}
destroy
()
{
switch
(
this
.
wordGrade
)
...
...
@@ -162,11 +194,23 @@ class AttackWord extends WordObject
}
if
(
WordSpace
.
gameTimer
.
now
<
this
.
counterTime
)
{
console
.
log
(
this
.
attacker
);
let
tempWord
=
WordSpace
.
generateWord
.
Name
(
ScenesData
.
gameScene
,
true
,
this
.
attacker
);
tempWord
.
physicsObj
.
setPosition
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
);
tempWord
.
wordObj
.
setPosition
(
tempWord
.
physicsObj
.
x
,
tempWord
.
physicsObj
.
y
);
tempWord
.
destroy
();
let
attackData
=
{
roomNum
:
RoomData
.
roomId
,
attacker
:
RoomData
.
myself
,
target
:
this
.
attacker
.
id
,
text
:
this
.
wordText
,
grade
:
Math
.
min
(
3
,
this
.
wordGrade
+
1
),
isStrong
:
false
,
isCountable
:
false
}
socket
.
emit
(
'
attack
'
,
attackData
);
}
//WordSpace.nameGroup.push(new NameWord(this.attacker, true)
);
if
(
this
.
maskBackground
!=
null
)
this
.
maskBackground
.
destroy
(
);
super
.
destroy
();
}
}
...
...
@@ -185,7 +229,8 @@ class NameWord extends WordObject
attract
()
{
if
(
this
.
isActive
)
super
.
attract
();
else
{
else
{
this
.
path
.
getPoint
(
this
.
follower
.
t
,
this
.
follower
.
vec
);
this
.
physicsObj
.
setPosition
(
this
.
follower
.
vec
.
x
,
this
.
follower
.
vec
.
y
);
this
.
wordObj
.
setPosition
(
this
.
physicsObj
.
x
,
this
.
physicsObj
.
y
);
...
...
js/WordReader.js
View file @
11a48a49
...
...
@@ -54,9 +54,6 @@ WordReader.getWordGrade = function(_wordTyping)
17
<=
_wordTyping
&&
_wordTyping
<
26
?
0
:
-
1
;
}
WordReader
.
getWordWeight
=
function
(
_wordGrade
)
{
return
_wordGrade
==
3
?
3
:
_wordGrade
==
2
?
5
:
_wordGrade
==
1
?
7
:
10
;
}
\ No newline at end of file
WordReader
.
normalWeight
=
[
3
,
5
,
7
,
10
];
WordReader
.
attackWeight
=
[
6
,
8
,
12
,
15
];
WordReader
.
strongAttackWeight
=
[
10
,
13
,
16
,
20
];
\ No newline at end of file
js/WordSpace.js
View file @
11a48a49
...
...
@@ -256,20 +256,27 @@ WordSpace.loadAnimation = function(scene)
repeat
:
0
,
hideOnComplete
:
false
});
WordSpace
.
pyeongminAnims
.
push
(
scene
.
anims
.
create
({
key
:
'
write
'
,
WordSpace
.
pyeongminAnims
[
Enums
.
characterAnim
.
write
]
=
scene
.
anims
.
create
({
key
:
'
pyeongminWriteAnim
'
,
frames
:
scene
.
anims
.
generateFrameNumbers
(
'
pyeongminWrite
'
),
frameRate
:
10
,
repeat
:
0
,
hideOnComplete
:
false
}));
WordSpace
.
pyeongminAnims
.
push
(
scene
.
anims
.
create
({
key
:
'
throw
'
,
});
WordSpace
.
pyeongminAnims
[
Enums
.
characterAnim
.
attackWrite
]
=
scene
.
anims
.
create
({
key
:
'
pyeongminattackWriteAnim
'
,
frames
:
scene
.
anims
.
generateFrameNumbers
(
'
pyeongminWrite
'
),
frameRate
:
10
,
repeat
:
-
1
,
hideOnComplete
:
false
});
WordSpace
.
pyeongminAnims
[
Enums
.
characterAnim
.
throw
]
=
scene
.
anims
.
create
({
key
:
'
pyeongminThrowAnim
'
,
frames
:
scene
.
anims
.
generateFrameNumbers
(
'
pyeongminThrow
'
),
frameRate
:
10
,
repeat
:
0
,
hideOnComplete
:
false
})
)
;
});
}
WordSpace
.
generateWord
=
...
...
@@ -280,9 +287,9 @@ WordSpace.generateWord =
WordSpace
.
pushWord
(
scene
,
word
,
lenRate
);
return
word
;
},
Attack
:
function
(
scene
,
wordText
,
grade
,
attacker
,
isStrong
,
lenRate
)
Attack
:
function
(
scene
,
wordText
,
grade
,
attacker
,
isStrong
,
isCountable
,
lenRate
)
{
word
=
new
AttackWord
(
wordText
,
grade
,
attacker
,
isStrong
);
word
=
new
AttackWord
(
wordText
,
grade
,
attacker
,
isStrong
,
isCountable
);
WordSpace
.
pushWord
(
scene
,
word
,
lenRate
);
return
word
;
},
...
...
@@ -373,6 +380,8 @@ WordSpace.findWord = function(wordText)
Input
.
attackMode
=
true
;
WordSpace
.
attackGauge
.
pauseCycle
(
true
);
WordSpace
.
setPlayerTyping
.
add
(
wordText
);
BackGround
.
myCharacter
.
play
(
WordSpace
.
pyeongminAnims
[
Enums
.
characterAnim
.
attackWrite
]);
BackGround
.
myCharacter
.
anims
.
msPerFrame
/=
(
4
-
WordSpace
.
attackGauge
.
getAttackOption
().
wordGrade
);
}
else
// 오타 체크
{
...
...
@@ -394,7 +403,7 @@ WordSpace.findWord = function(wordText)
console
.
log
(
'
Attack word :
'
+
element
.
wordText
+
'
of
'
+
element
.
attacker
.
nickname
+
'
오타임
'
);
let
victimData
=
{
roomNum
:
RoomData
.
room
Num
,
roomNum
:
RoomData
.
room
Id
,
victim
:
RoomData
.
myself
,
target
:
element
.
attacker
.
id
}
...
...
@@ -417,8 +426,6 @@ WordSpace.setPlayerTyping =
},
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
'
);
}
}
...
...
@@ -431,9 +438,10 @@ WordSpace.attack = function(wordText, grade)
console
.
log
(
'
attack
'
+
wordText
+
'
, grade:
'
+
grade
);
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
//console.log(RoomData.myself);
let
attackData
=
{
roomNum
:
RoomData
.
room
Num
,
roomNum
:
RoomData
.
room
Id
,
attacker
:
RoomData
.
myself
,
target
:
element
.
ownerId
,
text
:
wordText
,
...
...
@@ -450,7 +458,7 @@ WordSpace.attack = function(wordText, grade)
WordSpace
.
attackGauge
.
resetValue
();
WordSpace
.
setPlayerTyping
.
add
(
wordText
);
BackGround
.
myCharacter
.
play
(
WordSpace
.
pyeongminAnims
[
1
]);
BackGround
.
myCharacter
.
play
(
WordSpace
.
pyeongminAnims
[
Enums
.
characterAnim
.
throw
]);
}
else
WordSpace
.
attackGauge
.
cutValue
(
0.3
);
Input
.
maxInput
=
6
;
...
...
@@ -463,8 +471,10 @@ WordSpace.nameQueue =
queue
:
[],
shuffle
:
function
()
{
let
tempIdx
,
tempElement
,
tempLength
;
let
tempQueue
=
RoomData
.
players
;
let
tempIdx
,
tempElement
,
tempLength
,
tempQueue
=
[];
RoomData
.
players
.
forEach
(
function
(
element
){
tempQueue
.
push
(
element
.
index
)
})
for
(
tempLength
=
tempQueue
.
length
;
tempLength
;
tempLength
-=
1
)
{
tempIdx
=
Math
.
floor
(
Math
.
random
()
*
tempLength
);
...
...
@@ -474,7 +484,7 @@ WordSpace.nameQueue =
}
tempQueue
.
forEach
(
function
(
element
)
{
if
(
element
.
id
!=
PlayerData
.
idNum
&&
element
.
isAlive
)
if
(
RoomData
.
players
[
element
].
id
!=
PlayerData
.
id
&&
RoomData
.
players
[
element
]
.
isAlive
)
WordSpace
.
nameQueue
.
queue
.
push
(
element
);
});
},
...
...
@@ -482,7 +492,8 @@ WordSpace.nameQueue =
{
let
tempElement
=
WordSpace
.
nameQueue
.
queue
.
shift
();
if
(
WordSpace
.
nameQueue
.
queue
.
length
<=
RoomData
.
aliveCount
)
this
.
shuffle
();
return
tempElement
;
if
(
!
RoomData
.
players
[
tempElement
].
isAlive
)
return
WordSpace
.
nameQueue
.
pop
();
else
return
RoomData
.
players
[
tempElement
];
},
initiate
:
function
()
{
...
...
js/main.js
View file @
11a48a49
...
...
@@ -23,13 +23,13 @@ var game = new Phaser.Game(config)
//테스트용이므로 차후 수정 요망
var
PlayerData
=
PlayerData
||
{};
PlayerData
.
id
Num
=
-
1
;
//플레이어 아이디, 고유 번호
PlayerData
.
id
=
-
1
;
//플레이어 아이디, 고유 번호
PlayerData
.
nickname
=
'
홍길동
'
;
//플레이어 닉네임
// 현재 들어가있는 Game Room의 정보
var
RoomData
=
RoomData
||
{};
RoomData
.
room
Num
=
-
1
;
RoomData
.
room
Id
=
-
1
;
RoomData
.
myself
=
null
;
RoomData
.
players
=
null
;
RoomData
.
aliveCount
=
-
1
;
\ No newline at end of file
server.js
View file @
11a48a49
...
...
@@ -25,12 +25,11 @@ io.on('connection', function(socket)
{
id
:
GameServer
.
getPlayerNumber
(),
nickname
:
'
게스트
'
,
socketId
:
socket
,
currentRoom
:
null
,
playingData
:
null
,
isReceivable
:
false
};
GameServer
.
currentPlayer
.
push
(
socket
.
playerData
);
GameServer
.
currentPlayer
.
push
(
socket
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client request
'
);
socket
.
emit
(
'
setId
'
,
{
...
...
@@ -44,14 +43,14 @@ io.on('connection', function(socket)
let
isAlreadyHave
=
false
;
GameServer
.
currentPlayer
.
forEach
(
function
(
element
)
{
if
(
element
.
nickname
===
msg
)
isAlreadyHave
=
true
;
if
(
element
.
playerData
.
nickname
===
msg
)
isAlreadyHave
=
true
;
});
if
(
isAlreadyHave
)
socket
.
emit
(
'
alert
'
,
'
errNicknameOverlaped
'
);
else
{
socket
.
playerData
.
nickname
=
msg
;
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] nickname set to
'
+
msg
);
GameServer
.
enterEmptyRoom
(
socket
.
playerData
);
GameServer
.
enterEmptyRoom
(
socket
);
}
});
...
...
@@ -76,15 +75,15 @@ io.on('connection', function(socket)
socket
.
playerData
.
currentRoom
.
aliveCount
--
;
if
(
socket
.
playerData
.
currentRoom
.
aliveCount
===
0
)
{
GameServer
.
startRoom
(
GameServer
.
findRoomIndex
(
socket
.
playerData
.
currentRoom
.
roomNum
)
);
socket
.
playerData
.
currentRoom
.
startRoom
(
);
}
});
socket
.
on
(
'
attack
'
,
function
(
msg
)
{
GameServer
.
announceToTarget
(
GameServer
.
findRoomIndex
(
msg
.
roomNum
),
msg
.
target
,
'
attacked
'
,
msg
);
//console.log('
find ' + msg.target + ' by ' + msg.attacker.idNum
+ ' with ' + msg.text);
let
target
=
GameServer
.
findPlayer
(
msg
.
target
);
socket
.
playerData
.
currentRoom
.
announceToTarget
(
msg
.
target
,
'
attacked
'
,
msg
);
//console.log('
attack ' + msg.target + ' by ' + msg.attacker.id
+ ' with ' + msg.text);
let
target
=
GameServer
.
findPlayer
Socket
(
msg
.
target
);
if
(
target
!=
null
)
{
let
dataToPush
=
...
...
@@ -96,23 +95,23 @@ io.on('connection', function(socket)
time
:
Date
.
now
()
}
if
(
target
.
play
ingData
.
lastAttacks
.
length
<
5
)
target
.
playingData
.
lastAttacks
.
push
(
dataToPush
);
if
(
target
.
play
erData
.
playingData
.
lastAttacks
.
length
<
5
)
target
.
playerData
.
playingData
.
lastAttacks
.
push
(
dataToPush
);
else
{
target
.
playingData
.
lastAttacks
.
splice
(
0
,
1
);
target
.
playingData
.
lastAttacks
.
push
(
dataToPush
);
target
.
play
erData
.
play
ingData
.
lastAttacks
.
splice
(
0
,
1
);
target
.
play
erData
.
play
ingData
.
lastAttacks
.
push
(
dataToPush
);
}
}
});
socket
.
on
(
'
defeated
'
,
function
()
{
GameServer
.
playerDefeat
(
socket
.
playerData
);
socket
.
playerData
.
playingData
.
defeat
(
);
});
socket
.
on
(
'
defenseFailed
'
,
function
(
msg
)
{
GameServer
.
announceToTarget
(
GameServer
.
findRoomIndex
(
msg
.
roomNum
),
msg
.
target
,
'
attackSucceed
'
,
msg
);
socket
.
playerData
.
currentRoom
.
announceToTarget
(
msg
.
target
,
'
attackSucceed
'
,
msg
);
});
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
...
...
@@ -128,31 +127,38 @@ io.on('connection', function(socket)
console
.
log
(
'
[
'
+
data
.
id
+
'
] client disconnected, reason:
'
+
reason
);
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
data
.
id
;
return
element
.
playerData
.
id
===
data
.
id
;
});
if
(
idxToDel
!=
-
1
)
{
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
// 룸에서도 제거
if
(
data
.
currentRoom
!=
null
)
{
if
(
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
READY
||
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
COUNT
)
{
data
.
currentRoom
.
currentPlayer
[
data
.
playingData
.
index
]
=
null
;
data
.
currentRoom
.
currentSocket
[
data
.
playingData
.
index
]
=
null
;
data
.
currentRoom
.
aliveCount
--
;
if
(
data
.
currentRoom
.
aliveCount
<
GameServer
.
startCount
)
data
.
currentRoom
.
exitRoom
(
data
.
id
);
if
(
data
.
currentRoom
.
aliveCount
<
data
.
currentRoom
.
startCount
)
{
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
data
.
currentRoom
.
roomNum
),
'
setCount
'
,
{
isEnable
:
false
,
endTime
:
0
});
data
.
currentRoom
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
false
,
endTime
:
0
,
playerCount
:
data
.
currentRoom
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
data
.
playingData
});
data
.
currentRoom
.
currentPhase
=
GameServer
.
Phase
.
READY
;
}
else
data
.
currentRoom
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
true
,
endTime
:
data
.
currentRoom
.
endTime
,
playerCount
:
data
.
currentRoom
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
data
.
playingData
});
}
else
if
(
data
.
playingData
.
isAlive
)
{
GameServer
.
playerDefeat
(
socket
.
playerData
);
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
data
.
currentRoom
.
roomNum
),
'
userDisconnect
'
,
data
.
playingData
);
data
.
playingData
.
defeat
(
);
data
.
currentRoom
.
announceToRoom
(
'
userDisconnect
'
,
data
.
playingData
);
}
}
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
}
console
.
log
(
'
[
'
+
data
.
id
+
'
] disconnect complete
'
);
}
...
...
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