Skip to content

Commit

Permalink
chore: implemented BuildingType cost
Browse files Browse the repository at this point in the history
  • Loading branch information
alemazzo committed Sep 19, 2023
1 parent 5bbe36a commit 45d61c8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/main/scala/scatan/model/BuildingType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 16 additions & 0 deletions src/test/scala/scatan/model/building/BuildingTypeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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))
}

0 comments on commit 45d61c8

Please sign in to comment.