-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: implementing base model classes in a functional way
- Loading branch information
Showing
14 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
src/test/scala/scatan/model/building/BuildingTypeTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
src/test/scala/scatan/model/development/DevelopmentTypeTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
src/test/scala/scatan/model/development/DevelpmentCardTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
src/test/scala/scatan/model/resource/ResourceCardTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
src/test/scala/scatan/model/resource/ResourceTypeTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |