Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강동현
/
nodejs-game
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
강동현
2021-06-08 00:43:00 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f00a02d77c26bc708ef25cc831fea0f7390231dc
f00a02d7
1 parent
120063f0
Builds for 1 pipeline
failed
in 1 minute 25 seconds
게임 시작, 종료 구현
Changes
3
Builds
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
5 deletions
common/message.ts
server/game/WordGuessingGame.ts
server/room/Room.ts
common/message.ts
View file @
f00a02d
...
...
@@ -47,6 +47,9 @@ export class ServerInboundMessageRecordMap {
ready
:
Boolean
,
});
// 방장이 게임을 시작합니다.
startGame
=
Record
({});
// drawer가 단어를 선택합니다.
chooseWord
=
Record
({
word
:
String
,
...
...
server/game/WordGuessingGame.ts
View file @
f00a02d
...
...
@@ -177,7 +177,7 @@ export class WorldGuessingGame implements Game {
private
finishGame
():
void
{
this
.
room
.
broadcast
(
"finishGame"
,
{});
// TODO
this
.
room
.
finishGame
();
}
private
forceFinishGame
()
{
...
...
server/room/Room.ts
View file @
f00a02d
...
...
@@ -9,6 +9,8 @@ import {
}
from
"../../common"
;
import
{
RoomDescription
,
RoomInfo
,
UserData
}
from
"../../common/dataType"
;
import
{
RoomManager
}
from
"./RoomManager"
;
import
{
Game
}
from
"../game/Game"
;
import
{
WorldGuessingGame
}
from
"../game/WordGuessingGame"
;
export
class
Room
{
public
readonly
uuid
:
string
;
...
...
@@ -22,6 +24,8 @@ export class Room {
public
usersReady
:
User
[]
=
[];
public
admin
?:
User
;
public
game
?:
Game
;
public
closed
:
boolean
=
false
;
public
handler
:
MessageHandler
;
...
...
@@ -60,6 +64,17 @@ export class Room {
this
.
setReady
(
user
,
message
.
ready
);
return
{
ok
:
true
};
},
startGame
:
(
user
,
message
)
=>
{
if
(
user
!==
this
.
admin
)
{
return
{
ok
:
false
};
}
const
result
=
this
.
canStart
();
if
(
!
result
.
ok
)
{
return
result
;
}
this
.
startGame
();
return
{
ok
:
true
};
},
});
if
(
this
.
admin
)
{
...
...
@@ -149,16 +164,31 @@ export class Room {
return
this
.
usersReady
.
includes
(
user
);
}
public
canStart
():
boolean
{
public
canStart
():
{
ok
:
boolean
;
reason
?:
string
}
{
if
(
this
.
isPlayingGame
())
{
return
{
ok
:
false
,
reason
:
"이미 게임이 진행 중입니다."
};
}
if
(
this
.
users
.
length
<
2
)
{
return
false
;
return
{
ok
:
false
,
reason
:
"최소 2명의 플레이어가 필요합니다."
}
;
}
for
(
let
i
=
0
;
i
<
this
.
users
.
length
;
i
++
)
{
if
(
!
this
.
isAdmin
(
this
.
users
[
i
])
&&
!
this
.
isReady
(
this
.
users
[
i
]))
{
return
false
;
return
{
ok
:
false
,
reason
:
"모든 플레이어가 준비해야 합니다."
}
;
}
}
return
true
;
return
{
ok
:
true
};
}
private
startGame
():
void
{
this
.
game
=
new
WorldGuessingGame
(
this
);
}
public
finishGame
():
void
{
this
.
game
=
undefined
;
}
public
isPlayingGame
():
boolean
{
return
this
.
game
!==
undefined
;
}
public
sendChat
(
user
:
User
,
message
:
string
):
void
{
...
...
Please
register
or
login
to post a comment