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
95b3b93e
Commit
95b3b93e
authored
Jul 17, 2019
by
18신대성
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
서버의 많은 부분을 뜯어고침
게임룸 클래스화
parent
61daf001
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
255 additions
and
185 deletions
+255
-185
GameServer.js
GameServer.js
+214
-148
Client.js
js/Client.js
+13
-3
ScenesData.js
js/ScenesData.js
+3
-8
WordSpace.js
js/WordSpace.js
+4
-3
main.js
js/main.js
+2
-2
server.js
server.js
+19
-21
No files found.
GameServer.js
View file @
95b3b93e
var
GameServer
=
GameServer
||
{};
var
GameServer
=
GameServer
||
{};
GameServer
.
Phase
=
{
READY
:
0
,
COUNT
:
-
1
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
Phase
=
{
READY
:
0
,
COUNT
:
-
1
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
startCount
=
2
;
GameServer
.
currentPlayer
=
[];
GameServer
.
currentPlayer
=
[];
GameServer
.
playingRoom
=
[];
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
(
GameServer
.
playingRoom
[
i
].
roomId
===
roomId
)
return
GameServer
.
playingRoom
[
i
]
;
if
(
!
this
.
currentPlayer
.
includes
(
num
))
return
num
;
}
}
while
(
true
)
console
.
log
(
'
[ERR] no room with num
'
+
roomId
);
}
}
GameServer
.
findPlayer
=
function
(
playerId
)
GameServer
.
findPlayer
Socket
=
function
(
playerId
)
{
{
var
idx
=
this
.
currentPlayer
.
findIndex
(
function
(
element
)
var
idx
=
this
.
currentPlayer
.
findIndex
(
function
(
element
)
{
{
return
element
.
id
===
playerId
;
return
element
.
playerData
.
id
===
playerId
;
});
});
if
(
idx
!=
-
1
)
return
this
.
currentPlayer
[
idx
];
if
(
idx
!=
-
1
)
return
this
.
currentPlayer
[
idx
];
else
else
...
@@ -27,192 +26,220 @@ GameServer.findPlayer = function(playerId)
...
@@ -27,192 +26,220 @@ GameServer.findPlayer = function(playerId)
return
null
;
return
null
;
}
}
}
}
GameServer
.
nextRoomNumber
=
0
;
GameServer
.
enterEmptyRoom
=
function
(
playerSocket
)
GameServer
.
makeRoom
=
function
()
{
{
// 나중에 room 삭제시 생긴 null에 채워넣는식으로 만들것, 룸의 인덱스를 고정
let
emptyRoomIndex
=
-
1
;
var
roomOption
=
for
(
let
i
=
0
;
i
<
this
.
playingRoom
.
length
;
i
++
)
{
{
roomNum
:
GameServer
.
nextRoomNumber
++
,
if
((
this
.
playingRoom
[
i
].
currentPhase
===
this
.
Phase
.
READY
||
this
.
playingRoom
[
i
].
currentPhase
===
this
.
Phase
.
COUNT
)
&&
this
.
playingRoom
[
i
].
maxPlayer
>
this
.
playingRoom
[
i
].
currentPlayer
.
length
)
maxPlayer
:
100
,
{
nextRank
:
100
,
emptyRoomIndex
=
i
;
currentPlayer
:
[],
break
;
aliveCount
:
0
,
}
currentSocket
:
[],
}
currentPhase
:
GameServer
.
Phase
.
READY
,
if
(
emptyRoomIndex
!=
-
1
)
endTime
:
0
,
{
this
.
playingRoom
[
emptyRoomIndex
].
enterRoom
(
playerSocket
);
rateArrangePoint
:
300
,
}
maxTypingPlayer
:
null
,
else
minTypingPlayer
:
null
{
}
let
newRoom
=
new
GameRoom
();
this
.
playingRoom
.
push
(
roomOption
);
newRoom
.
enterRoom
(
playerSocket
);
console
.
log
(
'
[SERVER] new room #
'
+
roomOption
.
roomNum
+
'
made, roomCount:
'
+
this
.
playingRoom
.
length
);
}
return
this
.
playingRoom
.
length
-
1
;
}
}
GameServer
.
findRoomIndex
=
function
(
roomNum
)
GameServer
.
getPlayerNumber
=
function
(
)
{
{
return
GameServer
.
playingRoom
.
findIndex
(
function
(
element
)
do
{
{
return
element
.
roomNum
===
roomNum
;
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
)
}
}
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
class
GameRoom
{
{
let
room
=
this
.
playingRoom
[
roomIdx
];
constructor
()
let
nextIdx
=
-
1
;
for
(
let
i
=
0
;
i
<
room
.
currentPlayer
.
length
;
i
++
)
{
{
if
(
room
.
currentPlayer
[
i
]
===
null
)
this
.
roomId
=
GameServer
.
getRoomNumber
();
this
.
roomIndex
=
-
1
;
this
.
startCount
=
2
;
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
)
{
{
nextId
x
=
i
;
this
.
roomInde
x
=
i
;
break
break
;
}
}
}
}
let
player
=
new
Player
((
nextIdx
!=
-
1
?
nextIdx
:
room
.
currentPlayer
.
length
),
playerData
);
if
(
this
.
roomIndex
===
-
1
)
if
(
nextIdx
!=
-
1
)
{
{
room
.
currentPlayer
[
nextIdx
]
=
player
;
this
.
roomIndex
=
GameServer
.
playingRoom
.
length
;
room
.
currentSocket
[
nextIdx
]
=
playerData
;
GameServer
.
playingRoom
.
push
(
this
)
;
}
}
else
else
{
{
room
.
currentPlayer
.
push
(
player
);
GameServer
.
playingRoom
[
this
.
roomIndex
]
=
this
;
room
.
currentSocket
.
push
(
playerData
);
}
console
.
log
(
'
[LOG] new room #
'
+
this
.
roomId
+
'
made, roomCount:
'
+
GameServer
.
playingRoom
.
length
);
}
}
playerData
.
playingData
=
player
;
playerData
.
currentRoom
=
room
;
room
.
aliveCount
++
;
console
.
log
(
'
[
'
+
playerData
.
id
+
'
] entered to room #
'
+
room
.
roomNum
);
enterRoom
(
playerSocket
)
playerData
.
socketId
.
emit
(
'
enterRoom
'
);
if
(
room
.
currentPlayer
.
length
>=
this
.
startCount
)
{
{
if
(
room
.
currentPhase
===
this
.
Phase
.
READY
)
// start count
let
playerInst
=
new
Player
(
this
,
playerSocket
.
playerData
);
this
.
currentPlayer
.
push
(
playerInst
);
this
.
currentSocket
.
push
(
playerSocket
);
playerSocket
.
playerData
.
playingData
=
playerInst
;
playerSocket
.
playerData
.
currentRoom
=
this
;
console
.
log
(
'
[
'
+
playerInst
.
id
+
'
] entered to room #
'
+
this
.
roomId
);
playerSocket
.
emit
(
'
enterRoom
'
);
this
.
aliveCount
++
;
if
(
this
.
currentPlayer
.
length
>=
this
.
startCount
)
{
{
room
.
endTime
=
Date
.
now
()
+
15000
;
// 테스트로 15초로 남겨둠
if
(
this
.
currentPhase
===
GameServer
.
Phase
.
READY
)
this
.
announceToRoom
(
room
.
roomNum
,
'
setCount
'
,
{
isEnable
:
true
,
endTime
:
room
.
endTime
});
{
room
.
currentPhase
=
this
.
Phase
.
COUNT
;
this
.
endTime
=
Date
.
now
()
+
1000
;
// 테스트용 10초
this
.
announceToRoom
(
'
setCount
'
,
{
isEnable
:
true
,
endTime
:
this
.
endTime
,
playerCount
:
this
.
currentPlayer
.
length
});
this
.
currentPhase
=
GameServer
.
Phase
.
COUNT
;
}
}
else
if
(
room
.
currentPhase
===
this
.
Phase
.
COUNT
)
// countinue count
else
if
(
this
.
currentPhase
===
GameServer
.
Phase
.
COUNT
)
{
{
playerData
.
socketId
.
emit
(
'
setCount
'
,
{
isEnable
:
true
,
endTime
:
room
.
endTime
});
this
.
announceToRoom
(
'
setCount
'
,
{
isEnable
:
true
,
endTime
:
this
.
endTime
,
playerCount
:
this
.
currentPlayer
.
length
});
}
}
}
}
else
// stop count
else
{
{
this
.
announceToRoom
(
room
.
roomNum
,
'
setCount
'
,
{
isEnable
:
false
,
endTime
:
0
});
this
.
announceToRoom
(
'
setCount
'
,
{
isEnable
:
false
,
endTime
:
0
,
playerCount
:
this
.
currentPlayer
.
length
});
room
.
currentPhase
=
this
.
Phase
.
READY
;
this
.
currentPhase
=
GameServer
.
Phase
.
READY
;
}
}
return
room
;
}
}
GameServer
.
enterEmptyRoom
=
function
(
playerData
)
exitRoom
(
playerId
)
{
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
||
this
.
playingRoom
[
i
].
currentPhase
==
this
.
Phase
.
COUNT
)
)
for
(
let
i
=
0
;
i
<
this
.
currentPlayer
.
length
;
i
++
)
{
{
toEnter
=
i
;
if
(
this
.
currentPlayer
[
i
].
id
===
playerId
)
break
;
{
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
;
}
}
if
(
toEnter
===
-
1
)
{
toEnter
=
this
.
makeRoom
();
}
}
return
this
.
enterRoom
(
toEnter
,
playerData
);
console
.
log
(
'
[ERR] No player who have
'
+
playerId
);
}
return
;
GameServer
.
startRoom
=
function
(
roomIdx
)
}
{
let
room
=
this
.
playingRoom
[
roomIdx
];
startRoom
()
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
;
this
.
currentPhase
=
GameServer
.
Phase
.
START
;
});
this
.
maxTypingPlayer
=
this
.
currentPlayer
[
0
];
let
syncPlayers
=
[];
this
.
minTypingPlayer
=
this
.
currentPlayer
[
0
];
room
.
currentPlayer
.
forEach
(
function
(
element
)
this
.
nextRank
=
this
.
currentPlayer
.
length
;
this
.
aliveCount
=
this
.
currentPlayer
.
length
;
this
.
currentSocket
.
forEach
(
function
(
element
)
{
{
if
(
element
!=
null
)
syncPlayers
.
push
(
element
)
;
element
.
playerData
.
isReceivable
=
true
;
});
});
room
.
nextRank
=
syncPlayers
.
length
;
room
.
aliveCount
=
syncPlayers
.
length
;
// sync roomData
let
toSync
=
let
toSync
=
{
{
roomNum
:
room
.
roomNum
,
roomId
:
this
.
roomId
,
players
:
syncPlayers
players
:
this
.
currentPlayer
};
};
//console.log(toSync);
this
.
announceToRoom
(
'
syncRoomData
'
,
toSync
);
this
.
announceToRoom
(
roomIdx
,
'
syncRoomData
'
,
toSync
);
console
.
log
(
'
[ROOM#
'
+
room
.
roomNum
+
'
] Game Start with
'
+
syncPlayers
.
length
+
'
players
'
);
console
.
log
(
'
[ROOM#
'
+
this
.
roomId
+
'
] Game Start with
'
+
this
.
currentPlayer
.
length
+
'
players
'
);
this
.
announceToRoom
(
roomIdx
,
'
changePhase
'
,
this
.
Phase
.
START
);
this
.
announceToRoom
(
'
changePhase
'
,
GameServer
.
Phase
.
START
);
this
.
announceToRoom
(
roomIdx
,
'
startGame
'
);
this
.
announceToRoom
(
'
startGame
'
);
}
}
GameServer
.
playerDefeat
=
function
(
playerData
)
{
endRoom
()
playerData
.
playingData
.
isAlive
=
false
;
{
playerData
.
playingData
.
rank
=
playerData
.
currentRoom
.
nextRank
--
;
playerData
.
isReceivable
=
false
;
}
playerData
.
currentRoom
.
aliveCount
--
;
if
(
playerData
.
playingData
.
lastAttacks
.
length
>
0
)
destroyRoom
()
{
{
playerData
.
playingData
.
lastAttack
=
playerData
.
playingData
.
lastAttacks
[
playerData
.
playingData
.
lastAttacks
.
length
-
1
];
if
(
this
.
aliveCount
>
0
)
if
(
Date
.
now
()
-
playerData
.
playingData
.
lastAttack
.
time
>
40000
)
playerData
.
playingData
.
lastAttack
=
null
;
{
console
.
log
(
'
[ERR] can not destroy room#
'
+
this
.
roomId
+
'
, cause player left
'
);
}
else
else
{
{
playerData
.
playingData
.
lastAttacks
.
forEach
(
function
(
element
)
let
idx
=
GameServer
.
playingRoom
.
findIndex
(
function
(
element
)
{
{
if
(
Date
.
now
()
-
element
.
time
<
40000
&&
element
.
wordGrade
>
playerData
.
playingData
.
lastAttack
.
wordGrade
)
playerData
.
playingData
.
lastAttack
=
element
;
return
element
.
roomId
===
this
.
roomId
;
});
});
if
(
idx
!=
-
1
)
{
GameServer
.
playingRoom
[
idx
]
=
null
;
}
}
}
}
}
GameServer
.
announceToRoom
(
this
.
findRoomIndex
(
playerData
.
currentRoom
.
roomNum
),
'
defeat
'
,
playerData
.
playingData
);
announceToRoom
(
_message
,
_data
=
null
)
console
.
log
(
'
[
'
+
playerData
.
id
+
'
]
'
+
'
defeated, rank:
'
+
playerData
.
playingData
.
rank
);
if
(
playerData
.
currentRoom
.
aliveCount
===
1
)
{
{
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
)
announceToTarget
(
targetId
,
_message
,
_data
=
null
)
{
this
.
playingRoom
[
roomIdx
].
currentSocket
.
forEach
(
function
(
element
)
{
{
if
(
element
!=
null
)
element
.
socketId
.
emit
(
_message
,
_data
);
let
targetSocketIndex
=
this
.
currentSocket
.
findIndex
(
function
(
element
)
});
}
GameServer
.
announceToTarget
=
function
(
roomIdx
,
targetNum
,
_message
,
_data
=
null
)
{
let
targetSocket
=
this
.
playingRoom
[
roomIdx
].
currentSocket
.
find
(
function
(
element
)
{
{
return
(
element
!=
null
&&
element
.
id
===
targetNum
)
;
return
element
.
playerData
.
id
===
targetId
;
});
});
if
(
targetSocket
!=
undefined
&&
targetSocket
.
isReceivable
)
targetSocket
.
socketId
.
emit
(
_message
,
_data
);
//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
class
Player
{
{
constructor
(
index
,
playerData
)
constructor
(
gameRoom
,
playerData
)
{
{
this
.
index
=
index
;
this
.
id
=
playerData
.
id
;
this
.
id
=
playerData
.
id
;
this
.
gameRoomId
=
gameRoom
.
roomId
;
this
.
index
=
gameRoom
.
currentPlayer
.
length
;
this
.
nickname
=
playerData
.
nickname
;
this
.
nickname
=
playerData
.
nickname
;
this
.
isAlive
=
true
;
this
.
isAlive
=
true
;
this
.
rank
=
-
1
;
this
.
rank
=
-
1
;
...
@@ -220,6 +247,45 @@ class Player
...
@@ -220,6 +247,45 @@ class Player
this
.
lastAttacks
=
[];
// { attackerId, word, wordGrade, time }
this
.
lastAttacks
=
[];
// { attackerId, word, wordGrade, time }
this
.
lastAttack
=
null
;
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
;
module
.
exports
=
GameServer
;
\ No newline at end of file
js/Client.js
View file @
95b3b93e
...
@@ -14,7 +14,7 @@ socket.on('alert', function(msg) // string errorcode
...
@@ -14,7 +14,7 @@ socket.on('alert', function(msg) // string errorcode
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
.
id
Num
=
msg
.
num
;
PlayerData
.
id
=
msg
.
num
;
});
});
socket
.
on
(
'
enterRoom
'
,
function
()
socket
.
on
(
'
enterRoom
'
,
function
()
{
{
...
@@ -26,15 +26,24 @@ socket.on('setCount', function(msg)
...
@@ -26,15 +26,24 @@ socket.on('setCount', function(msg)
{
{
ScenesData
.
roomScene
.
isCounting
=
msg
.
isEnable
;
ScenesData
.
roomScene
.
isCounting
=
msg
.
isEnable
;
ScenesData
.
roomScene
.
endTime
=
msg
.
endTime
;
ScenesData
.
roomScene
.
endTime
=
msg
.
endTime
;
ScenesData
.
roomScene
.
peopleCount
=
msg
.
playerCount
;
});
});
// init game
// 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
.
room
Num
=
msg
.
roomNum
;
RoomData
.
room
Id
=
msg
.
roomId
;
RoomData
.
players
=
msg
.
players
;
RoomData
.
players
=
msg
.
players
;
RoomData
.
aliveCount
=
msg
.
players
.
length
;
RoomData
.
aliveCount
=
msg
.
players
.
length
;
RoomData
.
players
.
forEach
(
function
(
element
)
{
if
(
element
.
id
===
PlayerData
.
id
)
{
RoomData
.
myself
=
element
;
return
;
}
});
});
});
socket
.
on
(
'
startGame
'
,
function
()
socket
.
on
(
'
startGame
'
,
function
()
{
{
...
@@ -55,6 +64,7 @@ socket.on('setPlayerTypingRate', function(msg) // number playerTypingRate
...
@@ -55,6 +64,7 @@ socket.on('setPlayerTypingRate', function(msg) // number playerTypingRate
});
});
socket
.
on
(
'
attacked
'
,
function
(
msg
)
// object attackData
socket
.
on
(
'
attacked
'
,
function
(
msg
)
// object attackData
{
{
//console.log('attacked by ' + msg.attacker.nickname);
setTimeout
(
function
()
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
);
...
...
js/ScenesData.js
View file @
95b3b93e
...
@@ -61,6 +61,7 @@ var roomScene = new Phaser.Class(
...
@@ -61,6 +61,7 @@ var roomScene = new Phaser.Class(
this
.
countText
.
setText
(((
this
.
endTime
-
Date
.
now
())
/
1000
).
toFixed
(
1
));
this
.
countText
.
setText
(((
this
.
endTime
-
Date
.
now
())
/
1000
).
toFixed
(
1
));
if
(
this
.
endTime
-
Date
.
now
()
<
0
)
if
(
this
.
endTime
-
Date
.
now
()
<
0
)
{
{
//console.log('end Count');
socket
.
emit
(
'
endCount
'
);
socket
.
emit
(
'
endCount
'
);
this
.
isCounting
=
false
;
this
.
isCounting
=
false
;
}
}
...
@@ -119,14 +120,8 @@ var gameScene = new Phaser.Class(
...
@@ -119,14 +120,8 @@ var gameScene = new Phaser.Class(
WordSpace
.
nameWordTextForTest
=
ScenesData
.
gameScene
.
add
.
text
(
50
,
400
,
'
현재 가진 호패들 : 없음
'
).
setDepth
(
10
).
setColor
(
'
#000000
'
);
WordSpace
.
nameWordTextForTest
=
ScenesData
.
gameScene
.
add
.
text
(
50
,
400
,
'
현재 가진 호패들 : 없음
'
).
setDepth
(
10
).
setColor
(
'
#000000
'
);
WordSpace
.
nameQueue
.
initiate
();
WordSpace
.
nameQueue
.
initiate
();
RoomData
.
players
.
forEach
(
function
(
element
)
{
// for test
if
(
element
.
nickname
==
PlayerData
.
nickname
)
{
RoomData
.
myself
=
element
;
return
;
}
});
WordSpace
.
attackGauge
.
add
(
11
);
WordSpace
.
attackGauge
.
add
(
11
);
},
},
...
...
js/WordSpace.js
View file @
95b3b93e
...
@@ -394,7 +394,7 @@ WordSpace.findWord = function(wordText)
...
@@ -394,7 +394,7 @@ WordSpace.findWord = function(wordText)
console
.
log
(
'
Attack word :
'
+
element
.
wordText
+
'
of
'
+
element
.
attacker
.
nickname
+
'
오타임
'
);
console
.
log
(
'
Attack word :
'
+
element
.
wordText
+
'
of
'
+
element
.
attacker
.
nickname
+
'
오타임
'
);
let
victimData
=
let
victimData
=
{
{
roomNum
:
RoomData
.
room
Num
,
roomNum
:
RoomData
.
room
Id
,
victim
:
RoomData
.
myself
,
victim
:
RoomData
.
myself
,
target
:
element
.
attacker
.
id
target
:
element
.
attacker
.
id
}
}
...
@@ -431,9 +431,10 @@ WordSpace.attack = function(wordText, grade)
...
@@ -431,9 +431,10 @@ WordSpace.attack = function(wordText, grade)
console
.
log
(
'
attack
'
+
wordText
+
'
, grade:
'
+
grade
);
console
.
log
(
'
attack
'
+
wordText
+
'
, grade:
'
+
grade
);
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
WordSpace
.
nameGroup
.
forEach
(
function
(
element
)
{
{
//console.log(RoomData.myself);
let
attackData
=
let
attackData
=
{
{
roomNum
:
RoomData
.
room
Num
,
roomNum
:
RoomData
.
room
Id
,
attacker
:
RoomData
.
myself
,
attacker
:
RoomData
.
myself
,
target
:
element
.
ownerId
,
target
:
element
.
ownerId
,
text
:
wordText
,
text
:
wordText
,
...
@@ -474,7 +475,7 @@ WordSpace.nameQueue =
...
@@ -474,7 +475,7 @@ WordSpace.nameQueue =
}
}
tempQueue
.
forEach
(
function
(
element
)
tempQueue
.
forEach
(
function
(
element
)
{
{
if
(
element
.
id
!=
PlayerData
.
id
Num
&&
element
.
isAlive
)
if
(
element
.
id
!=
PlayerData
.
id
&&
element
.
isAlive
)
WordSpace
.
nameQueue
.
queue
.
push
(
element
);
WordSpace
.
nameQueue
.
queue
.
push
(
element
);
});
});
},
},
...
...
js/main.js
View file @
95b3b93e
...
@@ -23,13 +23,13 @@ var game = new Phaser.Game(config)
...
@@ -23,13 +23,13 @@ var game = new Phaser.Game(config)
//테스트용이므로 차후 수정 요망
//테스트용이므로 차후 수정 요망
var
PlayerData
=
PlayerData
||
{};
var
PlayerData
=
PlayerData
||
{};
PlayerData
.
id
Num
=
-
1
;
//플레이어 아이디, 고유 번호
PlayerData
.
id
=
-
1
;
//플레이어 아이디, 고유 번호
PlayerData
.
nickname
=
'
홍길동
'
;
//플레이어 닉네임
PlayerData
.
nickname
=
'
홍길동
'
;
//플레이어 닉네임
// 현재 들어가있는 Game Room의 정보
// 현재 들어가있는 Game Room의 정보
var
RoomData
=
RoomData
||
{};
var
RoomData
=
RoomData
||
{};
RoomData
.
room
Num
=
-
1
;
RoomData
.
room
Id
=
-
1
;
RoomData
.
myself
=
null
;
RoomData
.
myself
=
null
;
RoomData
.
players
=
null
;
RoomData
.
players
=
null
;
RoomData
.
aliveCount
=
-
1
;
RoomData
.
aliveCount
=
-
1
;
\ No newline at end of file
server.js
View file @
95b3b93e
...
@@ -25,12 +25,11 @@ io.on('connection', function(socket)
...
@@ -25,12 +25,11 @@ io.on('connection', function(socket)
{
{
id
:
GameServer
.
getPlayerNumber
(),
id
:
GameServer
.
getPlayerNumber
(),
nickname
:
'
게스트
'
,
nickname
:
'
게스트
'
,
socketId
:
socket
,
currentRoom
:
null
,
currentRoom
:
null
,
playingData
:
null
,
playingData
:
null
,
isReceivable
:
false
isReceivable
:
false
};
};
GameServer
.
currentPlayer
.
push
(
socket
.
playerData
);
GameServer
.
currentPlayer
.
push
(
socket
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client request
'
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client request
'
);
socket
.
emit
(
'
setId
'
,
socket
.
emit
(
'
setId
'
,
{
{
...
@@ -44,14 +43,14 @@ io.on('connection', function(socket)
...
@@ -44,14 +43,14 @@ io.on('connection', function(socket)
let
isAlreadyHave
=
false
;
let
isAlreadyHave
=
false
;
GameServer
.
currentPlayer
.
forEach
(
function
(
element
)
GameServer
.
currentPlayer
.
forEach
(
function
(
element
)
{
{
if
(
element
.
nickname
===
msg
)
isAlreadyHave
=
true
;
if
(
element
.
playerData
.
nickname
===
msg
)
isAlreadyHave
=
true
;
});
});
if
(
isAlreadyHave
)
socket
.
emit
(
'
alert
'
,
'
errNicknameOverlaped
'
);
if
(
isAlreadyHave
)
socket
.
emit
(
'
alert
'
,
'
errNicknameOverlaped
'
);
else
else
{
{
socket
.
playerData
.
nickname
=
msg
;
socket
.
playerData
.
nickname
=
msg
;
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] nickname set to
'
+
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)
...
@@ -76,15 +75,15 @@ io.on('connection', function(socket)
socket
.
playerData
.
currentRoom
.
aliveCount
--
;
socket
.
playerData
.
currentRoom
.
aliveCount
--
;
if
(
socket
.
playerData
.
currentRoom
.
aliveCount
===
0
)
if
(
socket
.
playerData
.
currentRoom
.
aliveCount
===
0
)
{
{
GameServer
.
startRoom
(
GameServer
.
findRoomIndex
(
socket
.
playerData
.
currentRoom
.
roomNum
)
);
socket
.
playerData
.
currentRoom
.
startRoom
(
);
}
}
});
});
socket
.
on
(
'
attack
'
,
function
(
msg
)
socket
.
on
(
'
attack
'
,
function
(
msg
)
{
{
GameServer
.
announceToTarget
(
GameServer
.
findRoomIndex
(
msg
.
roomNum
),
msg
.
target
,
'
attacked
'
,
msg
);
socket
.
playerData
.
currentRoom
.
announceToTarget
(
msg
.
target
,
'
attacked
'
,
msg
);
//console.log('
find ' + msg.target + ' by ' + msg.attacker.idNum
+ ' with ' + msg.text);
//console.log('
attack ' + msg.target + ' by ' + msg.attacker.id
+ ' with ' + msg.text);
let
target
=
GameServer
.
findPlayer
(
msg
.
target
);
let
target
=
GameServer
.
findPlayer
Socket
(
msg
.
target
);
if
(
target
!=
null
)
if
(
target
!=
null
)
{
{
let
dataToPush
=
let
dataToPush
=
...
@@ -96,23 +95,23 @@ io.on('connection', function(socket)
...
@@ -96,23 +95,23 @@ io.on('connection', function(socket)
time
:
Date
.
now
()
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
else
{
{
target
.
playingData
.
lastAttacks
.
splice
(
0
,
1
);
target
.
play
erData
.
play
ingData
.
lastAttacks
.
splice
(
0
,
1
);
target
.
playingData
.
lastAttacks
.
push
(
dataToPush
);
target
.
play
erData
.
play
ingData
.
lastAttacks
.
push
(
dataToPush
);
}
}
}
}
});
});
socket
.
on
(
'
defeated
'
,
function
()
socket
.
on
(
'
defeated
'
,
function
()
{
{
GameServer
.
playerDefeat
(
socket
.
playerData
);
socket
.
playerData
.
playingData
.
defeat
(
);
});
});
socket
.
on
(
'
defenseFailed
'
,
function
(
msg
)
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
)
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
...
@@ -128,31 +127,30 @@ io.on('connection', function(socket)
...
@@ -128,31 +127,30 @@ io.on('connection', function(socket)
console
.
log
(
'
[
'
+
data
.
id
+
'
] client disconnected, reason:
'
+
reason
);
console
.
log
(
'
[
'
+
data
.
id
+
'
] client disconnected, reason:
'
+
reason
);
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
{
{
return
element
.
id
===
data
.
id
;
return
element
.
playerData
.
id
===
data
.
id
;
});
});
if
(
idxToDel
!=
-
1
)
if
(
idxToDel
!=
-
1
)
{
{
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
// 룸에서도 제거
// 룸에서도 제거
if
(
data
.
currentRoom
!=
null
)
if
(
data
.
currentRoom
!=
null
)
{
{
if
(
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
READY
||
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
COUNT
)
if
(
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
READY
||
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
COUNT
)
{
{
data
.
currentRoom
.
currentPlayer
[
data
.
playingData
.
index
]
=
null
;
data
.
currentRoom
.
exitRoom
(
data
.
id
);
data
.
currentRoom
.
currentSocket
[
data
.
playingData
.
index
]
=
null
;
data
.
currentRoom
.
aliveCount
--
;
if
(
data
.
currentRoom
.
aliveCount
<
GameServer
.
startCount
)
if
(
data
.
currentRoom
.
aliveCount
<
GameServer
.
startCount
)
{
{
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
data
.
currentRoom
.
roomNum
),
'
setCount
'
,
{
isEnable
:
false
,
endTime
:
0
});
data
.
currentRoom
.
announceToRoom
(
'
setCount
'
,
{
isEnable
:
false
,
endTime
:
0
,
playerCount
:
data
.
currentRoom
.
currentPlayer
.
length
});
data
.
currentRoom
.
currentPhase
=
GameServer
.
Phase
.
READY
;
data
.
currentRoom
.
currentPhase
=
GameServer
.
Phase
.
READY
;
}
}
else
data
.
currentRoom
.
announceToRoom
(
'
setCount
'
,
{
isEnable
:
true
,
endTime
:
data
.
currentRoom
.
endTime
,
playerCount
:
data
.
currentRoom
.
currentPlayer
.
length
});
}
}
else
if
(
data
.
playingData
.
isAlive
)
else
if
(
data
.
playingData
.
isAlive
)
{
{
GameServer
.
playerDefeat
(
socket
.
playerData
);
data
.
playingData
.
defeat
(
);
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
data
.
currentRoom
.
roomNum
),
'
userDisconnect
'
,
data
.
playingData
);
data
.
currentRoom
.
announceToRoom
(
'
userDisconnect
'
,
data
.
playingData
);
}
}
}
}
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
}
}
console
.
log
(
'
[
'
+
data
.
id
+
'
] disconnect complete
'
);
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