Skip to content

Commit

Permalink
Merge branch 'refs/heads/feature/DRAW-197' into sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
SunwoongH committed Jul 30, 2024
2 parents 0ded135 + 8f3f270 commit f5c96d1
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import com.xorker.draw.websocket.SessionMessage
import com.xorker.draw.websocket.broker.WebSocketBroadcaster
import com.xorker.draw.websocket.message.response.dto.MafiaGameInfoBody
import com.xorker.draw.websocket.message.response.dto.MafiaGameInfoMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseEndBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseEndMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseInferAnswerBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseInferAnswerMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhasePlayingBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhasePlayingMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseReadyBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseReadyMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseVoteBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseVoteMessage
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseWaitBody
import com.xorker.draw.websocket.message.response.dto.MafiaPhaseWaitMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseEndBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseEndMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseInferAnswerBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseInferAnswerMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhasePlayingBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhasePlayingMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseReadyBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseReadyMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseVoteBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseVoteMessage
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseWaitBody
import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseWaitMessage
import com.xorker.draw.websocket.message.response.dto.toResponse
import java.time.LocalDateTime
import org.springframework.stereotype.Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.xorker.draw.websocket.message.response.dto
package com.xorker.draw.websocket.message.response.dto.phase

import com.xorker.draw.websocket.ResponseAction
import com.xorker.draw.websocket.SessionMessage
import com.xorker.draw.websocket.message.response.dto.MafiaGameInfoMessage

class MafiaPhaseEndMessage(
override val body: MafiaPhaseEndBody,
) : SessionMessage {
override val action = ResponseAction.PHASE_INFER_ANSWER
override val action = ResponseAction.PHASE_END
override val status = SessionMessage.Status.OK
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.xorker.draw.websocket.message.response.dto
package com.xorker.draw.websocket.message.response.dto.phase

import com.xorker.draw.websocket.ResponseAction
import com.xorker.draw.websocket.SessionMessage
import com.xorker.draw.websocket.message.response.dto.MafiaGameInfoMessage
import java.time.LocalDateTime

class MafiaPhaseInferAnswerMessage(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xorker.draw.websocket.message.response.dto
package com.xorker.draw.websocket.message.response.dto.phase

import com.xorker.draw.websocket.ResponseAction
import com.xorker.draw.websocket.SessionMessage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.xorker.draw.websocket.message.response.dto
package com.xorker.draw.websocket.message.response.dto.phase

import com.xorker.draw.websocket.ResponseAction
import com.xorker.draw.websocket.SessionMessage
import com.xorker.draw.websocket.message.response.dto.MafiaGameInfoMessage
import java.time.LocalDateTime

class MafiaPhaseReadyMessage(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.xorker.draw.websocket.message.response.dto
package com.xorker.draw.websocket.message.response.dto.phase

import com.xorker.draw.user.UserId
import com.xorker.draw.websocket.ResponseAction
import com.xorker.draw.websocket.SessionMessage
import com.xorker.draw.websocket.message.response.dto.MafiaGameInfoMessage
import java.time.LocalDateTime

class MafiaPhaseVoteMessage(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.xorker.draw.websocket.message.response.dto
package com.xorker.draw.websocket.message.response.dto.phase

import com.xorker.draw.room.RoomId
import com.xorker.draw.websocket.ResponseAction
import com.xorker.draw.websocket.SessionMessage
import com.xorker.draw.websocket.message.response.dto.MafiaGameOptionResponse
import com.xorker.draw.websocket.message.response.dto.MafiaPlayerResponse

data class MafiaPhaseWaitMessage(
override val body: MafiaPhaseWaitBody,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ internal class MafiaPhasePlayGameProcessor(

val gameOption = gameInfo.gameOption

val nextTurn = phase.nextTurn(gameOption.round, gameOption.turnCount)
val room = gameInfo.room
val nextTurn = phase.nextTurn(gameOption.round - 1, room.size() - 1)

if (nextTurn == null) {
nextStep.invoke()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal class MafiaPhasePlayVoteProcessor(

if (candidate.first == mafiaPlayer.userId) {
winStep.invoke()
return
}
}
loseStep.invoke()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.xorker.draw.mafia.MafiaGameInfo
import com.xorker.draw.mafia.MafiaGameRepository
import com.xorker.draw.mafia.MafiaPhase
import com.xorker.draw.mafia.MafiaPhaseMessenger
import com.xorker.draw.mafia.assert
import com.xorker.draw.mafia.assertIs
import com.xorker.draw.room.RoomId
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -94,7 +95,7 @@ internal class MafiaPhaseService(

val phase = synchronized(gameInfo) {
val votePhase = gameInfo.phase
assertIs<MafiaPhase.Vote>(votePhase)
assert<MafiaPhase.Vote, MafiaPhase.InferAnswer>(votePhase)
mafiaPhaseEndGameProcessor.endGame(gameInfo)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ data class MafiaGameOption(
val round: Int = 2, // 전체 라운드 수
val turnTime: Duration = Duration.ofSeconds(5), // 턴 당 최대 시간
val turnCount: Int = 2, // 턴 당 최대 획 수
val voteTime: Duration = Duration.ofMinutes(10), // 투표 시간
val answerTime: Duration = Duration.ofMinutes(10), // 정답 입력 시간
val voteTime: Duration = Duration.ofSeconds(10), // 투표 시간
val answerTime: Duration = Duration.ofSeconds(10), // 정답 입력 시간
)
11 changes: 11 additions & 0 deletions domain/src/main/kotlin/com/xorker/draw/mafia/MafiaPhase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,14 @@ inline fun <reified T : MafiaPhase> assertIs(phase: MafiaPhase) {
throw InvalidMafiaPhaseException("유효하지 않는 Phase 입니다. 기대값: ${T::class}, 요청값: $phase")
}
}

@OptIn(ExperimentalContracts::class)
inline fun <reified T1 : MafiaPhase, reified T2 : MafiaPhase> assert(phase: MafiaPhase) {
contract {
returns() implies (phase is T1 || phase is T2)
}

if (phase !is T1 && phase !is T2) {
throw InvalidMafiaPhaseException("유효하지 않는 Phase 입니다. 기대값: ${T1::class} or ${T2::class}, 요청값: $phase")
}
}

0 comments on commit f5c96d1

Please sign in to comment.