Skip to content

Commit

Permalink
Make sure that game is not started twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Jun 28, 2022
1 parent 4dddedc commit 554e056
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class GameFlowImpl<T: Any>(
override val actionsInput: Channel<Actionable<T, out Any>> = Channel()
var job: Job? = null
override suspend fun start(coroutineScope: CoroutineScope) {
if (job != null) throw IllegalStateException("Game already started")
val game = this
job = coroutineScope.launch(Dispatchers.Default) {
logger.info("GameFlow Coroutine started")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class GameImpl<T : Any>(
private val rules = GameActionRulesContext(gameConfig, model, replayState, eliminationCallback)

override suspend fun start(coroutineScope: CoroutineScope) {
if (this.actionsInputJob != null) throw IllegalStateException("Game already started")
println("$this: pre-setup")
replayState.stateKeeper.preSetup(this) { feedbackFlow.send(it) }
setupContext.model.onStart(GameStartContext(gameConfig, model, replayState, playerCount))
Expand Down

0 comments on commit 554e056

Please sign in to comment.