2026-04-26 10:40:54 +08:00

33 lines
927 B
Kotlin

package com.unogame.model
data class GameState(
val players: List<Player> = emptyList(),
val currentPlayerIndex: Int = 0,
val direction: Int = 1,
val discardPile: List<Card> = emptyList(),
val drawPileCount: Int = 76,
val currentWildColor: CardColor? = null,
val isGameOver: Boolean = false,
val winner: Player? = null,
val pendingDrawCount: Int = 0,
val flipped: Boolean = false,
val turnNumber: Int = 0,
val message: String = ""
) {
val currentPlayer: Player
get() = if (players.isEmpty())
Player("", "")
else players[currentPlayerIndex]
val topCard: Card?
get() = discardPile.lastOrNull()
fun nextPlayerIndex(): Int {
if (players.isEmpty()) return 0
var next = currentPlayerIndex + direction
if (next < 0) next = players.size - 1
if (next >= players.size) next = 0
return next
}
}