From a7da1b8463b98eb822f5359b039afa9e86aaef9f Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Tue, 10 Jul 2018 22:53:54 +0200 Subject: Refactor wonders creation --- .../sevenwonders/game/data/GameDefinition.kt | 8 +++---- .../sevenwonders/game/data/GameDefinitionLoader.kt | 2 +- .../game/data/definitions/WonderDefinition.kt | 25 ++++++++++++++++------ .../game/data/definitions/WonderSideDefinition.kt | 14 ------------ .../game/data/definitions/WonderStageDefinition.kt | 13 ----------- 5 files changed, 24 insertions(+), 38 deletions(-) delete mode 100644 game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderSideDefinition.kt delete mode 100644 game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderStageDefinition.kt (limited to 'game-engine/src/main/kotlin') 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, + private val wonders: List, 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 { - 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::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 loadJson(filename: String, clazz: Class, 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 ) { - 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, + 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, - val image: String -) { - fun createStages(): List { - 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()) - } -} -- cgit