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
cfa46b01
Commit
cfa46b01
authored
Jul 18, 2019
by
18손재민
Committed by
18신대성
Jul 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/server' into wordspace
# Conflicts: # GameServer.js
parents
0b81dc2a
9730f4ec
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
353 additions
and
193 deletions
+353
-193
GameServer.js
GameServer.js
+229
-148
Background.js
js/Background.js
+7
-1
Client.js
js/Client.js
+64
-6
ScenesData.js
js/ScenesData.js
+19
-11
WordSpace.js
js/WordSpace.js
+4
-3
main.js
js/main.js
+2
-2
server.js
server.js
+28
-22
No files found.
GameServer.js
View file @
cfa46b01
This diff is collapsed.
Click to expand it.
js/Background.js
View file @
cfa46b01
...
...
@@ -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 @
cfa46b01
...
...
@@ -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,6 +112,7 @@ 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
);
...
...
js/ScenesData.js
View file @
cfa46b01
...
...
@@ -42,29 +42,43 @@ 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
()
)
{
//console.log('end Count');
socket
.
emit
(
'
endCount
'
);
this
.
isCounting
=
false
;
this
.
isCountEnd
=
true
;
}
}
else
if
(
this
.
isCountEnd
)
{
this
.
countText
.
setText
(
'
잠시만 기다려주세요...
'
);
}
else
{
this
.
countText
.
setText
(
'
사람들을 위해 대기중입니다...
'
);
...
...
@@ -121,14 +135,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/WordSpace.js
View file @
cfa46b01
...
...
@@ -403,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
}
...
...
@@ -438,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
,
...
...
@@ -481,7 +482,7 @@ WordSpace.nameQueue =
}
tempQueue
.
forEach
(
function
(
element
)
{
if
(
element
.
id
!=
PlayerData
.
id
Num
&&
element
.
isAlive
)
if
(
element
.
id
!=
PlayerData
.
id
&&
element
.
isAlive
)
WordSpace
.
nameQueue
.
queue
.
push
(
element
);
});
},
...
...
js/main.js
View file @
cfa46b01
...
...
@@ -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 @
cfa46b01
...
...
@@ -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