Show points on Endcard
This commit is contained in:
parent
69a1781106
commit
b7ab14c437
2 changed files with 17 additions and 10 deletions
|
@ -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 } }
|
||||
|
|
|
@ -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
|
||||
) {
|
||||
|
|
Loading…
Reference in a new issue