Skip to content

Commit

Permalink
#25 support rounds
Browse files Browse the repository at this point in the history
  • Loading branch information
stoerti committed Dec 21, 2024
1 parent 13a9b82 commit bc6b342
Show file tree
Hide file tree
Showing 48 changed files with 1,779 additions and 627 deletions.
5 changes: 1 addition & 4 deletions backend/src/main/kotlin/org/quizmania/game/api/GameConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import org.quizmania.question.api.QuestionType

data class GameConfig(
val maxPlayers: Int = 10,
val numQuestions: Int = 10,
val secondsToAnswer: Long = 10,
val questionTypes: Set<QuestionType> = QuestionType.entries.toSet(),
val questionSetId: QuestionSetId,
val useBuzzer: Boolean = false,
)
)
17 changes: 17 additions & 0 deletions backend/src/main/kotlin/org/quizmania/game/api/commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ data class StartGameCommand(
override val gameId: UUID,
): GameCommand

data class StartNextRoundCommand(
@TargetAggregateIdentifier
override val gameId: UUID,
): GameCommand

data class ScoreRoundCommand(
@TargetAggregateIdentifier
override val gameId: UUID,
): GameCommand

data class CloseRoundCommand(
@TargetAggregateIdentifier
override val gameId: UUID,
): GameCommand



data class AnswerQuestionCommand(
@TargetAggregateIdentifier
override val gameId: UUID,
Expand Down
26 changes: 24 additions & 2 deletions backend/src/main/kotlin/org/quizmania/game/api/events.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.quizmania.game.api

import org.quizmania.question.api.Question
import org.quizmania.question.api.QuestionId
import org.quizmania.question.api.Round
import org.quizmania.question.api.RoundConfig
import java.time.Instant
import java.util.*

Expand All @@ -22,7 +24,7 @@ data class GameCreatedEvent(
override val gameId: GameId,
val name: String,
val config: GameConfig,
val questionList: List<QuestionId>,
val rounds: List<Round>,
val creatorUsername: String,
val moderatorUsername: String?,
) : GameEvent
Expand Down Expand Up @@ -51,10 +53,30 @@ data class GameCanceledEvent(
override val gameId: GameId,
) : GameEvent

data class RoundStartedEvent(
override val gameId: GameId,
val gameRoundId: GameRoundId,
val roundNumber: Int,
val roundName: String,
val roundConfig: RoundConfig,
val questions: List<QuestionId>,
) : GameEvent

data class RoundScoredEvent(
override val gameId: GameId,
val gameRoundId: GameRoundId,
) : GameEvent

data class RoundClosedEvent(
override val gameId: GameId,
val gameRoundId: GameRoundId,
) : GameEvent

data class QuestionAskedEvent(
override val gameId: GameId,
override val gameQuestionId: GameQuestionId,
val gameQuestionNumber: GameQuestionNumber,
val roundNumber: GameRoundNumber,
val roundQuestionNumber: RoundQuestionNumber,
val questionMode: GameQuestionMode,
val questionTimestamp: Instant,
val timeToAnswer: Long,
Expand Down
9 changes: 9 additions & 0 deletions backend/src/main/kotlin/org/quizmania/game/api/exceptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ class UsernameTakenProblem(gameId: UUID) :
class GameAlreadyFullProblem(gameId: UUID) :
GameProblem(gameId, "urn:quizmania:game:alreadyFull", "Game already full")

class GameNotStartedProblem(gameId: UUID) :
GameProblem(gameId, "urn:quizmania:game:notStarted", "Game has not started")

class GameAlreadyStartedProblem(gameId: UUID) :
GameProblem(gameId, "urn:quizmania:game:alreadyStarted", "Game has already started")

class GameAlreadyEndedProblem(gameId: UUID) :
GameProblem(gameId, "urn:quizmania:game:alreadyEnded", "Game has already ended")

class RoundAlreadyStartedProblem(gameId: UUID) :
GameProblem(gameId, "urn:quizmania:game:roundAlreadyStarted", "Round has already started")

class RoundAlreadyClosedProblem(gameId: UUID) :
GameProblem(gameId, "urn:quizmania:game:alreadyEnded", "Round has already ended")

class OtherQuestionStillOpenProblem(gameId: UUID) :
GameProblem(gameId, "urn:quizmania:game:questionStillOpen", "Another question is still open")

Expand Down
4 changes: 3 additions & 1 deletion backend/src/main/kotlin/org/quizmania/game/api/types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import java.util.UUID
typealias GameId = UUID
typealias GameQuestionId = UUID
typealias GamePlayerId = UUID
typealias GameQuestionNumber = Int
typealias GameRoundId = UUID
typealias GameRoundNumber = Int
typealias RoundQuestionNumber = Int
Loading

0 comments on commit bc6b342

Please sign in to comment.