diff --git a/src/main/scala/scatan/model/BuildingType.scala b/src/main/scala/scatan/model/BuildingType.scala index 662a78f8..6b281ea4 100644 --- a/src/main/scala/scatan/model/BuildingType.scala +++ b/src/main/scala/scatan/model/BuildingType.scala @@ -2,7 +2,24 @@ package scatan.model import scatan.mvc.lib.Model -enum BuildingType: +type ResourceCost = (ResourceType, Int) +type Cost = Map[ResourceType, Int] +object Cost: + def apply(resourceCosts: ResourceCost*): Cost = resourceCosts.toMap + +import BuildingType.* +enum BuildingType(val cost: Cost): case Settlement - case City - case Road + extends BuildingType( + Cost( + ResourceType.Wood * 1, + ResourceType.Brick * 1, + ResourceType.Wheat * 1, + ResourceType.Sheep * 1 + ) + ) + case City extends BuildingType(Cost(ResourceType.Wheat * 2, ResourceType.Rock * 3)) + case Road extends BuildingType(Cost(ResourceType.Brick * 1, ResourceType.Wood * 1)) + +object BuildingType: + extension (resourceType: ResourceType) def *(amount: Int): ResourceCost = (resourceType, amount) diff --git a/src/test/scala/scatan/model/building/BuildingTypeTest.scala b/src/test/scala/scatan/model/building/BuildingTypeTest.scala index 8716fa2f..e08a3467 100644 --- a/src/test/scala/scatan/model/building/BuildingTypeTest.scala +++ b/src/test/scala/scatan/model/building/BuildingTypeTest.scala @@ -3,6 +3,9 @@ package scatan.model.building import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should import scatan.model.BuildingType +import scatan.model.BuildingType.* +import scatan.model.ResourceType +import scatan.model.Cost class BuildingTypeTest extends AnyFlatSpec with should.Matchers: @@ -25,3 +28,16 @@ class BuildingTypeTest extends AnyFlatSpec with should.Matchers: val buildingType: BuildingType = BuildingType.Road buildingType should be(BuildingType.Road) } + + it should "have a cost" in { + BuildingType.Road.cost should be(Cost(ResourceType.Brick * 1, ResourceType.Wood * 1)) + BuildingType.Settlement.cost should be( + Cost( + ResourceType.Wood * 1, + ResourceType.Brick * 1, + ResourceType.Wheat * 1, + ResourceType.Sheep * 1 + ) + ) + BuildingType.City.cost should be(Cost(ResourceType.Wheat * 2, ResourceType.Rock * 3)) + }