feat: 积分榜详情增加对手名和各自得分

This commit is contained in:
flykhan 2026-04-26 22:33:46 +08:00
parent 800238df40
commit 145a432f7d
2 changed files with 27 additions and 4 deletions

View File

@ -66,7 +66,8 @@ data class ScoreEntry(
val playerCount: Int,
val turnNumber: Int,
val date: Long,
val scoreDetail: String? = ""
val scoreDetail: String? = "",
val opponentDetail: String? = ""
)
object Scoreboard {
@ -95,7 +96,8 @@ object Scoreboard {
duration: Int,
playerCount: Int,
turnNumber: Int,
scoreDetail: String = ""
scoreDetail: String = "",
opponentDetail: String = ""
) {
val scores = loadScores(context).toMutableList()
scores.add(
@ -108,7 +110,8 @@ object Scoreboard {
playerCount = playerCount,
turnNumber = turnNumber,
date = System.currentTimeMillis(),
scoreDetail = scoreDetail
scoreDetail = scoreDetail,
opponentDetail = opponentDetail
)
)
saveScores(context, scores.sortedByDescending { it.points }.take(50))
@ -201,6 +204,14 @@ fun LocalGameScreen(
}
}
val detailStr = scoreDetails.joinToString(", ")
// 对手名和各自总分
val opponentDetails = state.players.filter { it.id != myPlayerId }.joinToString("") { p ->
val pScore = p.cards.sumOf { card ->
val active = if (state.flipped && card.flipSide != null) card.flipSide else card
active.score
}
"${p.name}${pScore}"
}
Scoreboard.addEntry(
context = context,
name = humanPlayerName,
@ -210,7 +221,8 @@ fun LocalGameScreen(
duration = gameDuration,
playerCount = totalPlayers,
turnNumber = gameTurnNumber,
scoreDetail = detailStr
scoreDetail = detailStr,
opponentDetail = opponentDetails
)
}
}

View File

@ -307,6 +307,17 @@ fun ScoreboardScreen(onBack: () -> Unit) {
Spacer(modifier = Modifier.height(4.dp))
Text("难度: ${entry.difficulty} | ${entry.playerCount}人 | ${entry.turnNumber}",
color = Color.White.copy(alpha = 0.5f), fontSize = 12.sp)
// 对手得分
val opps = (entry.opponentDetail ?: "").split("").filter { it.isNotEmpty() }
if (opps.isNotEmpty()) {
Spacer(modifier = Modifier.height(8.dp))
Text("对手得分", color = GoldAccent, fontSize = 14.sp, fontWeight = FontWeight.Bold)
Spacer(modifier = Modifier.height(4.dp))
opps.forEach { opp ->
Text(opp, color = Color.White.copy(alpha = 0.7f), fontSize = 13.sp,
modifier = Modifier.padding(vertical = 1.dp))
}
}
Spacer(modifier = Modifier.height(12.dp))
Text("分数明细", color = GoldAccent, fontSize = 14.sp, fontWeight = FontWeight.Bold)
Spacer(modifier = Modifier.height(6.dp))