diff --git a/.bsp/sbt.json b/.bsp/sbt.json index d041aef..0e7fda3 100644 --- a/.bsp/sbt.json +++ b/.bsp/sbt.json @@ -1 +1 @@ -{"name":"sbt","version":"1.8.2","bspVersion":"2.1.0-M1","languages":["scala"],"argv":["C:\\Users\\Ignacio\\.jdks\\openjdk-19/bin/java","-Xms100m","-Xmx100m","-classpath","C:/Users/Ignacio/AppData/Local/JetBrains/Toolbox/apps/IDEA-U/ch-0/223.8836.41.plugins/Scala/launcher/sbt-launch.jar","-Dsbt.script=C:\\Program%20Files%20(x86)\\sbt\\bin\\sbt.bat","xsbt.boot.Boot","-bsp"]} \ No newline at end of file +{"name":"sbt","version":"1.8.2","bspVersion":"2.1.0-M1","languages":["scala"],"argv":["C:\\Users\\Usuario\\.jdks\\openjdk-19.0.2/bin/java","-Xms100m","-Xmx100m","-classpath","C:/Users/Usuario/AppData/Roaming/JetBrains/IntelliJIdea2022.3/plugins/Scala/launcher/sbt-launch.jar","xsbt.boot.Boot","-bsp","--sbt-launch-jar=C:/Users/Usuario/AppData/Roaming/JetBrains/IntelliJIdea2022.3/plugins/Scala/launcher/sbt-launch.jar"]} \ No newline at end of file diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..4dcbefa --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +gwent \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index dd0d86e..d6b961a 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,53 +1,5 @@ - - \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml index 6df95bc..a55e7a1 100644 --- a/.idea/codeStyles/codeStyleConfig.xml +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -1,5 +1,5 @@ - \ No newline at end of file diff --git a/.idea/libraries/sbt__junit_junit_4_13_2_jar.xml b/.idea/libraries/sbt__junit_junit_4_13_2_jar.xml index 48da8ef..6340917 100644 --- a/.idea/libraries/sbt__junit_junit_4_13_2_jar.xml +++ b/.idea/libraries/sbt__junit_junit_4_13_2_jar.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/libraries/sbt__org_hamcrest_hamcrest_core_1_3_jar.xml b/.idea/libraries/sbt__org_hamcrest_hamcrest_core_1_3_jar.xml index e415d3b..e9a5a19 100644 --- a/.idea/libraries/sbt__org_hamcrest_hamcrest_core_1_3_jar.xml +++ b/.idea/libraries/sbt__org_hamcrest_hamcrest_core_1_3_jar.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/libraries/sbt__org_scala_lang_scala3_library_3_3_2_2_jar.xml b/.idea/libraries/sbt__org_scala_lang_scala3_library_3_3_2_2_jar.xml index b48c846..62a9dd5 100644 --- a/.idea/libraries/sbt__org_scala_lang_scala3_library_3_3_2_2_jar.xml +++ b/.idea/libraries/sbt__org_scala_lang_scala3_library_3_3_2_2_jar.xml @@ -3,60 +3,60 @@ Scala_3_2 - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/sbt__org_scala_lang_scala_library_2_13_10_jar.xml b/.idea/libraries/sbt__org_scala_lang_scala_library_2_13_10_jar.xml index ea17d8a..f3892ab 100644 --- a/.idea/libraries/sbt__org_scala_lang_scala_library_2_13_10_jar.xml +++ b/.idea/libraries/sbt__org_scala_lang_scala_library_2_13_10_jar.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/libraries/sbt__org_scala_sbt_test_interface_1_0_jar.xml b/.idea/libraries/sbt__org_scala_sbt_test_interface_1_0_jar.xml index b74c24e..9522148 100644 --- a/.idea/libraries/sbt__org_scala_sbt_test_interface_1_0_jar.xml +++ b/.idea/libraries/sbt__org_scala_sbt_test_interface_1_0_jar.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/libraries/sbt__org_scalameta_junit_interface_0_7_29_jar.xml b/.idea/libraries/sbt__org_scalameta_junit_interface_0_7_29_jar.xml index 1d6d600..3eecfb4 100644 --- a/.idea/libraries/sbt__org_scalameta_junit_interface_0_7_29_jar.xml +++ b/.idea/libraries/sbt__org_scalameta_junit_interface_0_7_29_jar.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/libraries/sbt__org_scalameta_munit_3_0_7_29_jar.xml b/.idea/libraries/sbt__org_scalameta_munit_3_0_7_29_jar.xml index a175522..40a2a8e 100644 --- a/.idea/libraries/sbt__org_scalameta_munit_3_0_7_29_jar.xml +++ b/.idea/libraries/sbt__org_scalameta_munit_3_0_7_29_jar.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/modules/gwent-build.iml b/.idea/modules/gwent-build.iml index 3b0273d..baca593 100644 --- a/.idea/modules/gwent-build.iml +++ b/.idea/modules/gwent-build.iml @@ -109,8 +109,8 @@ - \ No newline at end of file diff --git a/.idea/modules/gwent.iml b/.idea/modules/gwent.iml index 54312c4..fac9c5f 100644 --- a/.idea/modules/gwent.iml +++ b/.idea/modules/gwent.iml @@ -1,5 +1,5 @@ - + diff --git a/src/main/scala/gwent/IPlayer.scala b/src/main/scala/gwent/IPlayer.scala new file mode 100644 index 0000000..dbedfba --- /dev/null +++ b/src/main/scala/gwent/IPlayer.scala @@ -0,0 +1,28 @@ +package cl.uchile.dcc +package gwent + +import card.ICard + +import scala.collection.mutable.ListBuffer +/** Trait that dictates the general actions of a Player class */ +trait IPlayer { + val name: String + var deck: ListBuffer[ICard] + /** Method that plays a Card */ + def playCard(card: ICard): Boolean + /** Method that shuffles the Player's Deck */ + def shuffleDeck: Boolean + /** Method that draws cards from the Player's deck */ + def drawCards(): Boolean + /** Method that returns the Hand of the Player */ + def getHand: ListBuffer[ICard] + /** Method that returns the Deck of the Player */ + def getDeck: ListBuffer[ICard] + /** Method that returns the name of the Player */ + def getName: String + /** Method that returns the current gems of the Player */ + def getGems: Int + /** Method that returns True if the Player can lose the given gems or false if not*/ + def setGems(value: Int): Boolean + +} diff --git a/src/main/scala/gwent/Player.scala b/src/main/scala/gwent/Player.scala new file mode 100644 index 0000000..af66d0c --- /dev/null +++ b/src/main/scala/gwent/Player.scala @@ -0,0 +1,76 @@ +package cl.uchile.dcc +package gwent + +import card.{AbstractCard, ICard} + +import scala.collection.mutable.ListBuffer +import scala.util.Random + +/** Class that represents a player in Gwent */ +class Player(val name: String, var deck: ListBuffer[ICard]) extends IPlayer with Equals { + /** Gems are the "HP" in Gwent */ + private var gems: Int = 2 + private var hand: ListBuffer[ICard] = ListBuffer() + + override def equals(that: Any): Boolean = { + if(canEqual(that)){ + val other = that.asInstanceOf[Player] + (this eq other) || (this.name == other.name && this.deck == other.deck && this.hand == other.hand) + } else { + false + } + } + override def canEqual(that: Any): Boolean = { + that.isInstanceOf[Player] + } + override def drawCards(): Boolean = { + /* if there are cards in deck -> add to hand and true, if not false */ + if (this.deck.isEmpty){ + false + } else{ + val card: ICard = this.deck.head + this.hand += card + this.deck.remove(0) + true + } + } + + override def getName: String = this.name + + override def getGems: Int = this.gems + + override def setGems(value: Int): Boolean = { + if (this.gems > 0) { + this.gems -= value + true + } else { + false + } + } + + override def getDeck: ListBuffer[ICard] = this.deck + + override def getHand: ListBuffer[ICard] = this.hand + + override def shuffleDeck: Boolean = { + if (this.deck.nonEmpty) { + Random.shuffle(this.deck) + true + } else { + println("Deck is empty") + false + } + } + + override def playCard(card: ICard): Boolean = { + /* if the card is in hand -> true and play it, if not false */ + if (this.hand.contains(card) && this.hand.nonEmpty){ + //Not yet implemented + this.hand -= card + true + } else{ + println("Card not in hand") + false + } + } +} diff --git a/src/main/scala/gwent/board/Board.scala b/src/main/scala/gwent/board/Board.scala new file mode 100644 index 0000000..a0642df --- /dev/null +++ b/src/main/scala/gwent/board/Board.scala @@ -0,0 +1,51 @@ +package cl.uchile.dcc +package gwent.board +import gwent.card.{ClimateCard, ICard, MeleeUnitCard, RangeUnitCard, SiegeUnitCard} +import gwent.IPlayer + + +/** Class representing a Board in the game Gwen't + * + * The board has players and zones for each player. + * + * @constructor Create a new board with two players + * @param side1 Player 1. + * @param side2 Player 2. + * @param climateSlot where the ClimateCard is placed + * + * @author Jose Pereira Morgado + * @version 1.2 + * @since 1.2 + */ +class Board(val side1: PlayerSide, val side2: PlayerSide, var climateSlot: ClimateCard) extends Equals{ + + override def canEqual(that: Any): Boolean = { + that.isInstanceOf[Board] + } + + override def equals(that: Any): Boolean = { + if (canEqual(that)) { + val other = that.asInstanceOf[Board] + (this eq other) || (this.side1 == other.side1 && this.side2 == other.side2) + } else { + false + } + } + + /** Places a ClimateCard on it's Slot */ + def placeClimateCard(cl: ClimateCard): Unit = { + climateSlot = cl + } + + def placeMeleeCard(m: MeleeUnitCard): Unit = { + side1.placeMeleeCard(m) + } + + def placeRangeCard(r: RangeUnitCard): Unit = { + side1.placeRangeCard(r) + } + + def placeSiegeCard(s: SiegeUnitCard): Unit = { + side1.placeSiegeCard(s) + } +} diff --git a/src/main/scala/gwent/board/PlayerSide.scala b/src/main/scala/gwent/board/PlayerSide.scala new file mode 100644 index 0000000..0ddbc92 --- /dev/null +++ b/src/main/scala/gwent/board/PlayerSide.scala @@ -0,0 +1,65 @@ +package cl.uchile.dcc +package gwent.board +import gwent.IPlayer +import gwent.card.{ClimateCard, ICard, MeleeUnitCard, RangeUnitCard, SiegeUnitCard} + +import scala.collection.mutable.ListBuffer + +/** Class representing a Player's Board in the game Gwen't + * + * The player's board has space for every kind of Card + * Only one for ClimateCards (shared by both players)! read the README for more info + * + * @constructor Create a new player's board for a given Player + * @param player Player that uses the board. + * @param climateSlot Contains the currently active ClimateCard. + * @param meleeZone where the MeleeUnitCards will be placed + * @param rangeZone where the RangeUnitCards will be placed + * @param siegeZone where the SiegeUnitCards will be placed + * + * @author Jose Pereira Morgado + * @version 1.2 + * @since 1.2 + */ +class PlayerSide(val player: IPlayer, + var climateSlot: ICard, + val meleeZone: ListBuffer[ICard], + val rangeZone: ListBuffer[ICard], + val siegeZone: ListBuffer[ICard]) extends Equals { + override def canEqual(that: Any): Boolean = { + that.isInstanceOf[PlayerSide] + } + + override def equals(that: Any): Boolean = { + if (canEqual(that)) { + val other = that.asInstanceOf[PlayerSide] + (this eq other) || (this.player == other.player && + this.meleeZone == other.meleeZone && + this.rangeZone == other.rangeZone && + this.siegeZone == other.siegeZone) + } else { + false + } + } + + /** Places a ClimateCard on it's Slot */ + def placeClimateCard(cl: ClimateCard): Unit = { + climateSlot = cl + } + + /** Places a Melee Card on it's Zone/Row */ + def placeMeleeCard(m : MeleeUnitCard): Unit = { + meleeZone.addOne(m) + } + + /** Places a RangeUnitCard on it's Zone/Row */ + def placeRangeCard(r: RangeUnitCard): Unit = { + meleeZone.addOne(r) + } + + /** Places a SiegeUnitCard on it's Zone/Row */ + def placeSiegeCard(s: SiegeUnitCard): Unit = { + meleeZone.addOne(s) + } + +} diff --git a/src/main/scala/gwent/card/AbstractCard.scala b/src/main/scala/gwent/card/AbstractCard.scala new file mode 100644 index 0000000..6382dcc --- /dev/null +++ b/src/main/scala/gwent/card/AbstractCard.scala @@ -0,0 +1,9 @@ +package cl.uchile.dcc +package gwent.card + +/** Class that represents a card in the game Gwent */ +abstract class AbstractCard(val name: String, val effect: String) extends ICard { + override def getName: String + + override def getEffect: String +} diff --git a/src/main/scala/gwent/card/AbstractUnitCard.scala b/src/main/scala/gwent/card/AbstractUnitCard.scala new file mode 100644 index 0000000..f82a988 --- /dev/null +++ b/src/main/scala/gwent/card/AbstractUnitCard.scala @@ -0,0 +1,28 @@ +package cl.uchile.dcc +package gwent.card +import gwent.board.PlayerSide + +/** Class that represents the Unit Cards in the game Gwent */ +abstract class AbstractUnitCard(val name: String, val effect: String, var _power: Int) extends ICard with Equals { + override def canEqual(that: Any): Boolean = { + that.isInstanceOf[AbstractUnitCard] + } + + override def equals(that: Any): Boolean = { + if (canEqual(that)) { + val other = that.asInstanceOf[AbstractUnitCard] + (this eq other) || (this.name == other.name && this.effect == other.effect && this._power == other._power) + } else { + false + } + } + /** Method that returns the power from a Unit Card */ + def power: Int = _power + + /** Method that changed the value of power from a Unit Card */ + def power_(newPower: Int): Unit = { + _power = newPower + } + /** Method that plays a UnitCard on the board */ + override def playCard(b: PlayerSide): Unit +} diff --git a/src/main/scala/gwent/card/ClimateCard.scala b/src/main/scala/gwent/card/ClimateCard.scala new file mode 100644 index 0000000..a75f1e8 --- /dev/null +++ b/src/main/scala/gwent/card/ClimateCard.scala @@ -0,0 +1,22 @@ +package cl.uchile.dcc +package gwent.card +import gwent.board.PlayerSide + +/** Class that represents the Climate Cards in the game Gwent */ +class ClimateCard(val name: String, val effect: String) extends ICard with Equals{ + override def canEqual(that: Any): Boolean = { + that.isInstanceOf[ClimateCard] + } + override def equals(that: Any): Boolean = { + if (canEqual(that)){ + val other = that.asInstanceOf[ClimateCard] + (this eq other) || (this.name == other.name && this.effect == other.effect) + } else { + false + } + } + + override def playCard(b: PlayerSide): Unit = { + b.placeClimateCard(this) + } +} diff --git a/src/main/scala/gwent/card/ICard.scala b/src/main/scala/gwent/card/ICard.scala new file mode 100644 index 0000000..7aa647e --- /dev/null +++ b/src/main/scala/gwent/card/ICard.scala @@ -0,0 +1,14 @@ +package cl.uchile.dcc +package gwent.card + +import gwent.board.PlayerSide + +/** Trait that dictates the general behavior of a Card */ +trait ICard { + /** Method that returns the Card's name */ + val name: String + val effect: String + + def playCard(b: PlayerSide): Unit + +} diff --git a/src/main/scala/gwent/card/MeleeUnitCard.scala b/src/main/scala/gwent/card/MeleeUnitCard.scala new file mode 100644 index 0000000..e05573e --- /dev/null +++ b/src/main/scala/gwent/card/MeleeUnitCard.scala @@ -0,0 +1,23 @@ +package cl.uchile.dcc +package gwent.card +import gwent.board.PlayerSide + +/** Class that represents a Melee Unit Card in the game Gwent */ +class MeleeUnitCard(name: String, effect: String, power: Int) extends AbstractUnitCard(name, effect, power) with Equals { + override def canEqual(that: Any): Boolean = { + that.isInstanceOf[MeleeUnitCard] + } + override def equals(that: Any): Boolean = { + if (canEqual(that)) { + val other = that.asInstanceOf[MeleeUnitCard] + (this eq other) || (this.name == other.name && this.effect == other.effect && this.power == other.power) + } else { + false + } + } + + override def playCard(b: PlayerSide): Unit = { + b.placeMeleeCard(this) + } + +} diff --git a/src/main/scala/gwent/card/RangeUnitCard.scala b/src/main/scala/gwent/card/RangeUnitCard.scala new file mode 100644 index 0000000..fae7fa1 --- /dev/null +++ b/src/main/scala/gwent/card/RangeUnitCard.scala @@ -0,0 +1,25 @@ +package cl.uchile.dcc +package gwent.card + +import gwent.board.PlayerSide + +/** Class that represents a Range Unit Card in the game Gwent */ +class RangeUnitCard(name: String, effect: String, power: Int) extends AbstractUnitCard(name, effect, power) with Equals { + override def canEqual(that: Any): Boolean = { + that.isInstanceOf[RangeUnitCard] + } + + override def equals(that: Any): Boolean = { + if (canEqual(that)) { + val other = that.asInstanceOf[RangeUnitCard] + (this eq other) || (this.name == other.name && this.effect == other.effect && this.power == other.power) + } else { + false + } + } + + override def playCard(b: PlayerSide): Unit = { + b.placeRangeCard(this) + } + +} diff --git a/src/main/scala/gwent/card/SiegeUnitCard.scala b/src/main/scala/gwent/card/SiegeUnitCard.scala new file mode 100644 index 0000000..b63b4bf --- /dev/null +++ b/src/main/scala/gwent/card/SiegeUnitCard.scala @@ -0,0 +1,22 @@ +package cl.uchile.dcc +package gwent.card +import gwent.board.PlayerSide + +/** Class that represents a Siege Unit Card in the game Gwent */ +class SiegeUnitCard(name: String, effect: String, power: Int) extends AbstractUnitCard(name,effect,power) with Equals { + override def canEqual(that: Any): Boolean = { + that.isInstanceOf[SiegeUnitCard] + } + override def equals(that: Any): Boolean = { + if (canEqual(that)){ + val other = that.asInstanceOf[SiegeUnitCard] + (this eq other) || (this.name == other.name && this.effect == other.effect && this.power == other.power) + } else { + false + } + } + + override def playCard(b: PlayerSide): Unit = { + b.placeSiegeCard(this) + } +} diff --git a/src/test/scala/gwent/PlayerTest.scala b/src/test/scala/gwent/PlayerTest.scala new file mode 100644 index 0000000..b2615c5 --- /dev/null +++ b/src/test/scala/gwent/PlayerTest.scala @@ -0,0 +1,77 @@ +package cl.uchile.dcc +package gwent + +import munit.FunSuite +import gwent.card.* + +import scala.collection.mutable.ListBuffer + +class PlayerTest extends FunSuite { + var Player1: Player = _ + var Player2: Player = _ + val name1: String = "Geralt" + val name2: String = "Roach" + val climateCard: ICard = new ClimateCard("cartita",null) + val siegeCard: ICard = new SiegeUnitCard("cartota","null",5) + val meleeCard1: ICard = new MeleeUnitCard("Juan","null",3) + val meleeCard2: ICard = new MeleeUnitCard("Geralt","null",4) + val rangeCard: ICard = new RangeUnitCard("Daff", null,2) + val deck: ListBuffer[ICard] = ListBuffer(climateCard,meleeCard1,meleeCard2,rangeCard,siegeCard) + override def beforeEach(context: BeforeEach): Unit = { + Player1 = new Player(name1,deck) + Player2 = new Player(name2,deck) + } + + test("Players have names"){ + assertEquals(Player1.getName,name1) + assertEquals(Player2.getName, name2) + assertNotEquals(Player1.getName, Player2.getName) + } + + test("Players have gems"){ + assertEquals(Player1.getGems,2) + assertEquals(Player2.getGems, Player2.getGems) + } + test("Players can lose gems"){ + assertEquals(Player1.getGems,2) + assert(Player1.setGems(1)) + assertEquals(Player1.getGems,1) + assert(Player2.setGems(2)) + assertEquals(Player2.getGems,0) + assert(!Player2.setGems(1)) + } + test("Player can be compared"){ + assert(Player1.equals(Player1)) + val Player3: IPlayer = new Player(name1,deck) + assert(Player1.equals(Player3)) + assert(Player3.equals(Player1)) + assert(!Player2.equals(Player1)) + assert(!Player1.equals(climateCard)) + } + test("Decks can be shuffled"){ + assertEquals(Player1.getDeck, deck) + assert(Player1.shuffleDeck) + } + test("Players can draw cards"){ + assert(Player1.deck.nonEmpty) + assert(Player2.deck.nonEmpty) + assert(Player1.drawCards())//1 + assert(Player1.drawCards())//2 + assert(Player1.drawCards())//3 + assert(Player1.drawCards())//4 + assert(Player1.drawCards())//5 + //No quedan cartas + assert(!Player1.drawCards()) + } + test("Players can play cards from their hands") { + //No tiene cartas en mano + assert(!Player1.playCard(climateCard)) + //obtnemos carta y la jugamos + Player1.drawCards() + // + assert(Player1.getHand.nonEmpty) + assert(Player1.playCard(climateCard)) + //nuevamente no tenemos carta + assert(!Player1.playCard(climateCard)) + } +} diff --git a/src/test/scala/gwent/card/ClimateCardTest.scala b/src/test/scala/gwent/card/ClimateCardTest.scala new file mode 100644 index 0000000..8d53ecb --- /dev/null +++ b/src/test/scala/gwent/card/ClimateCardTest.scala @@ -0,0 +1,42 @@ +package cl.uchile.dcc +package gwent.card + +import munit.FunSuite + +class ClimateCardTest extends FunSuite{ + var card1: ICard = _ + var card2: ICard = _ + val name1: String = "Lluvia Torrencial" + val effect1: String = "Rain" + val name2: String = "Clima Despejado" + val effect2: String = "None" + + override def beforeEach(context: BeforeEach): Unit = { + card1 = new ClimateCard(name1,effect1) + card2 = new ClimateCard(name2,effect2) + } + + test("Cards have names"){ + assertEquals(card1.getName,name1) + assertEquals(card2.getName,name2) + assertNotEquals(card1.getEffect,card2.getName) + } + test("Card have effects"){ + assertEquals(card1.getEffect,effect1) + assertEquals(card2.getEffect,effect2) + assertNotEquals(card1.getEffect,card2.getEffect) + } + test("Cards can be compared"){ + val card3: ICard = new ClimateCard(name1,effect1) + assert(card1.equals(card3)) + assert(card1.equals(card1)) + assert(!card1.equals(card2)) + val card4: ICard = new RangeUnitCard(name1, effect1, 3) + val card5: ICard = new SiegeUnitCard(name2, effect2, 3) + val card6: ICard = new MeleeUnitCard(name1,effect2,3) + //compared to different card class + assert(!card1.equals(card4)) + assert(!card1.equals(card5)) + assert(!card1.equals(card6)) + } +} diff --git a/src/test/scala/gwent/card/MeleeUnitCardTest.scala b/src/test/scala/gwent/card/MeleeUnitCardTest.scala new file mode 100644 index 0000000..1f76038 --- /dev/null +++ b/src/test/scala/gwent/card/MeleeUnitCardTest.scala @@ -0,0 +1,54 @@ +package cl.uchile.dcc +package gwent.card + +import munit.Clue.generate +import munit.FunSuite + +class MeleeUnitCardTest extends FunSuite{ + var card1: AbstractUnitCard = _ + var card2: AbstractUnitCard = _ + val name1: String = "Geralt" + val name2: String = "Roach" + val effect1: String = "a" + val effect2: String = "b" + val power1: Int = 5 + val power2: Int = 2 + + override def beforeEach(context: BeforeEach): Unit = { + card1 = new MeleeUnitCard(name1,effect1,power1) + card2 = new MeleeUnitCard(name2,effect2,power2) + } + + test("Cards have names") { + assertEquals(card1.getName, name1) + assertEquals(card2.getName, name2) + assertNotEquals(card1.getEffect, card2.getName) + } + test("Card have effects") { + assertEquals(card1.getEffect, effect1) + assertEquals(card2.getEffect, effect2) + assertNotEquals(card1.getEffect, card2.getEffect) + } + test("Melee Cards have power"){ + assertEquals(card1.power(), power1) + assertEquals(card2.getPower,power2) + assertNotEquals(card1.getPower,card2.getPower) + } + test("Cards can be compared") { + val card3: ICard = new MeleeUnitCard(name1,effect1,power1) + //compared to itself + assert(card1.equals(card1)) + //compared to an identical card + assert(card1.equals(card3)) + //compared to a different card + assert(!card1.equals(card2)) + val card4: ICard = new RangeUnitCard(name1,effect1,power1) + val card5: ICard = new SiegeUnitCard(name2,effect2,power2) + //compared to different class with same params + assert(!card1.equals(card4)) + //compared to different class with diff params + assert(!card1.equals(card5)) + val card6: ICard = new ClimateCard(name1,effect1) + assert(!card1.equals(card6)) + } +} diff --git a/src/test/scala/gwent/card/RangeUnitCardTest.scala b/src/test/scala/gwent/card/RangeUnitCardTest.scala new file mode 100644 index 0000000..55cae57 --- /dev/null +++ b/src/test/scala/gwent/card/RangeUnitCardTest.scala @@ -0,0 +1,53 @@ +package cl.uchile.dcc +package gwent.card + +import munit.FunSuite + +class RangeUnitCardTest extends FunSuite{ + var card1: AbstractUnitCard = _ + var card2: AbstractUnitCard = _ + val name1: String = "Geralt" + val name2: String = "Roach" + val effect1: String = "a" + val effect2: String = "b" + val power1: Int = 5 + val power2: Int = 2 + + override def beforeEach(context: BeforeEach): Unit = { + card1 = new RangeUnitCard(name1, effect1, power1) + card2 = new RangeUnitCard(name2, effect2, power2) + } + + test("Cards have names") { + assertEquals(card1.getName, name1) + assertEquals(card2.getName, name2) + assertNotEquals(card1.getEffect, card2.getName) + } + test("Card have effects") { + assertEquals(card1.getEffect, effect1) + assertEquals(card2.getEffect, effect2) + assertNotEquals(card1.getEffect, card2.getEffect) + } + test("Range Cards have power") { + assertEquals(card1.getPower, power1) + assertEquals(card2.getPower, power2) + assertNotEquals(card1.getPower, card2.getPower) + } + test("Cards can be compared") { + val card3: ICard = new RangeUnitCard(name1, effect1, power1) + //compared to itself + assert(card1.equals(card1)) + //compared to an identical card + assert(card1.equals(card3)) + //compared to a different card + assert(!card1.equals(card2)) + val card4: ICard = new MeleeUnitCard(name1, effect1, power1) + val card5: ICard = new SiegeUnitCard(name2, effect2, power2) + //compared to different class with same params + assert(!card1.equals(card4)) + //compared to different class with diff params + assert(!card1.equals(card5)) + val card6: ICard = new ClimateCard(name1, effect1) + assert(!card1.equals(card6)) + } +} diff --git a/src/test/scala/gwent/card/SiegeUnitCardTest.scala b/src/test/scala/gwent/card/SiegeUnitCardTest.scala new file mode 100644 index 0000000..043849a --- /dev/null +++ b/src/test/scala/gwent/card/SiegeUnitCardTest.scala @@ -0,0 +1,53 @@ +package cl.uchile.dcc +package gwent.card + +import munit.FunSuite + +class SiegeUnitCardTest extends FunSuite{ + var card1: AbstractUnitCard = _ + var card2: AbstractUnitCard = _ + val name1: String = "Geralt" + val name2: String = "Roach" + val effect1: String = "a" + val effect2: String = "b" + val power1: Int = 5 + val power2: Int = 2 + + override def beforeEach(context: BeforeEach): Unit = { + card1 = new SiegeUnitCard(name1, effect1, power1) + card2 = new SiegeUnitCard(name2, effect2, power2) + } + + test("Cards have names") { + assertEquals(card1.getName, name1) + assertEquals(card2.getName, name2) + assertNotEquals(card1.getEffect, card2.getName) + } + test("Card have effects") { + assertEquals(card1.getEffect, effect1) + assertEquals(card2.getEffect, effect2) + assertNotEquals(card1.getEffect, card2.getEffect) + } + test("Siege Cards have power") { + assertEquals(card1.getPower, power1) + assertEquals(card2.getPower, power2) + assertNotEquals(card1.getPower, card2.getPower) + } + test("Cards can be compared") { + val card3: ICard = new SiegeUnitCard(name1, effect1, power1) + //compared to itself + assert(card1.equals(card1)) + //compared to an identical card + assert(card1.equals(card3)) + //compared to a different card + assert(!card1.equals(card2)) + val card4: ICard = new RangeUnitCard(name1, effect1, power1) + val card5: ICard = new MeleeUnitCard(name2, effect2, power2) + //compared to different class with same params + assert(!card1.equals(card4)) + //compared to different class with diff params + assert(!card1.equals(card5)) + val card6: ICard = new ClimateCard(name1, effect1) + assert(!card1.equals(card6)) + } +}