Added CardManager
Build and Test (KnockOutWhist) TeamCity build failed

This commit is contained in:
2024-10-18 11:25:11 +02:00
parent 3c163e01f8
commit 7f0b85ea84
7 changed files with 151 additions and 63 deletions
@@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="sbt: org.scala-lang:scala-library:2.13.15:jar" external-system-id="SBT">
<CLASSES>
<root url="jar://$USER_HOME$/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.15/scala-library-2.13.15.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.15/scala-library-2.13.15-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.15/scala-library-2.13.15-sources.jar!/" />
</SOURCES>
</library>
</component>
-18
View File
@@ -1,18 +0,0 @@
<component name="libraryTable">
<library name="sbt: scala-sdk-2.13.15" type="Scala">
<properties>
<compiler-classpath>
<root url="file://$USER_HOME$/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.15/scala-library-2.13.15.jar" />
<root url="file://$USER_HOME$/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/java-diff-utils/java-diff-utils/4.12/java-diff-utils-4.12.jar" />
<root url="file://$USER_HOME$/.cache/coursier/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.14.0/jna-5.14.0.jar" />
<root url="file://$USER_HOME$/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline/3.26.3/jline-3.26.3.jar" />
<root url="file://$USER_HOME$/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.15/scala-compiler-2.13.15.jar" />
<root url="file://$USER_HOME$/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.13.15/scala-reflect-2.13.15.jar" />
</compiler-classpath>
<compiler-bridge-binary-jar>file://$USER_HOME$/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala2-sbt-bridge/2.13.15/scala2-sbt-bridge-2.13.15.jar</compiler-bridge-binary-jar>
</properties>
<CLASSES />
<JAVADOC />
<SOURCES />
</library>
</component>
+5 -1
View File
@@ -1,3 +1,5 @@
import de.knockoutwhist.cards.CardManager
val eol = sys.props("line.separator") // String =
def bar(cellwidth: Int = 3, cellNum: Int = 3) = (("+" + "-" * cellwidth)*cellNum) + "+" + eol
def cells(cellwidth: Int = 3, cellNum: Int = 3) = ("|" + " " * cellwidth) *cellNum + "|" + eol
@@ -5,4 +7,6 @@ def mesh(cellwidth: Int = 3, cellNum: Int = 3) = (bar(cellwidth, cellNum) + cell
bar(8,6)
cells()
mesh()
mesh()
CardManager.cardContainer
@@ -1,30 +1,34 @@
package de.knockoutwhist
object Main {
import de.knockoutwhist.cards.CardManager
object KnockOutWhist {
class KnockOutWhist {
}
val eol = sys.props("line.separator")
val eol: String = sys.props("line.separator")
def bar(cellWidth: Int = 9, cellNum: Int = 1) =
def bar(cellWidth: Int = 9, cellNum: Int = 1): String =
("-" * cellWidth) * cellNum
def cells(cellWidth: Int = 7, cellNum: Int = 1) =
def cells(cellWidth: Int = 7, cellNum: Int = 1): String =
("|" + " " * cellWidth) * cellNum + "|"
def meshk =
def meshk: String =
bar() + cells() + eol + "|Karten | " + eol + (cells()+ eol) * 2 + bar() + eol
def mesha =
def mesha: String =
bar() + cells() + eol + "|Ablage | " + eol + (cells()+ eol) * 2 + bar() + eol
def mesht1 =
private def mesht1 =
bar() + eol + cells() + eol + "|Trumpfe| " + eol + "|s1 |\n" + cells() + eol + bar() + eol
def mesht2 =
private def mesht2 =
bar() + eol + cells() + eol + "|Trumpfe|" + eol + "|s2 |\n" + cells() + eol + bar() + eol
def meshTable = {
private def meshTable = {
bar() + "\t" + bar() + eol + cells() + "\t" + cells() + eol +
"|Karten |" + "\t" + "|Ablage |" + eol + (cells() + "\t" + cells() + eol) * 2 +
bar() + "\t" + bar() + eol
@@ -36,5 +40,7 @@ object Main {
print(meshTable)
print(mesht1)
print(mesht2)
}
}
@@ -1,31 +1,29 @@
package de.knockoutwhist.cards
enum Suit:
case Spades
case Hearts
case Diamonds
case Clubs
enum Suit(identifier: String):
case Spades extends Suit("")
case Hearts extends Suit("")
case Diamonds extends Suit("")
case Clubs extends Suit("")
end Suit
enum CardValue:
case Two
case Three
case Four
case Five
case Six
case Seven
case Eight
case Nine
case Ten
case Jack
case Queen
case King
case Ace
enum CardValue(identifier: String):
case Two extends CardValue("2")
case Three extends CardValue("3")
case Four extends CardValue("4")
case Five extends CardValue("5")
case Six extends CardValue("6")
case Seven extends CardValue("7")
case Eight extends CardValue("8")
case Nine extends CardValue("9")
case Ten extends CardValue("10")
case Jack extends CardValue("J")
case Queen extends CardValue("Q")
case King extends CardValue("K")
case Ace extends CardValue("A")
end CardValue
case class Card(cardValue: CardValue, suit: Suit) {
override def toString: String = s"$cardValue of $suit"
}
@@ -0,0 +1,34 @@
package de.knockoutwhist.cards
import scala.util.Random
object CardManager {
val cardContainer: Array[Card] = {
val cc = new Array[Card](52)
var i = 0
for (suit <- Suit.values) {
for (cardValue <- CardValue.values) {
cc(i) = Card(cardValue, suit)
i+=1
}
}
cc
}
private var currentIdx = 0
def shuffleAndReset(): Unit = {
Random.shuffle(cardContainer)
currentIdx = 0
}
def nextCard(): Card = {
val card = cardContainer(currentIdx)
currentIdx += 1
card
}
}
@@ -0,0 +1,77 @@
package de.knockoutwhist.cards
import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpec
class CardTests extends AnyWordSpec with Matchers{
"Knock Out Whist" should {
"The card container can't be empty" in {
CardManager.cardContainer must not be empty
}
"A deck should have 52 cards" in {
CardManager.cardContainer must have size 52
}
"A deck should have 13 cards of each suit" in {
"13 cards of Spades" in {
CardManager.cardContainer.count(_.suit == Suit.Spades) mustBe 13
}
"13 cards of Hearts" in {
CardManager.cardContainer.count(_.suit == Suit.Hearts) mustBe 13
}
"13 cards of Diamonds" in {
CardManager.cardContainer.count(_.suit == Suit.Diamonds) mustBe 13
}
"13 cards of Clubs" in {
CardManager.cardContainer.count(_.suit == Suit.Clubs) mustBe 13
}
}
"A deck should have 4 cards of each value" in {
"4 cards of Two" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Two) mustBe 4
}
"4 cards of Three" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Three) mustBe 4
}
"4 cards of Four" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Four) mustBe 4
}
"4 cards of Five" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Five) mustBe 4
}
"4 cards of Six" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Six) mustBe 4
}
"4 cards of Seven" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Seven) mustBe 4
}
"4 cards of Eight" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Eight) mustBe 4
}
"4 cards of Nine" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Nine) mustBe 4
}
"4 cards of Ten" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Ten) mustBe 4
}
"4 cards of Jack" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Jack) mustBe 4
}
"4 cards of Queen" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Queen) mustBe 4
}
"4 cards of King" in {
CardManager.cardContainer.count(_.cardValue == CardValue.King) mustBe 4
}
"4 cards of Ace" in {
CardManager.cardContainer.count(_.cardValue == CardValue.Ace) mustBe 4
}
}
"Check if shuffleAndReset shuffles the deck" in {
val originalDeck = CardManager.cardContainer.clone()
CardManager.shuffleAndReset()
CardManager.cardContainer must not equal originalDeck
}
}
}