Builds for
1 pipeline
failed
in
1 minute 25 seconds
게임 시작, 종료 구현
Showing
3 changed files
with
38 additions
and
5 deletions
| ... | @@ -47,6 +47,9 @@ export class ServerInboundMessageRecordMap { | ... | @@ -47,6 +47,9 @@ export class ServerInboundMessageRecordMap { |
| 47 | ready: Boolean, | 47 | ready: Boolean, |
| 48 | }); | 48 | }); |
| 49 | 49 | ||
| 50 | + // 방장이 게임을 시작합니다. | ||
| 51 | + startGame = Record({}); | ||
| 52 | + | ||
| 50 | // drawer가 단어를 선택합니다. | 53 | // drawer가 단어를 선택합니다. |
| 51 | chooseWord = Record({ | 54 | chooseWord = Record({ |
| 52 | word: String, | 55 | word: String, | ... | ... |
| ... | @@ -177,7 +177,7 @@ export class WorldGuessingGame implements Game { | ... | @@ -177,7 +177,7 @@ export class WorldGuessingGame implements Game { |
| 177 | private finishGame(): void { | 177 | private finishGame(): void { |
| 178 | this.room.broadcast("finishGame", {}); | 178 | this.room.broadcast("finishGame", {}); |
| 179 | 179 | ||
| 180 | - // TODO | 180 | + this.room.finishGame(); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | private forceFinishGame() { | 183 | private forceFinishGame() { | ... | ... |
| ... | @@ -9,6 +9,8 @@ import { | ... | @@ -9,6 +9,8 @@ import { |
| 9 | } from "../../common"; | 9 | } from "../../common"; |
| 10 | import { RoomDescription, RoomInfo, UserData } from "../../common/dataType"; | 10 | import { RoomDescription, RoomInfo, UserData } from "../../common/dataType"; |
| 11 | import { RoomManager } from "./RoomManager"; | 11 | import { RoomManager } from "./RoomManager"; |
| 12 | +import { Game } from "../game/Game"; | ||
| 13 | +import { WorldGuessingGame } from "../game/WordGuessingGame"; | ||
| 12 | 14 | ||
| 13 | export class Room { | 15 | export class Room { |
| 14 | public readonly uuid: string; | 16 | public readonly uuid: string; |
| ... | @@ -22,6 +24,8 @@ export class Room { | ... | @@ -22,6 +24,8 @@ export class Room { |
| 22 | public usersReady: User[] = []; | 24 | public usersReady: User[] = []; |
| 23 | public admin?: User; | 25 | public admin?: User; |
| 24 | 26 | ||
| 27 | + public game?: Game; | ||
| 28 | + | ||
| 25 | public closed: boolean = false; | 29 | public closed: boolean = false; |
| 26 | 30 | ||
| 27 | public handler: MessageHandler; | 31 | public handler: MessageHandler; |
| ... | @@ -60,6 +64,17 @@ export class Room { | ... | @@ -60,6 +64,17 @@ export class Room { |
| 60 | this.setReady(user, message.ready); | 64 | this.setReady(user, message.ready); |
| 61 | return { ok: true }; | 65 | return { ok: true }; |
| 62 | }, | 66 | }, |
| 67 | + startGame: (user, message) => { | ||
| 68 | + if (user !== this.admin) { | ||
| 69 | + return { ok: false }; | ||
| 70 | + } | ||
| 71 | + const result = this.canStart(); | ||
| 72 | + if (!result.ok) { | ||
| 73 | + return result; | ||
| 74 | + } | ||
| 75 | + this.startGame(); | ||
| 76 | + return { ok: true }; | ||
| 77 | + }, | ||
| 63 | }); | 78 | }); |
| 64 | 79 | ||
| 65 | if (this.admin) { | 80 | if (this.admin) { |
| ... | @@ -149,16 +164,31 @@ export class Room { | ... | @@ -149,16 +164,31 @@ export class Room { |
| 149 | return this.usersReady.includes(user); | 164 | return this.usersReady.includes(user); |
| 150 | } | 165 | } |
| 151 | 166 | ||
| 152 | - public canStart(): boolean { | 167 | + public canStart(): { ok: boolean; reason?: string } { |
| 168 | + if (this.isPlayingGame()) { | ||
| 169 | + return { ok: false, reason: "이미 게임이 진행 중입니다." }; | ||
| 170 | + } | ||
| 153 | if (this.users.length < 2) { | 171 | if (this.users.length < 2) { |
| 154 | - return false; | 172 | + return { ok: false, reason: "최소 2명의 플레이어가 필요합니다." }; |
| 155 | } | 173 | } |
| 156 | for (let i = 0; i < this.users.length; i++) { | 174 | for (let i = 0; i < this.users.length; i++) { |
| 157 | if (!this.isAdmin(this.users[i]) && !this.isReady(this.users[i])) { | 175 | if (!this.isAdmin(this.users[i]) && !this.isReady(this.users[i])) { |
| 158 | - return false; | 176 | + return { ok: false, reason: "모든 플레이어가 준비해야 합니다." }; |
| 159 | } | 177 | } |
| 160 | } | 178 | } |
| 161 | - return true; | 179 | + return { ok: true }; |
| 180 | + } | ||
| 181 | + | ||
| 182 | + private startGame(): void { | ||
| 183 | + this.game = new WorldGuessingGame(this); | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + public finishGame(): void { | ||
| 187 | + this.game = undefined; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + public isPlayingGame(): boolean { | ||
| 191 | + return this.game !== undefined; | ||
| 162 | } | 192 | } |
| 163 | 193 | ||
| 164 | public sendChat(user: User, message: string): void { | 194 | public sendChat(user: User, message: string): void { | ... | ... |
-
Please register or login to post a comment