summaryrefslogtreecommitdiff
path: root/game-engine/src/main/kotlin/org/luxons
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2018-07-08 13:30:41 +0200
committerjbion <joffrey.bion@amadeus.com>2018-07-08 13:34:13 +0200
commit3b844531a2f9ad8037c9666cfff00916b5321cf9 (patch)
treea8505a260ab6cccf4fb3c153c3a1009b0d5a559e /game-engine/src/main/kotlin/org/luxons
parentKotlin mig: api package tests (diff)
downloadseven-wonders-3b844531a2f9ad8037c9666cfff00916b5321cf9.tar.gz
seven-wonders-3b844531a2f9ad8037c9666cfff00916b5321cf9.tar.bz2
seven-wonders-3b844531a2f9ad8037c9666cfff00916b5321cf9.zip
Kotlin mig: wonders package
Diffstat (limited to 'game-engine/src/main/kotlin/org/luxons')
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.kt9
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt45
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt30
3 files changed, 77 insertions, 7 deletions
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 558f16e8..013a3d9c 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
@@ -9,13 +9,8 @@ internal data class WonderDefinition(
private val sides: Map<WonderSide, WonderSideDefinition>
) {
fun create(settings: Settings): Wonder {
- val wonder = Wonder()
- wonder.name = name
-
val wonderSideDef = sides[settings.pickWonderSide()]!!
- wonder.initialResource = wonderSideDef.initialResource
- wonder.stages = wonderSideDef.createStages()
- wonder.image = wonderSideDef.image
- return wonder
+ val stages = wonderSideDef.createStages()
+ return Wonder(name, wonderSideDef.initialResource, stages, wonderSideDef.image)
}
}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt
new file mode 100644
index 00000000..beb87580
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt
@@ -0,0 +1,45 @@
+package org.luxons.sevenwonders.game.wonders
+
+import org.luxons.sevenwonders.game.api.Table
+import org.luxons.sevenwonders.game.cards.CardBack
+import org.luxons.sevenwonders.game.resources.ResourceTransactions
+import org.luxons.sevenwonders.game.resources.ResourceType
+
+class Wonder(
+ val name: String,
+ val initialResource: ResourceType,
+ val stages: List<WonderStage>,
+ val image: String
+) {
+ val nbBuiltStages: Int
+ get() = stages.filter { it.isBuilt }.count()
+
+ private val nextStage: WonderStage
+ get() {
+ val nextLevel = nbBuiltStages
+ if (nextLevel == stages.size) {
+ throw IllegalStateException("This wonder has already reached its maximum level")
+ }
+ return stages[nextLevel]
+ }
+
+ private val lastBuiltStage: WonderStage
+ get() {
+ val lastLevel = nbBuiltStages - 1
+ return stages[lastLevel]
+ }
+
+ fun isNextStageBuildable(table: Table, playerIndex: Int, boughtResources: ResourceTransactions): Boolean =
+ nbBuiltStages < stages.size && nextStage.isBuildable(table, playerIndex, boughtResources)
+
+ fun buildLevel(cardBack: CardBack) = nextStage.build(cardBack)
+
+ fun activateLastBuiltStage(table: Table, playerIndex: Int, boughtResources: ResourceTransactions) =
+ lastBuiltStage.activate(table, playerIndex, boughtResources)
+
+ fun computePoints(table: Table, playerIndex: Int): Int = stages
+ .filter { it.isBuilt }
+ .flatMap { c -> c.effects }
+ .map { e -> e.computePoints(table, playerIndex) }
+ .sum()
+}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt
new file mode 100644
index 00000000..6aad135d
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/wonders/WonderStage.kt
@@ -0,0 +1,30 @@
+package org.luxons.sevenwonders.game.wonders
+
+import org.luxons.sevenwonders.game.api.Table
+import org.luxons.sevenwonders.game.cards.CardBack
+import org.luxons.sevenwonders.game.cards.Requirements
+import org.luxons.sevenwonders.game.effects.Effect
+import org.luxons.sevenwonders.game.resources.ResourceTransactions
+
+class WonderStage(val requirements: Requirements, val effects: List<Effect>) {
+
+ var cardBack: CardBack? = null
+ private set
+
+ val isBuilt: Boolean
+ get() = cardBack != null
+
+ fun isBuildable(table: Table, playerIndex: Int, boughtResources: ResourceTransactions): Boolean {
+ val board = table.getBoard(playerIndex)
+ return requirements.areMetWithHelpBy(board, boughtResources)
+ }
+
+ internal fun build(cardBack: CardBack) {
+ this.cardBack = cardBack
+ }
+
+ internal fun activate(table: Table, playerIndex: Int, boughtResources: ResourceTransactions) {
+ effects.forEach { e -> e.apply(table, playerIndex) }
+ requirements.pay(table, playerIndex, boughtResources)
+ }
+}
bgstack15