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
d6375559
Commit
d6375559
authored
Jul 10, 2019
by
18신대성
Committed by
18류지석
Jul 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
방에 혼자남으면 승리표시 뜸
parent
2fdf73fd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
17 deletions
+44
-17
GameServer.js
GameServer.js
+26
-1
Client.js
js/Client.js
+13
-4
server.js
server.js
+5
-12
No files found.
GameServer.js
View file @
d6375559
var
GameServer
=
GameServer
||
{};
GameServer
.
Phase
=
{
READY
:
0
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
startCount
=
4
;
GameServer
.
startCount
=
2
;
GameServer
.
currentPlayer
=
[];
GameServer
.
playingRoom
=
[];
...
...
@@ -30,12 +30,14 @@ GameServer.findPlayer = function(playerId)
GameServer
.
nextRoomNumber
=
0
;
GameServer
.
makeRoom
=
function
()
{
// 나중에 room 삭제시 생긴 null에 채워넣는식으로 만들것, 룸의 인덱스를 고정
var
roomOption
=
{
roomNum
:
GameServer
.
nextRoomNumber
++
,
maxPlayer
:
5
,
nextRank
:
5
,
currentPlayer
:
[],
aliveCount
:
-
1
,
currentSocket
:
[],
currentPhase
:
GameServer
.
Phase
.
READY
,
...
...
@@ -107,6 +109,8 @@ GameServer.startRoom = function(roomIdx)
{
let
room
=
this
.
playingRoom
[
roomIdx
];
room
.
currentPhase
=
this
.
Phase
.
START
;
room
.
nextRank
=
room
.
currentPlayer
.
length
;
room
.
aliveCount
=
room
.
currentPlayer
.
length
;
room
.
maxTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
minTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
currentSocket
.
forEach
(
function
(
element
)
...
...
@@ -127,6 +131,27 @@ GameServer.startRoom = function(roomIdx)
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
--
;
// 끝내기단어 체크
GameServer
.
announceToRoom
(
this
.
findRoomIndex
(
playerData
.
currentRoom
.
roomNum
),
'
defeat
'
,
playerData
.
playingData
);
console
.
log
(
'
[
'
+
playerData
.
id
+
'
]
'
+
'
defeated, rank:
'
+
playerData
.
playingData
.
rank
);
if
(
playerData
.
currentRoom
.
aliveCount
===
1
)
{
let
winner
=
playerData
.
currentRoom
.
currentPlayer
.
find
(
function
(
element
)
{
return
element
.
isAlive
;
});
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
)
...
...
js/Client.js
View file @
d6375559
...
...
@@ -2,15 +2,20 @@ var socket = io.connect();
// init account
socket
.
emit
(
'
idRequest
'
);
socket
.
on
(
'
alert
'
,
function
(
msg
)
// string errorcode
{
let
toAlert
=
'
null alert
'
;
if
(
msg
===
'
errNicknameOverlaped
'
)
toAlert
=
'
이미 사용중인 닉네임입니다.
'
;
if
(
msg
===
'
gameWin
'
)
toAlert
=
'
승리!
'
;
alert
(
toAlert
);
});
socket
.
on
(
'
setId
'
,
function
(
msg
)
// {str, num playerNum}
{
console
.
log
(
msg
.
str
);
PlayerData
.
idNum
=
msg
.
num
;
});
socket
.
on
(
'
errNicknameOverlaped
'
,
function
()
{
alert
(
'
이미 사용중인 닉네임입니다.
'
);
});
socket
.
on
(
'
enterRoom
'
,
function
()
{
game
.
scene
.
remove
(
'
menuScene
'
);
...
...
@@ -50,6 +55,10 @@ socket.on('defeat', function(msg) // object player
RoomData
.
aliveCount
--
;
console
.
log
(
RoomData
.
players
[
msg
.
index
].
nickname
+
'
defeated
'
);
});
socket
.
on
(
'
gameEnd
'
,
function
(
msg
)
// object player
{
console
.
log
(
msg
.
nickname
+
'
Win!!!!!!
'
);
});
socket
.
on
(
'
attackSucceed
'
,
function
(
msg
)
{
...
...
server.js
View file @
d6375559
...
...
@@ -46,7 +46,7 @@ io.on('connection', function(socket)
{
if
(
element
.
nickname
===
msg
)
isAlreadyHave
=
true
;
});
if
(
isAlreadyHave
)
socket
.
emit
(
'
errNicknameOverlaped
'
);
if
(
isAlreadyHave
)
socket
.
emit
(
'
alert
'
,
'
errNicknameOverlaped
'
);
else
{
socket
.
playerData
.
nickname
=
msg
;
...
...
@@ -79,12 +79,7 @@ io.on('connection', function(socket)
socket
.
on
(
'
defeated
'
,
function
()
{
socket
.
playerData
.
playingData
.
isAlive
=
false
;
socket
.
playerData
.
playingData
.
rank
=
socket
.
playerData
.
currentRoom
.
nextRank
--
;
socket
.
playerData
.
isReceivable
=
false
;
// 패배단어 체크
GameServer
.
announceToRoom
(
socket
.
playerData
.
currentRoom
.
roomNum
,
'
defeat
'
,
socket
.
playerData
.
playingData
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
]
'
+
'
defeated
'
);
GameServer
.
playerDefeat
(
socket
.
playerData
);
});
socket
.
on
(
'
defenseFailed
'
,
function
(
msg
)
...
...
@@ -118,13 +113,11 @@ io.on('connection', function(socket)
data
.
currentRoom
.
currentPlayer
[
data
.
playingData
.
index
]
=
null
;
data
.
currentRoom
.
currentSocket
[
data
.
playingData
.
index
]
=
null
;
}
else
else
if
(
data
.
playingData
.
isAlive
)
{
data
.
playingData
.
isAlive
=
false
;
if
(
data
.
playingData
.
rank
===
-
1
)
data
.
playingData
.
rank
=
data
.
currentRoom
.
nextRank
--
;
data
.
currentRoom
.
currentSocket
[
data
.
playingData
.
index
].
isReceivable
=
false
;
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
data
.
currentRoom
.
roomNum
),
'
userDisconnect
'
,
data
.
playingData
);
GameServer
.
playerDefeat
(
socket
.
playerData
);
}
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
data
.
currentRoom
.
roomNum
),
'
userDisconnect
'
,
data
.
playingData
);
}
}
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