Show points on Endcard

This commit is contained in:
Oliver Rümpelein 2021-08-18 18:49:21 +02:00
parent 69a1781106
commit b7ab14c437
2 changed files with 17 additions and 10 deletions

View file

@ -95,12 +95,15 @@ val game = Game(
)
fun main() = application {
// TODO: Read Game from JSON
Window(
onCloseRequest = ::exitApplication,
title = "J-EP-ardy"
) {
MaterialTheme {
val playerPointMap: MutableMap<Player, Long> = game.players.map { it to 0L }.toMutableStateMap()
val playerPointMap: MutableMap<Player, Long> =
remember { game.players.map { it to 0L }.toMutableStateMap() }
var questionsPlayed by remember { mutableStateOf(0) }
val secondRoundDouble by remember { derivedStateOf { questionsPlayed >= game.doubleAfter } }

View file

@ -22,24 +22,28 @@ fun EndCard(
modifier = Modifier.fillMaxWidth()
.fillMaxHeight()
) {
val firstThreePlaces = playerPointMap.entries
.sortedBy { it.value }
.map { it.key }
.take(3)
val firstPlayer = firstThreePlaces.first()
val sortedPlayersPoints = playerPointMap.entries
.sortedByDescending { it.value }
val firstPlayer = sortedPlayersPoints.first()
.key
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(text = "Congratulations, ${firstPlayer.name}!")
for ((index, player) in firstThreePlaces.withIndex()) {
for ((index, data) in sortedPlayersPoints.withIndex()) {
val player = data.key
Row(horizontalArrangement = Arrangement.SpaceBetween) {
Text(text = "Place ${index + 1}")
Surface(color = player.color.toColor()) {
Text(text = player.name)
Text( text = "${index+1}.")
Surface(
color = player.color.toColor()
) {
Text(text = "${player.name} (${data.value} Pts.)")
}
}
}
Button(
onClick = close
) {