diff options
Diffstat (limited to 'game-engine/src/main')
-rw-r--r-- | game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt | 15 | ||||
-rw-r--r-- | game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt | 16 |
2 files changed, 21 insertions, 10 deletions
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt index 2dd481ca..470b4efa 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt @@ -23,7 +23,7 @@ data class Board( val publicProduction: ApiProduction, val science: ApiScience, val military: ApiMilitary, - val playedCards: List<TableCard>, + val playedCards: List<List<TableCard>>, val gold: Int ) @@ -34,10 +34,21 @@ internal fun InternalBoard.toApiBoard(player: Player, lastMove: Move?): Board = publicProduction = publicProduction.toApiProduction(), science = science.toApiScience(), military = military.toApiMilitary(), - playedCards = getPlayedCards().map { it.toTableCard(lastMove) }, + playedCards = getPlayedCards().map { it.toTableCard(lastMove) }.toColumns(), gold = gold ) +internal fun List<TableCard>.toColumns(): List<List<TableCard>> { + val cardsByColor = this.groupBy { it.color } + val (resourceCardsCols, otherCols) = cardsByColor.values.partition { it[0].color.isResource } + val resourceCardsCol = resourceCardsCols.flatten() + val otherColsSorted = otherCols.sortedBy { it[0].color } + if (resourceCardsCol.isEmpty()) { + return otherColsSorted // we want only non-empty columns + } + return listOf(resourceCardsCol) + otherColsSorted +} + data class Wonder( val name: String, val initialResource: ResourceType, diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt index cf4df44e..18d9cb96 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt @@ -41,14 +41,14 @@ internal data class Card( } } -enum class Color { - BROWN, - GREY, - YELLOW, - BLUE, - GREEN, - RED, - PURPLE +enum class Color(val isResource: Boolean) { + BROWN(true), + GREY(true), + YELLOW(false), + BLUE(false), + GREEN(false), + RED(false), + PURPLE(false) } data class CardPlayability( |