151 lines
4.8 KiB
Kotlin
151 lines
4.8 KiB
Kotlin
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.material.MaterialTheme
|
|
import androidx.compose.runtime.*
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.window.Window
|
|
import androidx.compose.ui.window.application
|
|
import components.EndCard
|
|
import components.GameHeader
|
|
import components.PlayerBar
|
|
import components.QuestionGrid
|
|
import data.*
|
|
|
|
val game = Game(
|
|
title = "j-EP-ardy!",
|
|
doubleAfter = 5,
|
|
endGameAfter = 2,
|
|
players = listOf(
|
|
Player(name = "Oli"),
|
|
Player(name = "Gesina")
|
|
),
|
|
topics = listOf(
|
|
Topic(
|
|
color = ColorData(
|
|
red = 0x44,
|
|
green = 0x44,
|
|
blue = 0xAA
|
|
),
|
|
topic = "Wer MACKt's?",
|
|
questions = listOf(
|
|
QuestionData(
|
|
hint = "Mack",
|
|
answer = "Thomas",
|
|
points = 100u,
|
|
isDeferredDouble = true
|
|
),
|
|
QuestionData(
|
|
hint = "Mack",
|
|
answer = "Michael",
|
|
points = 200u
|
|
),
|
|
QuestionData(
|
|
hint = "Mack",
|
|
answer = "Ann-Kathrin",
|
|
points = 300u
|
|
)
|
|
)
|
|
),
|
|
Topic(
|
|
color = ColorData(
|
|
red = 0x22,
|
|
green = 0x22,
|
|
blue = 0xCC
|
|
),
|
|
topic = "Topic2",
|
|
questions = listOf(
|
|
QuestionData(
|
|
hint = "Wildcard",
|
|
answer = "any",
|
|
points = 1000u
|
|
),
|
|
QuestionData(
|
|
hint = "foo",
|
|
answer = "bar",
|
|
points = 5u
|
|
),
|
|
QuestionData(
|
|
hint = "foo",
|
|
answer = "bar",
|
|
points = 5u
|
|
)
|
|
)
|
|
),
|
|
Topic(
|
|
topic = "Topic3",
|
|
questions = listOf(
|
|
QuestionData(
|
|
hint = "Wildcard",
|
|
answer = "any",
|
|
points = 1000u
|
|
),
|
|
QuestionData(
|
|
hint = "foo",
|
|
answer = "bar",
|
|
points = 5u
|
|
),
|
|
QuestionData(
|
|
hint = "foo",
|
|
answer = "bar",
|
|
points = 5u
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
fun main() = application {
|
|
Window(
|
|
onCloseRequest = ::exitApplication,
|
|
title = "J-EP-ardy"
|
|
) {
|
|
MaterialTheme {
|
|
val playerPointMap: MutableMap<Player, Long> = game.players.map { it to 0L }.toMutableStateMap()
|
|
|
|
var questionsPlayed by remember { mutableStateOf(0) }
|
|
val doublePoints by remember { derivedStateOf { questionsPlayed >= game.doubleAfter } }
|
|
val gameEnded by remember { derivedStateOf { questionsPlayed >= game.endGameAfter } }
|
|
|
|
if (!gameEnded) {
|
|
Column(modifier = Modifier.fillMaxHeight().fillMaxWidth()) {
|
|
Row(
|
|
modifier = Modifier.fillMaxHeight(0.2f)
|
|
) {
|
|
GameHeader(
|
|
title = game.title,
|
|
color = game.headerColor
|
|
)
|
|
}
|
|
Spacer(modifier = Modifier.height(5.dp))
|
|
Row(
|
|
modifier = Modifier.fillMaxHeight()
|
|
) {
|
|
Column(Modifier.fillMaxWidth(0.8f)) {
|
|
QuestionGrid(
|
|
game,
|
|
doublePoints,
|
|
onResolveQuestion = {
|
|
questionsPlayed++
|
|
println("Questions: $questionsPlayed, Double: $doublePoints")
|
|
},
|
|
onPointsChange = { player, points ->
|
|
playerPointMap[player] = playerPointMap[player]?.plus(points) ?: 0
|
|
}
|
|
)
|
|
}
|
|
Spacer(modifier = Modifier.width(5.dp))
|
|
Column(Modifier.fillMaxWidth()) {
|
|
PlayerBar(players = playerPointMap)
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
EndCard(
|
|
playerPointMap = playerPointMap,
|
|
close = ::exitApplication
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|