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 { fun main() = application {
// TODO: Read Game from JSON
Window( Window(
onCloseRequest = ::exitApplication, onCloseRequest = ::exitApplication,
title = "J-EP-ardy" title = "J-EP-ardy"
) { ) {
MaterialTheme { 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) } var questionsPlayed by remember { mutableStateOf(0) }
val secondRoundDouble by remember { derivedStateOf { questionsPlayed >= game.doubleAfter } } val secondRoundDouble by remember { derivedStateOf { questionsPlayed >= game.doubleAfter } }

View file

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