diff options
author | jbion <joffrey.bion@amadeus.com> | 2019-02-26 22:12:37 +0100 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2019-02-26 22:12:37 +0100 |
commit | 20625511ff872404e70984f5b21e3f514793c511 (patch) | |
tree | 521803194965ae4ef633f4c12003472d573c4b84 /game-engine/src/main | |
parent | Add board and played cards (diff) | |
download | seven-wonders-20625511ff872404e70984f5b21e3f514793c511.tar.gz seven-wonders-20625511ff872404e70984f5b21e3f514793c511.tar.bz2 seven-wonders-20625511ff872404e70984f5b21e3f514793c511.zip |
Add support for multiple columns
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( |