Events for persistend game storage
This commit is contained in:
parent
1703cd87cb
commit
fe7d40c4f0
6 changed files with 31 additions and 13 deletions
|
@ -7,16 +7,19 @@ import androidx.compose.ui.unit.dp
|
|||
import components.GameHeader
|
||||
import components.PlayerBar
|
||||
import components.QuestionGrid
|
||||
import components.QuestionResolution
|
||||
import data.Player
|
||||
import data.QuestionData
|
||||
|
||||
@Composable
|
||||
@Suppress("FunctionName")
|
||||
fun GameBoard(
|
||||
reviewModeActive: Boolean,
|
||||
secondRoundDouble: Boolean,
|
||||
playerPointMap: MutableMap<Player, Long>,
|
||||
playerPointMap: Map<Player, Long>,
|
||||
onDisableReviewMode: () -> Unit,
|
||||
onChangeQuestionsPlayed: () -> Unit
|
||||
onPointsChange: (Player, Long) -> Unit,
|
||||
onQuestionDone: (QuestionData, QuestionResolution) -> Unit,
|
||||
) {
|
||||
Column(modifier = Modifier.fillMaxHeight().fillMaxWidth()) {
|
||||
Row(
|
||||
|
@ -40,10 +43,8 @@ fun GameBoard(
|
|||
QuestionGrid(
|
||||
game,
|
||||
secondRoundDouble,
|
||||
onResolveQuestion = onChangeQuestionsPlayed,
|
||||
onPointsChange = { player, points ->
|
||||
playerPointMap[player] = playerPointMap[player]?.plus(points) ?: 0
|
||||
}
|
||||
onResolveQuestion = onQuestionDone,
|
||||
onPointsChange = onPointsChange
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.width(5.dp))
|
||||
|
|
|
@ -3,6 +3,7 @@ import androidx.compose.runtime.*
|
|||
import androidx.compose.ui.window.Window
|
||||
import androidx.compose.ui.window.application
|
||||
import components.EndCard
|
||||
import components.QuestionResolution
|
||||
import data.*
|
||||
|
||||
val game = Game(
|
||||
|
@ -112,10 +113,21 @@ fun main() = application {
|
|||
title = "J-EP-ardy"
|
||||
) {
|
||||
MaterialTheme {
|
||||
|
||||
val playerPointMap: MutableMap<Player, Long> =
|
||||
remember { game.players.map { it to 0L }.toMutableStateMap() }
|
||||
|
||||
var questionsPlayed by remember { mutableStateOf(0) }
|
||||
val questionsResolved: MutableMap<QuestionData, QuestionResolution> = remember {
|
||||
game.topics
|
||||
.flatMap { it.questions }
|
||||
.map { it to QuestionResolution(false, null) }
|
||||
.toMutableStateMap()
|
||||
}
|
||||
val questionsPlayed by remember {
|
||||
derivedStateOf {
|
||||
questionsResolved.filter { it.value.answered }.count()
|
||||
}
|
||||
}
|
||||
val secondRoundDouble by remember { derivedStateOf { questionsPlayed >= game.doubleAfter } }
|
||||
val gameEnded by remember { derivedStateOf { questionsPlayed >= game.endGameAfter } }
|
||||
var reviewModeActive by remember { mutableStateOf(false) }
|
||||
|
@ -126,7 +138,10 @@ fun main() = application {
|
|||
secondRoundDouble,
|
||||
playerPointMap,
|
||||
onDisableReviewMode = { reviewModeActive = false },
|
||||
onChangeQuestionsPlayed = { questionsPlayed++ }
|
||||
onPointsChange = { player, points ->
|
||||
playerPointMap[player] = playerPointMap[player]?.plus(points) ?: 0
|
||||
},
|
||||
onQuestionDone = { question, questionResolution -> questionsResolved[question] = questionResolution }
|
||||
)
|
||||
} else {
|
||||
EndCard(
|
||||
|
|
|
@ -9,7 +9,7 @@ import data.Player
|
|||
|
||||
@Suppress("FunctionName")
|
||||
@Composable
|
||||
fun PlayerBar(players: MutableMap<Player, Long>) {
|
||||
fun PlayerBar(players: Map<Player, Long>) {
|
||||
val numberOfCards = players.size
|
||||
Column(
|
||||
modifier = Modifier.fillMaxHeight()
|
||||
|
|
|
@ -32,7 +32,7 @@ fun Question(
|
|||
heightFraction: Float,
|
||||
color: Color,
|
||||
onPointsChange: (Player, Long) -> Unit,
|
||||
onResolve: () -> Unit
|
||||
onResolve: (QuestionData, QuestionResolution) -> Unit
|
||||
) {
|
||||
var questionVisible by remember { mutableStateOf(false) }
|
||||
var questionResolution by remember { mutableStateOf(QuestionResolution(false, null)) }
|
||||
|
@ -92,7 +92,7 @@ fun Question(
|
|||
onResolve = {
|
||||
questionResolution = it
|
||||
questionVisible = false
|
||||
onResolve()
|
||||
onResolve(questionData, it)
|
||||
},
|
||||
onPointsChange = onPointsChange
|
||||
)
|
||||
|
|
|
@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Row
|
|||
import androidx.compose.runtime.*
|
||||
import data.Game
|
||||
import data.Player
|
||||
import data.QuestionData
|
||||
|
||||
@Suppress("FunctionName")
|
||||
@Composable
|
||||
|
@ -11,7 +12,7 @@ fun QuestionGrid(
|
|||
game: Game,
|
||||
secondRoundDouble: Boolean,
|
||||
onPointsChange: (player: Player, points: Long) -> Unit,
|
||||
onResolveQuestion: () -> Unit
|
||||
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit
|
||||
) {
|
||||
val users = game.players
|
||||
val numberOfColumns = game.topics.size
|
||||
|
|
|
@ -10,6 +10,7 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.em
|
||||
import data.Player
|
||||
import data.QuestionData
|
||||
import data.Topic
|
||||
import data.toColor
|
||||
|
||||
|
@ -21,7 +22,7 @@ fun TopicRow(
|
|||
users: List<Player>,
|
||||
columnFraction: Float,
|
||||
onPointsChange: (Player, Long) -> Unit,
|
||||
onResolveQuestion: () -> Unit
|
||||
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit
|
||||
) {
|
||||
val topicColor = topic.color.toColor()
|
||||
Column(
|
||||
|
|
Loading…
Reference in a new issue