Changed Delays added FirstCard
Some checks failed
Build and Test (KnockOutWhist) TeamCity build failed

This commit is contained in:
2024-12-13 11:31:03 +01:00
parent f7b09a0bd9
commit 56cc2f1182
6 changed files with 155 additions and 87 deletions

View File

@@ -56,7 +56,7 @@ object MainLogic {
val finalRound = Round(round.trumpSuit, round.tricklist, round.playersin, playersOut, round.startingPlayer, winner, firstRound = round.firstRound)
val newMatch = matchImpl.addRound(finalRound)
ControlHandler.invoke(ShowRoundStatus(WON_ROUND, finalRound, winner))
ControlHandler.invoke(DelayEvent(5000L))
ControlHandler.invoke(DelayEvent(1000L))
if (finalRound.playersout.nonEmpty) {
ControlHandler.invoke(ShowRoundStatus(PLAYERS_OUT, finalRound))
}
@@ -71,10 +71,9 @@ object MainLogic {
}else {
val result = TrickLogic.wonTrick(trick, round)
val newRound = round.addTrick(result._2)
//ControlHandler.invoke(ShowCurrentTrickEvent(newRound, result._2))
ControlHandler.invoke(ShowPlayerStatus(SHOW_WON_PLAYER_TRICK, result._1))
ControlHandler.invoke(ShowPlayerStatus(SHOW_WON_PLAYER_TRICK, result._1, result._2))
newRound.playerQueue.resetAndSetStart(result._1)
ControlHandler.invoke(DelayEvent(3000L))
ControlHandler.invoke(DelayEvent(1000L))
controlRound(matchImpl, newRound)
}
}

View File

@@ -21,7 +21,7 @@ object PlayerControl {
def playCard(matchImpl: Match, player: AbstractPlayer, round: Round, trick: Trick, currentIndex: Int): Unit = {
ControlHandler.invoke(ShowPlayerStatus(SHOW_TURN, player))
ControlHandler.invoke(DelayEvent(3000L))
ControlHandler.invoke(DelayEvent(500))
ControlHandler.invoke(ShowPlayerStatus(SHOW_PLAY_CARD, player))
ControlHandler.invoke(RenderHandEvent(player.currentHand().get, true))
player.handlePlayCard(player.currentHand().get, matchImpl, round, trick, currentIndex)
@@ -29,7 +29,7 @@ object PlayerControl {
def dogplayCard(matchImpl: Match, player: AbstractPlayer, round: Round, trick: Trick, currentIndex: Int): Unit = {
ControlHandler.invoke(ShowPlayerStatus(SHOW_TURN, player))
ControlHandler.invoke(DelayEvent(3000L))
ControlHandler.invoke(DelayEvent(500))
ControlHandler.invoke(ShowPlayerStatus(SHOW_DOG_PLAY_CARD, player, RoundLogic.dogNeedsToPlay(round)))
ControlHandler.invoke(RenderHandEvent(player.currentHand().get, false))
player.handleDogPlayCard(player.currentHand().get, matchImpl, round, trick, currentIndex, RoundLogic.dogNeedsToPlay(round))

View File

@@ -54,6 +54,9 @@ object TrickLogic {
val alternatives: List[Card] = for cardInHand <- player.currentHand().get.cards
if cardInHand.suit == firstCard.suit
yield cardInHand
if(round.trumpSuit == card.suit && alternatives.isEmpty) {
return Nil
}
if (alternatives.nonEmpty) {
return alternatives
}

View File

@@ -54,6 +54,9 @@ object GUIMain extends JFXApp3 with EventListener with UI {
case _ =>
case event: RequestCardEvent =>
Game.requestCard = Some(event)
Game.updateTrumpSuit(event.round.trumpSuit)
if(event.trick.firstCard.isDefined) Game.updateFirstCard(event.trick.firstCard.get)
else Game.resetFirstCard()
case event: RequestPickTrumpsuitEvent =>
PickTrumsuit.showPickTrumpsuit(event)
case event: SimpleEvent =>

View File

@@ -1,7 +1,7 @@
package de.knockoutwhist.ui.gui
import atlantafx.base.theme.Styles
import de.knockoutwhist.cards.{Card, Hand}
import de.knockoutwhist.cards.{Card, Hand, Suit}
import de.knockoutwhist.control.{ControlHandler, ControlThread, TrickLogic}
import de.knockoutwhist.events.directional.RequestCardEvent
import de.knockoutwhist.player.Playertype.HUMAN
@@ -12,13 +12,14 @@ import de.knockoutwhist.undo.commands.EnterPlayersCommand
import de.knockoutwhist.utils.gui.Animations
import scalafx.beans.property.ObjectProperty
import scalafx.geometry.Insets
import scalafx.geometry.Pos.{BottomCenter, BottomLeft, Center, TopCenter, TopLeft}
import scalafx.scene.Node
import scalafx.geometry.Pos.{BottomCenter, BottomLeft, Center, CenterLeft, CenterRight, TopCenter, TopLeft, TopRight}
import scalafx.scene.{Node, layout}
import scalafx.scene.control.{Button, Label}
import scalafx.scene.image.{Image, ImageView}
import scalafx.scene.layout.Priority.Always
import scalafx.scene.layout.{HBox, StackPane, VBox}
import scalafx.scene.text.Font
import scalafx.scene.layout.Priority.{Always, Never}
import scalafx.scene.layout.{Background, BorderPane, HBox, StackPane, VBox}
import scalafx.scene.paint.{Color, Paint}
import scalafx.scene.text.{Font, TextAlignment}
import scalafx.util.Duration
import scala.collection.mutable
@@ -30,97 +31,137 @@ import scala.util.Try
object Game {
private val statusLabel: Label = new Label {
alignment = TopCenter
alignment = Center
textAlignment = TextAlignment.Center
text = "It's {Player?}s turn:"
font = Font.font(35)
hgrow = Always
maxWidth = Double.MaxValue
}
private val suitLabel: Label = new Label {
alignment = Center
textAlignment = TextAlignment.Left
minWidth = 300
maxWidth = 300
text = "TrumpSuit: "
font = Font.font(18)
hgrow = Always
}
private val nextPlayers: HBox = new HBox {
alignment = TopLeft
alignment = TopCenter
minWidth = 300
maxWidth = 300
margin = Insets(30, 0, 0, 20)
children = Seq(
new Label {
alignment = TopLeft
text = "Next Players turn:"
font = Font.font(20)
margin = Insets(30, 0, 0, 20)
}
)
}
private val firstCard: ImageView = new ImageView {
alignmentInParent = BottomCenter
image = new Image("cards/1B.png")
fitWidth = 170
fitHeight = 250
onMouseClicked = _ => System.exit(0)
}
private val playedCards: HBox = new HBox {
alignment = BottomCenter
spacing = 10
margin = Insets(0, 0, 20, 0)
children = Seq(
new ImageView {
alignment = BottomCenter
image = new Image("cards/TH.png")
fitWidth = 102
fitHeight = 150
onMouseClicked = _ => System.exit(0)
},
)
}
private val playerCards: HBox = new HBox {
alignment = BottomCenter
spacing = 10
margin = Insets(30, 0, 20, 0)
children = Seq(
new ImageView {
alignment = BottomCenter
image = new Image("cards/3H.png")
fitWidth = 170
fitHeight = 250
onMouseClicked = _ => {
val slideOut = Animations.slideOutUp(children.head.asInstanceOf[javafx.scene.image.ImageView], Duration(400), -350)
slideOut.onFinished = _ => {
visible = false
}
slideOut.play()
}
},
new ImageView {
alignment = BottomCenter
image = new Image("cards/4C.png")
fitWidth = 170
fitHeight = 250
onMouseClicked = _ => System.exit(0)
},
)
}
def createGame(): Unit = {
MainMenu.changeChild(new StackPane {
children = Seq(
new VBox {
alignment = TopCenter
spacing = 10
margin = Insets(20, 0, 0, 0)
hgrow = Always
children = Seq(
statusLabel,
nextPlayers,
new Label {
alignment = Center
text = "Played Cards"
vgrow = Always
font = Font.font(20)
margin = Insets(50,0,0,0)
},
playedCards,
new Label {
alignment = Center
text = "Your Cards:"
font = Font.font(20)
margin = Insets(35,0,0,0)
},
playerCards,
)
}
)
MainMenu.changeChild(new BorderPane {
padding = Insets(10, 10, 10, 10)
top = new HBox {
alignment = Center
hgrow = Always
spacing = 0
children = Seq(
suitLabel,
statusLabel,
new HBox {
hgrow = Always
alignment = CenterRight
spacing = 10
minWidth = 300
maxWidth = 300
children = Seq(
new Button {
hgrow = Never
alignment = CenterRight
text = "Undo"
font = Font.font(20)
styleClass += Styles.WARNING
onMouseClicked = _ => {
UndoManager.undoStep()
}
},
new Button {
hgrow = Never
alignment = CenterRight
text = "Exit Game"
font = Font.font(20)
styleClass += Styles.DANGER
onMouseClicked = _ => System.exit(0)
}
)
},
)
}
center = new VBox {
alignment = TopCenter
children = Seq(
new Label {
alignment = Center
text = "Played Cards"
vgrow = Always
font = Font.font(20)
},
playedCards,
)
}
left = nextPlayers
right = new VBox {
alignment = Center
minWidth = 300
maxWidth = 300
children = Seq(
new Label {
alignment = Center
textAlignment = TextAlignment.Center
text = "First Card: "
vgrow = Always
font = Font.font(24)
},
firstCard
)
}
bottom = new VBox {
alignment = BottomCenter
children = Seq(
new Label {
alignment = Center
text = "Your Cards"
vgrow = Always
font = Font.font(20)
margin = Insets(50,0,0,0)
},
playerCards,
)
}
})
}
@@ -128,10 +169,27 @@ object Game {
statusLabel.text = s"It's ${player.name}s turn:"
}
def updateTrumpSuit(suit: Suit): Unit = {
suitLabel.text = s"TrumpSuit: $suit"
}
def visibilityPlayerCards(visible: Boolean): Unit = {
playerCards.visible = visible
}
def firstCardvisible(visible: Boolean): Unit = {
firstCard.visible = visible
}
def updateFirstCard(card: Card): Unit = {
firstCardvisible(true)
firstCard.image = CardUtils.cardtoImage(card)
}
def resetFirstCard(): Unit = {
firstCard.image = new Image("cards/1B.png")
}
def updatePlayerCards(hand: Hand): Unit = {
val cards = ListBuffer[Node]()
for (card <- hand.cards) {
@@ -142,18 +200,24 @@ object Game {
fitHeight = 250
onMouseClicked = _ => {
if(requestCard.isDefined) {
val event = requestCard.get
val slideOut = Animations.slideOutUp(this, Duration(400), -350)
slideOut.onFinished = _ => {
visible = false
ControlThread.runLater {
TrickLogic.controlSuitplayed(Try {
card
}, event.matchImpl, event.round, event.trick, event.currentIndex, event.player)
if (TrickLogic.alternativeCards(card, event.round, event.trick, event.player).nonEmpty) {
val pulse = Animations.pulse(this, Duration(400))
pulse.play()
} else {
val slideOut = Animations.slideOutUp(this, Duration(400), -350)
slideOut.onFinished = _ => {
visible = false
ControlThread.runLater {
TrickLogic.controlSuitplayed(Try {
card
}, event.matchImpl, event.round, event.trick, event.currentIndex, event.player)
}
requestCard = None
}
requestCard = None
slideOut.play()
}
slideOut.play()
}
}
}

View File

@@ -11,8 +11,7 @@ object DelayHandler extends EventListener {
event match {
case event: DelayEvent =>
if(activateDelay) Thread.sleep(event.delay)
Some(true)
case _ => None
case _ =>
}
}
}