Skip to content

Commit

Permalink
wip: implementing base model classes in a functional way
Browse files Browse the repository at this point in the history
  • Loading branch information
alemazzo committed Sep 9, 2023
1 parent eb71088 commit 5fa62c4
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/scala/scatan/model/Building.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package scatan.model

import scatan.mvc.lib.Model

final case class Building(buildingType: BuildingType)
8 changes: 8 additions & 0 deletions src/main/scala/scatan/model/BuildingType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package scatan.model

import scatan.mvc.lib.Model

enum BuildingType:
case Settlement
case City
case Road
5 changes: 5 additions & 0 deletions src/main/scala/scatan/model/DevelopmentCard.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package scatan.model

import scatan.mvc.lib.Model

final case class DevelopmentCard(developmentType: DevelopmentType)
10 changes: 10 additions & 0 deletions src/main/scala/scatan/model/DevelopmentType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package scatan.model

import scatan.mvc.lib.Model

enum DevelopmentType:
case Knight
case RoadBuilding
case YearOfPlenty
case Monopoly
case VictoryPoint
27 changes: 27 additions & 0 deletions src/main/scala/scatan/model/Player.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package scatan.model

import scatan.mvc.lib.Model

enum Color:
case Red
case Blue
case Green
case Yellow

final case class Player(
name: String,
color: Color,
buildings: Seq[Building] = Seq.empty,
resources: Seq[ResourceCard] = Seq.empty,
developmentCards: Seq[DevelopmentCard] = Seq.empty
)

extension (player: Player)
def addBuilding(building: Building): Player =
player.copy(buildings = player.buildings :+ building)

def addResource(resource: ResourceCard): Player =
player.copy(resources = player.resources :+ resource)

def addDevelopmentCard(developmentCard: DevelopmentCard): Player =
player.copy(developmentCards = player.developmentCards :+ developmentCard)
5 changes: 5 additions & 0 deletions src/main/scala/scatan/model/ResourceCard.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package scatan.model

import scatan.mvc.lib.Model

final case class ResourceCard(resourceType: ResourceType)
10 changes: 10 additions & 0 deletions src/main/scala/scatan/model/ResourceType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package scatan.model

import scatan.mvc.lib.Model

enum ResourceType:
case Wood
case Brick
case Sheep
case Wheat
case Rock
57 changes: 57 additions & 0 deletions src/test/scala/scatan/model/PlayerTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package scatan.model

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should

class PlayerTest extends AnyFlatSpec with should.Matchers:

"A Player" should "exists" in {
val player: Player = Player("name", Color.Red)
player should not be null
}

it should "have a name" in {
val player: Player = Player("name", Color.Red)
player.name should be("name")
}

it should "have a color" in {
val player: Player = Player("name", Color.Red)
player.color should be(Color.Red)
}

it should "have buildings" in {
val player: Player = Player("name", Color.Red, Seq.empty)
player.buildings should be(Seq.empty[Building])
}

it should "have resources" in {
val player: Player = Player("name", Color.Red, Seq.empty, Seq.empty)
player.resources should be(Seq.empty[ResourceCard])
}

it should "have development cards" in {
val player: Player = Player("name", Color.Red, Seq.empty, Seq.empty, Seq.empty)
player.developmentCards should be(Seq.empty[DevelopmentCard])
}

it should "be able to add a building" in {
val player: Player = Player("name", Color.Red)
val building: Building = Building(BuildingType.City)
val playerWithBuilding: Player = player.addBuilding(building)
playerWithBuilding.buildings should be(Seq(building))
}

it should "be able to add a resource" in {
val player: Player = Player("name", Color.Red)
val resource: ResourceCard = ResourceCard(ResourceType.Brick)
val playerWithResource: Player = player.addResource(resource)
playerWithResource.resources should be(Seq(resource))
}

it should "be able to add a development card" in {
val player: Player = Player("name", Color.Red)
val developmentCard: DevelopmentCard = DevelopmentCard(DevelopmentType.Knight)
val playerWithDevelopmentCard: Player = player.addDevelopmentCard(developmentCard)
playerWithDevelopmentCard.developmentCards should be(Seq(developmentCard))
}
17 changes: 17 additions & 0 deletions src/test/scala/scatan/model/building/BuildingTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package scatan.model.building

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should
import scatan.model.{Building, BuildingType}

class BuildingTest extends AnyFlatSpec with should.Matchers:

"A Building" should "exists" in {
val building: Building = Building(BuildingType.Settlement)
building should not be null
}

it should "have a building type" in {
val building: Building = Building(BuildingType.Settlement)
building.buildingType should be(BuildingType.Settlement)
}
27 changes: 27 additions & 0 deletions src/test/scala/scatan/model/building/BuildingTypeTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package scatan.model.building

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should
import scatan.model.BuildingType

class BuildingTypeTest extends AnyFlatSpec with should.Matchers:

"A BuildingType" should "exists" in {
val buildingType: BuildingType = BuildingType.Settlement
buildingType should not be null
}

it should "be able to be a settlement" in {
val buildingType: BuildingType = BuildingType.Settlement
buildingType should be(BuildingType.Settlement)
}

it should "be able to be a city" in {
val buildingType: BuildingType = BuildingType.City
buildingType should be(BuildingType.City)
}

it should "be able to be a road" in {
val buildingType: BuildingType = BuildingType.Road
buildingType should be(BuildingType.Road)
}
37 changes: 37 additions & 0 deletions src/test/scala/scatan/model/development/DevelopmentTypeTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package scatan.model.development

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should
import scatan.model.DevelopmentType

class DevelopmentTypeTest extends AnyFlatSpec with should.Matchers:

"A DevelopmentType" should "exists" in {
val developmentType: DevelopmentType = DevelopmentType.Knight
developmentType should not be null
}

it should "be able to be a knight" in {
val developmentType: DevelopmentType = DevelopmentType.Knight
developmentType should be(DevelopmentType.Knight)
}

it should "be able to be a victory point" in {
val developmentType: DevelopmentType = DevelopmentType.VictoryPoint
developmentType should be(DevelopmentType.VictoryPoint)
}

it should "be able to be a road building" in {
val developmentType: DevelopmentType = DevelopmentType.RoadBuilding
developmentType should be(DevelopmentType.RoadBuilding)
}

it should "be able to be a monopoly" in {
val developmentType: DevelopmentType = DevelopmentType.Monopoly
developmentType should be(DevelopmentType.Monopoly)
}

it should "be able to be a year of plenty" in {
val developmentType: DevelopmentType = DevelopmentType.YearOfPlenty
developmentType should be(DevelopmentType.YearOfPlenty)
}
17 changes: 17 additions & 0 deletions src/test/scala/scatan/model/development/DevelpmentCardTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package scatan.model.development

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should
import scatan.model.{DevelopmentCard, DevelopmentType}

class DevelpmentCardTest extends AnyFlatSpec with should.Matchers:

"A DevelopmentCard" should "exists" in {
val developmentCard: DevelopmentCard = DevelopmentCard(DevelopmentType.Knight)
developmentCard should not be null
}

it should "have a development type" in {
val developmentCard: DevelopmentCard = DevelopmentCard(DevelopmentType.Knight)
developmentCard.developmentType should be(DevelopmentType.Knight)
}
16 changes: 16 additions & 0 deletions src/test/scala/scatan/model/resource/ResourceCardTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package scatan.model

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should

class ResourceCardTest extends AnyFlatSpec with should.Matchers:

"A ResourceCard" should "exists" in {
val resourceCard: ResourceCard = ResourceCard(ResourceType.Brick)
resourceCard should not be null
}

it should "have a resource type" in {
val resourceCard: ResourceCard = ResourceCard(ResourceType.Brick)
resourceCard.resourceType should be(ResourceType.Brick)
}
36 changes: 36 additions & 0 deletions src/test/scala/scatan/model/resource/ResourceTypeTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package scatan.model

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should

class ResourceTypeTest extends AnyFlatSpec with should.Matchers:

"A ResourceType" should "exists" in {
val resourceType: ResourceType = ResourceType.Brick
resourceType should not be null
}

it should "be able to be a wood" in {
val resourceType: ResourceType = ResourceType.Wood
resourceType should be(ResourceType.Wood)
}

it should "be able to be a brick" in {
val resourceType: ResourceType = ResourceType.Brick
resourceType should be(ResourceType.Brick)
}

it should "be able to be a sheep" in {
val resourceType: ResourceType = ResourceType.Sheep
resourceType should be(ResourceType.Sheep)
}

it should "be able to be a wheat" in {
val resourceType: ResourceType = ResourceType.Wheat
resourceType should be(ResourceType.Wheat)
}

it should "be able to be a rock" in {
val resourceType: ResourceType = ResourceType.Rock
resourceType should be(ResourceType.Rock)
}

0 comments on commit 5fa62c4

Please sign in to comment.