diff options
Diffstat (limited to 'game-engine/src/main')
5 files changed, 24 insertions, 38 deletions
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/GameDefinition.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/GameDefinition.kt index 43703877..9c0ac87a 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/GameDefinition.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/GameDefinition.kt @@ -9,7 +9,7 @@ import org.luxons.sevenwonders.game.data.definitions.WonderDefinition class GameDefinition internal constructor( rules: GlobalRules, - private val wonders: Array<WonderDefinition>, + private val wonders: List<WonderDefinition>, private val decksDefinition: DecksDefinition ) { val minPlayers: Int = rules.minPlayers @@ -23,8 +23,8 @@ class GameDefinition internal constructor( } private fun assignBoards(settings: Settings, nbPlayers: Int): List<Board> { - val randomizedWonders = wonders.toMutableList() - randomizedWonders.shuffle(settings.random) - return randomizedWonders.take(nbPlayers).mapIndexed { i, wDef -> Board(wDef.create(settings), i, settings) } + return wonders.shuffled(settings.random) + .take(nbPlayers) + .mapIndexed { i, wDef -> Board(wDef.create(settings.pickWonderSide()), i, settings) } } } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/GameDefinitionLoader.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/GameDefinitionLoader.kt index 74b5b086..103adcae 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/GameDefinitionLoader.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/GameDefinitionLoader.kt @@ -30,7 +30,7 @@ class GameDefinitionLoader { val rules = loadJson("global_rules.json", GlobalRules::class.java, gson) val wonders = loadJson("wonders.json", Array<WonderDefinition>::class.java, gson) val decksDefinition = loadJson("cards.json", DecksDefinition::class.java, gson) - return GameDefinition(rules, wonders, decksDefinition) + return GameDefinition(rules, wonders.toList(), decksDefinition) } private fun <T> loadJson(filename: String, clazz: Class<T>, gson: Gson): T { diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.kt index 2e6efac4..c75e18d4 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.kt @@ -1,16 +1,29 @@ package org.luxons.sevenwonders.game.data.definitions -import org.luxons.sevenwonders.game.Settings +import org.luxons.sevenwonders.game.cards.Requirements import org.luxons.sevenwonders.game.data.WonderSide +import org.luxons.sevenwonders.game.resources.ResourceType import org.luxons.sevenwonders.game.wonders.Wonder +import org.luxons.sevenwonders.game.wonders.WonderStage internal class WonderDefinition( private val name: String, private val sides: Map<WonderSide, WonderSideDefinition> ) { - fun create(settings: Settings): Wonder { - val wonderSideDef = sides[settings.pickWonderSide()]!! - val stages = wonderSideDef.createStages() - return Wonder(name, wonderSideDef.initialResource, stages, wonderSideDef.image) - } + fun create(wonderSide: WonderSide): Wonder = sides[wonderSide]!!.createWonder(name) +} + +internal class WonderSideDefinition( + private val initialResource: ResourceType, + private val stages: List<WonderStageDefinition>, + private val image: String +) { + fun createWonder(name: String): Wonder = Wonder(name, initialResource, stages.map { it.create() }, image) +} + +internal class WonderStageDefinition( + private val requirements: Requirements, + private val effects: EffectsDefinition +) { + fun create(): WonderStage = WonderStage(requirements, effects.create()) } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderSideDefinition.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderSideDefinition.kt deleted file mode 100644 index 247432e3..00000000 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderSideDefinition.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.luxons.sevenwonders.game.data.definitions - -import org.luxons.sevenwonders.game.resources.ResourceType -import org.luxons.sevenwonders.game.wonders.WonderStage - -internal class WonderSideDefinition( - val initialResource: ResourceType, - private val stages: List<WonderStageDefinition>, - val image: String -) { - fun createStages(): List<WonderStage> { - return stages.map { def -> def.create() } - } -} diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderStageDefinition.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderStageDefinition.kt deleted file mode 100644 index 3d2872d0..00000000 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderStageDefinition.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.luxons.sevenwonders.game.data.definitions - -import org.luxons.sevenwonders.game.cards.Requirements -import org.luxons.sevenwonders.game.wonders.WonderStage - -internal class WonderStageDefinition( - private val requirements: Requirements, - private val effects: EffectsDefinition -) { - fun create(): WonderStage { - return WonderStage(requirements, effects.create()) - } -} |