786b813f7b
- Full UNO game logic with AI opponents - Compose Multiplatform UI with animations - Shared module (commonMain) with game engine - Desktop app (Compose Desktop) - Android app (Compose Multiplatform) - Web app (Kotlin/Wasm) - Nix shell for reproducible dev environment
60 lines
1.4 KiB
Kotlin
60 lines
1.4 KiB
Kotlin
package com.uno.game.model
|
|
|
|
import kotlinx.serialization.Serializable
|
|
|
|
@Serializable
|
|
enum class CardColor {
|
|
RED, GREEN, BLUE, YELLOW;
|
|
|
|
val displayName: String
|
|
get() = when (this) {
|
|
RED -> "Rot"
|
|
GREEN -> "Grün"
|
|
BLUE -> "Blau"
|
|
YELLOW -> "Gelb"
|
|
}
|
|
}
|
|
|
|
@Serializable
|
|
enum class CardValue(val points: Int) {
|
|
ZERO(0),
|
|
ONE(1), TWO(2), THREE(3), FOUR(4),
|
|
FIVE(5), SIX(6), SEVEN(7), EIGHT(8), NINE(9),
|
|
SKIP(20),
|
|
REVERSE(20),
|
|
DRAW_TWO(20),
|
|
WILD(50),
|
|
WILD_DRAW_FOUR(50);
|
|
|
|
val isActionCard: Boolean
|
|
get() = this in listOf(SKIP, REVERSE, DRAW_TWO, WILD, WILD_DRAW_FOUR)
|
|
|
|
val isWild: Boolean
|
|
get() = this in listOf(WILD, WILD_DRAW_FOUR)
|
|
}
|
|
|
|
@Serializable
|
|
data class Card(
|
|
val color: CardColor?,
|
|
val value: CardValue
|
|
) {
|
|
val isWild: Boolean get() = value.isWild
|
|
val isActionCard: Boolean get() = value.isActionCard
|
|
val displayValue: String
|
|
get() = when (value) {
|
|
CardValue.SKIP -> "🚫"
|
|
CardValue.REVERSE -> "↩️"
|
|
CardValue.DRAW_TWO -> "+2"
|
|
CardValue.WILD -> "🌈"
|
|
CardValue.WILD_DRAW_FOUR -> "+4"
|
|
else -> value.ordinal.toString()
|
|
}
|
|
|
|
fun canPlayOn(topCard: Card, currentColor: CardColor?): Boolean {
|
|
if (isWild) return true
|
|
if (color == currentColor) return true
|
|
if (value == topCard.value) return true
|
|
return false
|
|
}
|
|
}
|