Compare commits

..

5 Commits

Author SHA1 Message Date
TeamCity
8e511d2a11 ci: bump version to v1.1.0 2025-11-14 10:38:15 +00:00
e60fe7c98d feat(ci): Polling Added polling for when the game starts and a card gets played (#58)
Co-authored-by: LQ63 <lkhermann@web.de>
Reviewed-on: #58
2025-11-14 09:11:32 +01:00
370de175db feat(ci): Polling
Co-authored-by: LQ63 <lkhermann@web.de>
Reviewed-on: #53
2025-11-13 11:07:08 +01:00
5d245d0011 feat(ui): implement tie & trump menu, fixed some critical bugs (#52)
Co-authored-by: LQ63 <lkhermann@web.de>
Reviewed-on: #52
Co-authored-by: Janis <janis.e.20@gmx.de>
Co-committed-by: Janis <janis.e.20@gmx.de>
2025-11-13 08:20:30 +01:00
c220e54bb8 feat(ui): added js routing, updated ingame ui, added tricktable (#50)
This merge request has full JS routing for calling specific endpoints. Game is fully playable but doesn't have polling yet. This version already has the UI changes adressed in MR #43 so first merge MR #43 and then this one or only merge this one because it already has the UI changes :)

Co-authored-by: LQ63 <lkhermann@web.de>
Reviewed-on: #50
Reviewed-by: Janis <janis-e@gmx.de>
2025-11-12 11:44:21 +01:00
20 changed files with 665 additions and 304 deletions

View File

@@ -111,3 +111,11 @@
* removed trailing ([c7dd72e](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/c7dd72ecc2786ef63daf2b4288093025a8e22bfd)) * removed trailing ([c7dd72e](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/c7dd72ecc2786ef63daf2b4288093025a8e22bfd))
* removed trailing ([42a5adb](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/42a5adbae01802587a48a9de15bad44b5ef014cf)) * removed trailing ([42a5adb](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/42a5adbae01802587a48a9de15bad44b5ef014cf))
## (2025-11-14)
### Features
* **ci:** Polling ([370de17](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/370de175db65edf87e7ab211190977b540a39d85))
* **ci:** Polling Added polling for when the game starts and a card gets played ([#58](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/58)) ([e60fe7c](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/e60fe7c98dcab05949140a8a54ed6e4e2fbbc022))
* **ui:** added js routing, updated ingame ui, added tricktable ([#50](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/50)) ([c220e54](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/c220e54bb8d87f4f0f37a089bcd993e8df806123)), closes [#43](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/43) [#43](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/43)
* **ui:** implement tie & trump menu, fixed some critical bugs ([#52](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/issues/52)) ([5d245d0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/5d245d0011a5fb03193514303b45702cd8329224))

View File

@@ -25,6 +25,8 @@
.game-field-background { .game-field-background {
background-image: @background-image; background-image: @background-image;
background-repeat: no-repeat;
background-size: cover;
max-width: 1400px; max-width: 1400px;
margin: 0 auto; margin: 0 auto;
min-height: 100vh; min-height: 100vh;
@@ -79,6 +81,14 @@ body {
overflow: auto; overflow: auto;
} }
.navbar-drop-shadow {
box-shadow: 0 1px 15px 0 #000000
}
.ingame-side-shadow {
box-shadow: 0 1px 15px 0 #000000
}
#sessions { #sessions {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -113,45 +123,21 @@ body {
font-size: 40px; font-size: 40px;
font-family: Arial, serif; font-family: Arial, serif;
} }
#playercards {
display: flex;
flex-direction: row;
justify-content: center;
height: 20%;
img {
animation: slideIn 0.5s ease-out forwards;
animation-fill-mode: backwards;
&:nth-child(1) { animation-delay: 0.5s; }
&:nth-child(2) { animation-delay: 1s; }
&:nth-child(3) { animation-delay: 1.5s; }
&:nth-child(4) { animation-delay: 2s; }
&:nth-child(5) { animation-delay: 2.5s; }
&:nth-child(6) { animation-delay: 3s; }
&:nth-child(7) { animation-delay: 3.5s; }
}
}
#card-slide {
div {
animation: slideIn 0.5s ease-out forwards;
animation-fill-mode: backwards;
&:nth-child(1) { animation-delay: 0.5s; }
&:nth-child(2) { animation-delay: 1s; }
&:nth-child(3) { animation-delay: 1.5s; }
&:nth-child(4) { animation-delay: 2s; }
&:nth-child(5) { animation-delay: 2.5s; }
&:nth-child(6) { animation-delay: 3s; }
&:nth-child(7) { animation-delay: 3.5s; }
}
.ingame-cards-slide {
div {
animation: slideIn 0.5s ease-out forwards;
animation-fill-mode: backwards;
&:nth-child(1) { animation-delay: 0.5s; }
&:nth-child(2) { animation-delay: 1s; }
&:nth-child(3) { animation-delay: 1.5s; }
&:nth-child(4) { animation-delay: 2s; }
&:nth-child(5) { animation-delay: 2.5s; }
&:nth-child(6) { animation-delay: 3s; }
&:nth-child(7) { animation-delay: 3.5s; }
}
} }
#cardsplayed {
display: flex;
flex-direction: row;
height: 10%;
min-height: 10%
}
#playedcardplayer { #playedcardplayer {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -225,3 +211,35 @@ body {
.score-row { .score-row {
color: #000000; color: #000000;
} }
/* In-game centered stage and blurred sides overlay */
.ingame-stage {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 2rem 1rem;
}
/* Wrapper that adds a backdrop blur to the background outside the centered card */
.blur-sides {
position: relative;
}
/* Create an overlay that blurs everything behind it, except the central content area */
.blur-sides::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
/* fallback: subtle vignette if backdrop-filter unsupported */
background: radial-gradient(ellipse at center, rgba(0,0,0,0) 30%, rgba(0,0,0,0.35) 100%);
}
@supports ((-webkit-backdrop-filter: blur(8px)) or (backdrop-filter: blur(8px))) {
.blur-sides::before {
background: rgba(0,0,0,0.08);
-webkit-backdrop-filter: blur(10px) saturate(110%);
backdrop-filter: blur(10px) saturate(110%);
}
}

View File

@@ -1,25 +1,20 @@
package controllers package controllers
import auth.{AuthAction, AuthenticatedRequest} import auth.{AuthAction, AuthenticatedRequest}
import de.knockoutwhist.cards.Hand
import de.knockoutwhist.control.GameState.{InGame, Lobby, SelectTrump, TieBreak} import de.knockoutwhist.control.GameState.{InGame, Lobby, SelectTrump, TieBreak}
import exceptions.{CantPlayCardException, GameFullException, NotEnoughPlayersException, NotHostException, NotInThisGameException} import exceptions.*
import logic.PodManager import logic.PodManager
import logic.game.PollingEvents.CardPlayed import logic.game.GameLobby
import logic.game.PollingEvents.GameStarted import model.sessions.UserSession
import logic.game.{GameLobby, PollingEvents}
import model.sessions.{PlayerSession, UserSession}
import model.users.User
import play.api.* import play.api.*
import play.api.libs.json.{JsArray, JsValue, Json} import play.api.libs.json.{JsValue, Json}
import play.api.mvc.* import play.api.mvc.*
import util.WebUIUtils
import java.util.UUID import java.util.UUID
import javax.inject.* import javax.inject.*
import scala.concurrent.Future
import scala.util.Try
import scala.concurrent.ExecutionContext import scala.concurrent.ExecutionContext
import scala.util.Try
@Singleton @Singleton
class IngameController @Inject() ( class IngameController @Inject() (
val cc: ControllerComponents, val cc: ControllerComponents,
@@ -27,95 +22,6 @@ class IngameController @Inject() (
val authAction: AuthAction, val authAction: AuthAction,
implicit val ec: ExecutionContext implicit val ec: ExecutionContext
) extends AbstractController(cc) { ) extends AbstractController(cc) {
// --- Helper function (defined outside match/if for scope) ---
def buildSuccessResponse(game: GameLobby, hand: Option[Hand]): JsValue = {
// NOTE: Replace the unsafe .get calls here if game state is not guaranteed
val currentRound = game.logic.getCurrentRound.get
val currentTrick = game.logic.getCurrentTrick.get
// JSON Building Logic:
val trickCardsJson = Json.toJson(
currentTrick.cards.map { case (card, player) =>
Json.obj("cardId" -> WebUIUtils.cardtoString(card), "player" -> player.name)
}
)
val scoreTableJson = Json.toJson(
game.getLogic.getPlayerQueue.get.toList.map { player =>
Json.obj(
"name" -> player.name,
"tricks" -> currentRound.tricklist.count(_.winner.contains(player))
)
}
)
val stringHand = hand.map { h =>
val cardStrings = h.cards.map(WebUIUtils.cardtoString(_))
Json.toJson(cardStrings).as[JsArray]
}.getOrElse(Json.arr())
val firstCardId = currentTrick.firstCard.map(WebUIUtils.cardtoString).getOrElse("BLANK")
val nextPlayer = game.getLogic.getPlayerQueue.get.duplicate().nextPlayer().name
Json.obj(
"status" -> "cardPlayed",
"handData" -> stringHand,
"currentPlayerName" -> game.logic.getCurrentPlayer.get.name,
"trumpSuit" -> currentRound.trumpSuit.toString,
"trickCards" -> trickCardsJson,
"scoreTable" -> scoreTableJson,
"firstCardId" -> firstCardId,
"nextPlayer" -> nextPlayer
)
}
def handleEvent(event: PollingEvents, game: GameLobby, user: User): Result = {
event match {
case CardPlayed =>
val player = game.getPlayerByUser(user)
val hand = player.currentHand()
val jsonResponse = buildSuccessResponse(game, hand)
Ok(jsonResponse)
case GameStarted =>
val jsonResponse = Json.obj(
"status" -> "gameStart",
"redirectUrl" -> routes.IngameController.game(game.id).url
)
Ok(jsonResponse)
}
}
// --- Main Polling Action ---
def polling(gameId: String): Action[AnyContent] = authAction.async { implicit request: AuthenticatedRequest[AnyContent] =>
val playerId = request.user.id
// 1. Safely look up the game
podManager.getGame(gameId) match {
case Some(game) =>
// 2. Short-Poll Check (Check for missed events)
if (game.getPollingState.nonEmpty) {
val event = game.getPollingState.dequeue()
Future.successful(handleEvent(event, game, request.user))
} else {
val eventPromise = game.registerWaiter(playerId)
eventPromise.future.map { event =>
game.removeWaiter(playerId)
handleEvent(event, game, request.user)
}.recover {
case _: Throwable =>
game.removeWaiter(playerId)
NoContent
}
}
case None =>
// Game not found
Future.successful(NotFound("Game not found."))
}
}
def game(gameId: String): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] => def game(gameId: String): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
val game = podManager.getGame(gameId) val game = podManager.getGame(gameId)
game match { game match {
@@ -130,12 +36,12 @@ class IngameController @Inject() (
case SelectTrump => case SelectTrump =>
Ok(views.html.ingame.selecttrump( Ok(views.html.ingame.selecttrump(
g.getPlayerByUser(request.user), g.getPlayerByUser(request.user),
g.logic g
)) ))
case TieBreak => case TieBreak =>
Ok(views.html.ingame.tie( Ok(views.html.ingame.tie(
g.getPlayerByUser(request.user), g.getPlayerByUser(request.user),
g.logic g
)) ))
case _ => case _ =>
InternalServerError(s"Invalid game state for in-game view. GameId: $gameId" + s" State: ${g.logic.getCurrentState}") InternalServerError(s"Invalid game state for in-game view. GameId: $gameId" + s" State: ${g.logic.getCurrentState}")
@@ -143,7 +49,6 @@ class IngameController @Inject() (
case None => case None =>
NotFound("Game not found") NotFound("Game not found")
} }
//NotFound(s"Reached end of game method unexpectedly. GameId: $gameId")
} }
def startGame(gameId: String): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] => def startGame(gameId: String): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
val game = podManager.getGame(gameId) val game = podManager.getGame(gameId)

View File

@@ -20,7 +20,7 @@ class JavaScriptRoutingController @Inject()(
routes.javascript.IngameController.kickPlayer, routes.javascript.IngameController.kickPlayer,
routes.javascript.IngameController.leaveGame, routes.javascript.IngameController.leaveGame,
routes.javascript.IngameController.playCard, routes.javascript.IngameController.playCard,
routes.javascript.IngameController.polling routes.javascript.PollingController.polling
) )
).as("text/javascript") ).as("text/javascript")
} }

View File

@@ -0,0 +1,134 @@
package controllers
import auth.{AuthAction, AuthenticatedRequest}
import de.knockoutwhist.cards.Hand
import logic.PodManager
import logic.game.{GameLobby, PollingEvents}
import logic.game.PollingEvents.{CardPlayed, LobbyUpdate, NewRound, ReloadEvent}
import model.sessions.UserSession
import model.users.User
import play.api.libs.json.{JsArray, JsValue, Json}
import play.api.mvc.{AbstractController, Action, AnyContent, ControllerComponents, Result}
import util.WebUIUtils
import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
@Singleton
class PollingController @Inject() (
val cc: ControllerComponents,
val podManager: PodManager,
val authAction: AuthAction,
implicit val ec: ExecutionContext
) extends AbstractController(cc) {
private def buildCardPlayResponse(game: GameLobby, hand: Option[Hand], newRound: Boolean): JsValue = {
val currentRound = game.logic.getCurrentRound.get
val currentTrick = game.logic.getCurrentTrick.get
val trickCardsJson = Json.toJson(
currentTrick.cards.map { case (card, player) =>
Json.obj("cardId" -> WebUIUtils.cardtoString(card), "player" -> player.name)
}
)
val scoreTableJson = Json.toJson(
game.getLogic.getPlayerQueue.get.toList.map { player =>
Json.obj(
"name" -> player.name,
"tricks" -> currentRound.tricklist.count(_.winner.contains(player))
)
}
)
val stringHand = hand.map { h =>
val cardStrings = h.cards.map(WebUIUtils.cardtoString)
Json.toJson(cardStrings).as[JsArray]
}.getOrElse(Json.arr())
val firstCardId = currentTrick.firstCard.map(WebUIUtils.cardtoString).getOrElse("BLANK")
val nextPlayer = game.getLogic.getPlayerQueue.get.duplicate().nextPlayer().name
Json.obj(
"status" -> "cardPlayed",
"animation" -> newRound,
"handData" -> stringHand,
"currentPlayerName" -> game.logic.getCurrentPlayer.get.name,
"trumpSuit" -> currentRound.trumpSuit.toString,
"trickCards" -> trickCardsJson,
"scoreTable" -> scoreTableJson,
"firstCardId" -> firstCardId,
"nextPlayer" -> nextPlayer
)
}
private def buildLobbyUsersResponse(game: GameLobby, userSession: UserSession): JsValue = {
Json.obj(
"status" -> "lobbyUpdate",
"host" -> userSession.host,
"users" -> game.getUsers.map(u => Json.obj(
"name" -> u.name,
"id" -> u.id,
"self" -> (u.id == userSession.id)
))
)
}
def handleEvent(event: PollingEvents, game: GameLobby, userSession: UserSession): Result = {
event match {
case NewRound =>
val player = game.getPlayerByUser(userSession.user)
val hand = player.currentHand()
val jsonResponse = buildCardPlayResponse(game, hand, true)
Ok(jsonResponse)
case CardPlayed =>
val player = game.getPlayerByUser(userSession.user)
val hand = player.currentHand()
val jsonResponse = buildCardPlayResponse(game, hand, false)
Ok(jsonResponse)
case LobbyUpdate =>
Ok(buildLobbyUsersResponse(game, userSession))
case ReloadEvent =>
val jsonResponse = Json.obj(
"status" -> "reloadEvent",
"redirectUrl" -> routes.IngameController.game(game.id).url
)
Ok(jsonResponse)
}
}
// --- Main Polling Action ---
def polling(gameId: String): Action[AnyContent] = authAction.async { implicit request: AuthenticatedRequest[AnyContent] =>
val playerId = request.user.id
// 1. Safely look up the game
podManager.getGame(gameId) match {
case Some(game) =>
// 2. Short-Poll Check (Check for missed events)
if (game.getPollingState.nonEmpty) {
val event = game.getPollingState.dequeue()
Future.successful(handleEvent(event, game, game.getUserSession(playerId)))
} else {
val eventPromise = game.registerWaiter(playerId)
eventPromise.future.map { event =>
game.removeWaiter(playerId)
handleEvent(event, game, game.getUserSession(playerId))
}.recover {
case _: Throwable =>
game.removeWaiter(playerId)
NoContent
}
}
case None =>
// Game not found
Future.successful(NotFound("Game not found."))
}
}
}

View File

@@ -5,20 +5,20 @@ import de.knockoutwhist.control.GameLogic
import de.knockoutwhist.control.GameState.{InGame, Lobby, MainMenu} import de.knockoutwhist.control.GameState.{InGame, Lobby, MainMenu}
import de.knockoutwhist.control.controllerBaseImpl.sublogic.util.{MatchUtil, PlayerUtil} import de.knockoutwhist.control.controllerBaseImpl.sublogic.util.{MatchUtil, PlayerUtil}
import de.knockoutwhist.events.global.{CardPlayedEvent, GameStateChangeEvent, SessionClosed} import de.knockoutwhist.events.global.{CardPlayedEvent, GameStateChangeEvent, SessionClosed}
import de.knockoutwhist.events.player.PlayerEvent import de.knockoutwhist.events.player.{PlayerEvent, ReceivedHandEvent}
import de.knockoutwhist.player.Playertype.HUMAN import de.knockoutwhist.player.Playertype.HUMAN
import de.knockoutwhist.player.{AbstractPlayer, PlayerFactory} import de.knockoutwhist.player.{AbstractPlayer, PlayerFactory}
import de.knockoutwhist.rounds.{Match, Round, Trick} import de.knockoutwhist.rounds.{Match, Round, Trick}
import de.knockoutwhist.utils.events.{EventListener, SimpleEvent} import de.knockoutwhist.utils.events.{EventListener, SimpleEvent}
import exceptions.* import exceptions.*
import logic.game.PollingEvents.{CardPlayed, GameStarted} import logic.game.PollingEvents.{CardPlayed, LobbyUpdate, NewRound, ReloadEvent}
import model.sessions.{InteractionType, UserSession} import model.sessions.{InteractionType, UserSession}
import model.users.User import model.users.User
import java.util.UUID import java.util.UUID
import scala.collection.mutable import scala.collection.mutable
import scala.collection.mutable.ListBuffer import scala.collection.mutable.ListBuffer
import scala.concurrent.{Promise => ScalaPromise} import scala.concurrent.Promise as ScalaPromise
class GameLobby private( class GameLobby private(
val logic: GameLogic, val logic: GameLogic,
@@ -31,7 +31,7 @@ class GameLobby private(
logic.createSession() logic.createSession()
private val users: mutable.Map[UUID, UserSession] = mutable.Map() private val users: mutable.Map[UUID, UserSession] = mutable.Map()
private var pollingState: mutable.Queue[PollingEvents] = mutable.Queue() private val pollingState: mutable.Queue[PollingEvents] = mutable.Queue()
private val waitingPromises: mutable.Map[UUID, ScalaPromise[PollingEvents]] = mutable.Map() private val waitingPromises: mutable.Map[UUID, ScalaPromise[PollingEvents]] = mutable.Map()
def registerWaiter(playerId: UUID): ScalaPromise[PollingEvents] = { def registerWaiter(playerId: UUID): ScalaPromise[PollingEvents] = {
@@ -53,19 +53,17 @@ class GameLobby private(
host = false host = false
) )
users += (user.id -> userSession) users += (user.id -> userSession)
addToQueue(LobbyUpdate)
userSession userSession
} }
override def listen(event: SimpleEvent): Unit = { override def listen(event: SimpleEvent): Unit = {
event match { event match {
case event: ReceivedHandEvent =>
addToQueue(NewRound)
users.get(event.playerId).foreach(session => session.updatePlayer(event))
case event: CardPlayedEvent => case event: CardPlayedEvent =>
val newEvent = PollingEvents.CardPlayed addToQueue(CardPlayed)
if (waitingPromises.nonEmpty) {
waitingPromises.values.foreach(_.success(newEvent))
waitingPromises.clear()
} else {
pollingState.enqueue(newEvent)
}
case event: PlayerEvent => case event: PlayerEvent =>
users.get(event.playerId).foreach(session => session.updatePlayer(event)) users.get(event.playerId).foreach(session => session.updatePlayer(event))
case event: GameStateChangeEvent => case event: GameStateChangeEvent =>
@@ -73,13 +71,9 @@ class GameLobby private(
return return
} }
if (event.oldState == Lobby && event.newState == InGame) { if (event.oldState == Lobby && event.newState == InGame) {
val newEvent = PollingEvents.GameStarted addToQueue(ReloadEvent)
if (waitingPromises.nonEmpty) { }else {
waitingPromises.values.foreach(_.success(newEvent)) addToQueue(ReloadEvent)
waitingPromises.clear()
} else {
pollingState.enqueue(newEvent)
}
} }
users.values.foreach(session => session.updatePlayer(event)) users.values.foreach(session => session.updatePlayer(event))
case event: SessionClosed => case event: SessionClosed =>
@@ -89,6 +83,15 @@ class GameLobby private(
} }
} }
private def addToQueue(event: PollingEvents): Unit = {
if (waitingPromises.nonEmpty) {
waitingPromises.values.foreach(_.success(event))
waitingPromises.clear()
} else {
pollingState.enqueue(event)
}
}
/** /**
* Start the game if the user is the host. * Start the game if the user is the host.
* @param user the user who wants to start the game. * @param user the user who wants to start the game.
@@ -125,6 +128,7 @@ class GameLobby private(
throw new NotInThisGameException("You are not in this game!") throw new NotInThisGameException("You are not in this game!")
} }
users.remove(userId) users.remove(userId)
addToQueue(LobbyUpdate)
} }
/** /**
@@ -267,6 +271,10 @@ class GameLobby private(
trickOpt.get trickOpt.get
} }
def getUsers: Set[User] = {
users.values.map(d => d.user).toSet
}
} }
object GameLobby { object GameLobby {

View File

@@ -2,5 +2,7 @@ package logic.game
enum PollingEvents { enum PollingEvents {
case CardPlayed case CardPlayed
case GameStarted case NewRound
case ReloadEvent
case LobbyUpdate
} }

View File

@@ -7,7 +7,7 @@ import model.users.User
import java.util.UUID import java.util.UUID
import java.util.concurrent.locks.{Lock, ReentrantLock} import java.util.concurrent.locks.{Lock, ReentrantLock}
class UserSession(user: User, val host: Boolean) extends PlayerSession { class UserSession(val user: User, val host: Boolean) extends PlayerSession {
var canInteract: Option[InteractionType] = None var canInteract: Option[InteractionType] = None
val lock: ReentrantLock = ReentrantLock() val lock: ReentrantLock = ReentrantLock()

View File

@@ -8,6 +8,10 @@ import scalafx.scene.image.Image
object WebUIUtils { object WebUIUtils {
def cardtoImage(card: Card): Html = { def cardtoImage(card: Card): Html = {
views.html.render.card.apply(f"images/cards/${cardtoString(card)}.png")(card.toString)
}
def cardtoString(card: Card) = {
val s = card.suit match { val s = card.suit match {
case Spades => "S" case Spades => "S"
case Hearts => "H" case Hearts => "H"
@@ -29,6 +33,7 @@ object WebUIUtils {
case Three => "3" case Three => "3"
case Two => "2" case Two => "2"
} }
views.html.render.card.apply(f"images/cards/$cv$s.png")(card.toString) f"$cv$s"
} }
} }

View File

@@ -4,7 +4,7 @@
@main("Ingame") { @main("Ingame") {
<div class="lobby-background vh-100"> <div class="lobby-background vh-100">
<main class="game-field-background vh-100"> <main class="game-field-background vh-100 ingame-side-shadow">
<div class="py-5 container-xxl"> <div class="py-5 container-xxl">
<div class="row ms-4 me-4"> <div class="row ms-4 me-4">
@@ -72,7 +72,7 @@
</div> </div>
<div class="row justify-content-center g-2 mt-4 bottom-div" style="backdrop-filter: blur(4px); margin-left: 0; margin-right: 0;"> <div class="row justify-content-center g-2 mt-4 bottom-div" style="backdrop-filter: blur(4px); margin-left: 0; margin-right: 0;">
<div class="row justify-content-center" id="card-slide"> <div class="row justify-content-center ingame-cards-slide" id="card-slide">
@for(i <- player.currentHand().get.cards.indices) { @for(i <- player.currentHand().get.cards.indices) {
<div class="col-auto handcard" style="border-radius: 6px"> <div class="col-auto handcard" style="border-radius: 6px">
<div class="btn btn-outline-light p-0 border-0 shadow-none" data-card-id="@i" style="border-radius: 6px" onclick="handlePlayCard(this, '@gamelobby.id')"> <div class="btn btn-outline-light p-0 border-0 shadow-none" data-card-id="@i" style="border-radius: 6px" onclick="handlePlayCard(this, '@gamelobby.id')">

View File

@@ -1,27 +1,72 @@
@(player: de.knockoutwhist.player.AbstractPlayer, logic: de.knockoutwhist.control.GameLogic) @(player: de.knockoutwhist.player.AbstractPlayer, gamelobby: logic.game.GameLobby)
@main("Selecting Trumpsuit...") { @main("Selecting Trumpsuit...") {
<div id="selecttrumpsuit" class="game-field game-field-background"> <div id="selecttrumpsuit" class="game-field game-field-background">
@if(player.equals(logic.getCurrentMatch.get.roundlist.last.winner.get)) { <div class="ingame-stage blur-sides">
<h1>Knockout Whist</h1> <div class="container py-4">
<p>You (@player.toString) have won the last round! Select a trumpsuit for the next round!</p> <div class="row justify-content-center">
<p>Available trumpsuits are displayed below:</p> <div class="col-12">
<div id="playercards"> <div class="card shadow-sm">
@util.WebUIUtils.cardtoImage(de.knockoutwhist.cards.Card(de.knockoutwhist.cards.CardValue.Ace, de.knockoutwhist.cards.Suit.Spades)) <div class="card-header text-center">
@util.WebUIUtils.cardtoImage(de.knockoutwhist.cards.Card(de.knockoutwhist.cards.CardValue.Ace, de.knockoutwhist.cards.Suit.Clubs)) <h3 class="mb-0">Select Trump Suit</h3>
@util.WebUIUtils.cardtoImage(de.knockoutwhist.cards.Card(de.knockoutwhist.cards.CardValue.Ace, de.knockoutwhist.cards.Suit.Hearts)) </div>
@util.WebUIUtils.cardtoImage(de.knockoutwhist.cards.Card(de.knockoutwhist.cards.CardValue.Ace, de.knockoutwhist.cards.Suit.Diamonds)) <div class="card-body">
</div> @if(player.equals(gamelobby.logic.getCurrentMatch.get.roundlist.last.winner.get)) {
<p>Your cards</p> <div class="alert alert-info" role="alert" aria-live="polite">
You (@player.toString) won the last round. Choose the trump suit for the next round.
</div>
<div id="playercards"> <div class="row justify-content-center col-auto mb-5">
@for(card <- player.currentHand().get.cards) { <div class="col-auto handcard">
@util.WebUIUtils.cardtoImage(card) <form action="@routes.IngameController.playTrump(gamelobby.id)" method="post">
} <input type="hidden" name="cardId" value="0" />
<button type="submit" class="btn btn-outline-light p-0 border-0 shadow-none" name="trump" value="0" style="border-radius: 6px">
@util.WebUIUtils.cardtoImage(de.knockoutwhist.cards.Card(de.knockoutwhist.cards.CardValue.Ace, de.knockoutwhist.cards.Suit.Spades)) width="120px" style="border-radius: 6px"/>
</button>
</form>
</div>
<div class="col-auto handcard">
<form action="@routes.IngameController.playTrump(gamelobby.id)" method="post">
<input type="hidden" name="cardId" value="1" />
<button type="submit" class="btn btn-outline-light p-0 border-0 shadow-none" name="trump" value="1" style="border-radius: 6px">
@util.WebUIUtils.cardtoImage(de.knockoutwhist.cards.Card(de.knockoutwhist.cards.CardValue.Ace, de.knockoutwhist.cards.Suit.Hearts)) width="120px" style="border-radius: 6px"/>
</button>
</form>
</div>
<div class="col-auto handcard">
<form action="@routes.IngameController.playTrump(gamelobby.id)" method="post">
<input type="hidden" name="cardId" value="2" />
<button type="submit" class="btn btn-outline-light p-0 border-0 shadow-none" name="trump" value="2" style="border-radius: 6px">
@util.WebUIUtils.cardtoImage(de.knockoutwhist.cards.Card(de.knockoutwhist.cards.CardValue.Ace, de.knockoutwhist.cards.Suit.Diamonds)) width="120px" style="border-radius: 6px"/>
</button>
</form>
</div>
<div class="col-auto handcard">
<form action="@routes.IngameController.playTrump(gamelobby.id)" method="post">
<input type="hidden" name="cardId" value="3" />
<button type="submit" class="btn btn-outline-light p-0 border-0 shadow-none" name="trump" value="3" style="border-radius: 6px">
@util.WebUIUtils.cardtoImage(de.knockoutwhist.cards.Card(de.knockoutwhist.cards.CardValue.Ace, de.knockoutwhist.cards.Suit.Clubs)) width="120px" style="border-radius: 6px"/>
</button>
</form>
</div>
</div>
<div class="row justify-content-center ingame-cards-slide" id="card-slide">
@for(i <- player.currentHand().get.cards.indices) {
<div class="col-auto" style="border-radius: 6px">
@util.WebUIUtils.cardtoImage(player.currentHand().get.cards(i)) width="120px" style="border-radius: 6px"/>
</div>
}
</div>
} else {
<div class="alert alert-warning" role="alert" aria-live="polite">
@gamelobby.logic.getCurrentMatch.get.roundlist.last.winner.get.name is choosing a trumpsuit. The new round will start once a suit is picked.
</div>
}
</div>
</div>
</div>
</div>
</div> </div>
} else { </div>
<h1>Knockout Whist</h1>
<p>@player.toString is choosing a trumpsuit. Starting new round when @player.toString picked a trumpsuit...</p>
}
</div> </div>
} }

View File

@@ -1,27 +1,107 @@
@(player: de.knockoutwhist.player.AbstractPlayer, logic: de.knockoutwhist.control.GameLogic) @(player: de.knockoutwhist.player.AbstractPlayer, gamelobby: logic.game.GameLobby)
@main("Tie") { @main("Tie") {
<div id="tie" class="game-field game-field-background"> <div id="tie" class="game-field game-field-background">
<h1>Knockout Whist</h1> <div class="ingame-stage blur-sides">
<p>The last Round was tied between <div class="container py-4">
@for(players <- logic.playerTieLogic.getTiedPlayers) { <div class="row justify-content-center">
@players <div class="col-12 col-md-10 col-lg-8">
} <div class="card shadow-sm">
</p> <div class="card-header text-center">
@if(player.equals(logic.playerTieLogic.currentTiePlayer())) { <h3 class="mb-0">Tie Break</h3>
<p>Pick a card between 1 and @logic.playerTieLogic.highestAllowedNumber()! The resulting card will be your card for the cut.</p> </div>
} else { <div class="card-body">
<p>@logic.playerTieLogic.currentTiePlayer() is currently picking his number for the cut.</p> <div class="mb-3">
<p>Currently picked Cards:</p> <p class="card-text">
<div id="cardsplayed"> The last round was tied between:
@for((player, card) <- logic.playerTieLogic.getSelectedCard) { <span class="ms-1">
<div id="playedcardplayer"> @for(players <- gamelobby.logic.playerTieLogic.getTiedPlayers) {
<p>@player</p> <span class="badge text-bg-secondary me-1">@players</span>
@util.WebUIUtils.cardtoImage(card) }
</div> </span>
} </p>
</div> </div>
}
@if(player.equals(gamelobby.logic.playerTieLogic.currentTiePlayer())) {
@defining(gamelobby.logic.playerTieLogic.highestAllowedNumber()) { maxNum =>
<div class="alert alert-info" role="alert" aria-live="polite">
Pick a number between 1 and @{maxNum + 1}. The resulting card will be your card for the cut.
</div>
<form class="row g-2 align-items-center" method="post" action="@routes.IngameController.playTie(gamelobby.id)">
<div class="col-auto">
<label for="tieNumber" class="col-form-label">Your number</label>
</div>
<div class="col-auto">
<input type="number" id="tieNumber" class="form-control" name="tie" min="1" max="@{maxNum + 1}" placeholder="1" required>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary">Confirm</button>
</div>
</form>
<h6 class="mt-4 mb-3">Currently Picked Cards</h6>
<div id="cardsplayed" class="row g-3 justify-content-center">
@if(gamelobby.logic.playerTieLogic.getSelectedCard.nonEmpty) {
@for((player, card) <- gamelobby.logic.playerTieLogic.getSelectedCard) {
<div class="col-6">
<div class="card shadow-sm border-0 h-100 text-center">
<div class="card-body d-flex flex-column justify-content-between">
<p class="card-text fw-semibold mb-2 text-primary">@player</p>
<div class="card-img-top">
@util.WebUIUtils.cardtoImage(card)
</div>
</div>
</div>
</div>
}
} else {
<div class="col-12">
<div class="alert alert-info text-center" role="alert">
<i class="bi bi-info-circle me-2"></i>
No cards have been selected yet.
</div>
</div>
}
</div>
}
} else {
<div class="alert alert-warning" role="alert" aria-live="polite">
<strong>@gamelobby.logic.playerTieLogic.currentTiePlayer()</strong> is currently picking a number for the cut.
</div>
<h6 class="mt-4 mb-3">Currently Picked Cards</h6>
<div id="cardsplayed" class="row g-3 justify-content-center">
@if(gamelobby.logic.playerTieLogic.getSelectedCard.nonEmpty) {
@for((player, card) <- gamelobby.logic.playerTieLogic.getSelectedCard) {
<div class="col-6 col-sm-4 col-md-3 col-lg-2">
<div class="card shadow-sm border-0 h-100 text-center">
<div class="card-body d-flex flex-column justify-content-between">
<p class="card-text fw-semibold mb-2 text-primary">@player</p>
<div class="card-img-top">
@util.WebUIUtils.cardtoImage(card)
</div>
</div>
</div>
</div>
}
} else {
<div class="col-12">
<div class="alert alert-info text-center" role="alert">
<i class="bi bi-info-circle me-2"></i>
No cards have been selected yet.
</div>
</div>
}
</div>
}
</div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
} }

View File

@@ -20,42 +20,43 @@
</div> </div>
<div class="row justify-content-center align-items-center flex-grow-1"> <div class="row justify-content-center align-items-center flex-grow-1">
@if((gamelobby.getUserSession(user.get.id).host)) { @if((gamelobby.getUserSession(user.get.id).host)) {
@for(playersession <- gamelobby.getPlayers.values) { <div id="players" class="justify-content-center align-items-center d-flex">
<div class="col-auto my-auto"> @for(playersession <- gamelobby.getPlayers.values) {
<div class="card" style="width: 18rem;"> <div class="col-auto my-auto m-3">
<img src="@routes.Assets.versioned("images/profile.png")" alt="Profile" class="card-img-top w-50 mx-auto mt-3" /> <div class="card" style="width: 18rem;">
<div class="card-body"> <img src="@routes.Assets.versioned("images/profile.png")" alt="Profile" class="card-img-top w-50 mx-auto mt-3" />
<div class="card-body">
@if(playersession.id == user.get.id) { @if(playersession.id == user.get.id) {
<h5 class="card-title">@playersession.name (You)</h5> <h5 class="card-title">@playersession.name (You)</h5>
@* <p class="card-text">Your text could be here!</p>*@
<a href="#" class="btn btn-danger disabled" aria-disabled="true" tabindex="-1">Remove</a> <a href="#" class="btn btn-danger disabled" aria-disabled="true" tabindex="-1">Remove</a>
} else { } else {
<h5 class="card-title">@playersession.name</h5> <h5 class="card-title">@playersession.name</h5>
@* <p class="card-text">Your text could be here!</p>*@
<div class="btn btn-danger" onclick="removePlayer('@gamelobby.id', '@playersession.id')">Remove</div> <div class="btn btn-danger" onclick="removePlayer('@gamelobby.id', '@playersession.id')">Remove</div>
} }
</div>
</div> </div>
</div> </div>
</div> }
} </div>
<div class="col-12 text-center mb-5"> <div class="col-12 text-center mb-5">
<div class="btn btn-success" onclick="startGame('@gamelobby.id')">Start Game</div> <div class="btn btn-success" onclick="startGame('@gamelobby.id')">Start Game</div>
</div> </div>
} else { } else {
@for(playersession <- gamelobby.getPlayers.values) { <div id="players" class="justify-content-center align-items-center d-flex">
<div class="col-auto my-auto"> <div class="card" style="width: 18rem;"> @for(playersession <- gamelobby.getPlayers.values) {
<img src="@routes.Assets.versioned("images/profile.png")" alt="Profile" class="card-img-top w-50 mx-auto mt-3" /> <div class="col-auto my-auto m-3"> <div class="card" style="width: 18rem;">
<div class="card-body"> <img src="@routes.Assets.versioned("images/profile.png")" alt="Profile" class="card-img-top w-50 mx-auto mt-3" />
<div class="card-body">
@if(playersession.id == user.get.id) { @if(playersession.id == user.get.id) {
<h5 class="card-title">@playersession.name (You)</h5> <h5 class="card-title">@playersession.name (You)</h5>
} else { } else {
<h5 class="card-title">@playersession.name</h5> <h5 class="card-title">@playersession.name</h5>
} }
</div>
</div> </div>
</div> </div>
</div> }
} </div>
<div class="col-12 text-center mt-3"> <div class="col-12 text-center mt-3">
<p class="fs-4">Waiting for the host to start the game...</p> <p class="fs-4">Waiting for the host to start the game...</p>
<div class="spinner-border mt-1" role="status"> <div class="spinner-border mt-1" role="status">

View File

@@ -3,7 +3,7 @@
@main("Create Game") { @main("Create Game") {
@navbar(user) @navbar(user)
<main class="lobby-background flex-grow-1"> <main class="lobby-background flex-grow-1">
<div class="w-50 mx-auto"> <div class="w-25 mx-auto">
<div class="mt-3"> <div class="mt-3">
<label for="lobbyname" class="form-label">Lobby-Name</label> <label for="lobbyname" class="form-label">Lobby-Name</label>
<input type="text" class="form-control" id="lobbyname" name="lobbyname" placeholder="Lobby 1" required> <input type="text" class="form-control" id="lobbyname" name="lobbyname" placeholder="Lobby 1" required>

View File

@@ -1,6 +1,6 @@
@(user: Option[model.users.User]) @(user: Option[model.users.User])
<nav class="navbar navbar-expand-lg bg-body-tertiary"> <nav class="navbar navbar-expand-lg bg-body-tertiary navbar-drop-shadow">
<div class="container d-flex justify-content-left"> <div class="container d-flex justify-content-start">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navBar" aria-controls="navBar" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navBar" aria-controls="navBar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>

View File

@@ -2,75 +2,179 @@
@main("Rules") { @main("Rules") {
@navbar(user) @navbar(user)
<div id="rules">
<div class="container my-4"> <main class="lobby-background flex-grow-1">
<div class="card shadow-sm rounded-3"> <div class="container my-4" style="max-width:980px;">
<div class="card-header text-white text-center"> <div class="card rules-card shadow-sm rounded-3 overflow-hidden">
<h4 class="mb-0 text-body">Game Rules Overview</h4> <div class="card-header text-center py-3 border-0">
</div> <h3 class="mb-0 rules-title">Game Rules Overview</h3>
<div class="card-body p-0"> </div>
<div class="table-responsive">
<table class="table table-striped table-hover mb-0 align-middle"> <div class="card-body p-0">
<thead class="table-dark"> <style>
<tr>
<th scope="col">Section</th> </style>
<th scope="col">Details</th>
</tr> <div class="accordion rules-accordion" id="rulesAccordion">
</thead> <div class="accordion-item">
<tbody> <h2 class="accordion-header" id="headingPlayers">
<tr> <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapsePlayers" aria-expanded="true" aria-controls="collapsePlayers">
<td>Players</td> Players
<td>Two to seven players. The aim is to be the last player left in the game.</td> </button>
</tr> </h2>
<tr> <div id="collapsePlayers" class="accordion-collapse collapse show" aria-labelledby="headingPlayers" data-bs-parent="#rulesAccordion">
<td>Aim</td> <div class="accordion-body">
<td>To be the last player left at the end of the game, with the object in each hand being to win a majority of tricks.</td> Two to seven players. The aim is to be the last player left in the game.
</tr> </div>
<tr> </div>
<td>Equipment</td> </div>
<td>A standard 52-card pack is used.</td>
</tr> <div class="accordion-item">
<tr> <h2 class="accordion-header" id="headingAim">
<td>Card Ranks</td> <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseAim" aria-expanded="false" aria-controls="collapseAim">
<td>In each suit, cards rank from highest to lowest: A K Q J 10 9 8 7 6 5 4 3 2.</td> Aim
</tr> </button>
<tr> </h2>
<td>Deal (First Hand)</td> <div id="collapseAim" class="accordion-collapse collapse" aria-labelledby="headingAim" data-bs-parent="#rulesAccordion">
<td>The dealer deals seven cards to each player. One card is turned up to determine the trump suit for the round.</td> <div class="accordion-body">
</tr> To be the last player left at the end of the game, with the object in each hand being to win a majority of tricks.
<tr> </div>
<td>Deal (Subsequent Hands)</td> </div>
<td>The deal rotates clockwise. The player who took the most tricks in the previous hand selects the trump suit. If there's a tie, players cut cards to decide who calls trumps. One fewer card is dealt in each successive hand until the final hand consists of one card each.</td> </div>
</tr>
<tr> <div class="accordion-item">
<td>Play</td> <h2 class="accordion-header" id="headingEquipment">
<td>The player to the dealer's left (eldest hand) leads the first trick. Any card can be led. Other players must follow suit if possible. A player with no cards of the suit led may play any card.</td> <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseEquipment" aria-expanded="false" aria-controls="collapseEquipment">
</tr> Equipment
<tr> </button>
<td>Winning a Trick</td> </h2>
<td>The highest card of the suit led wins, unless a trump is played, in which case the highest trump wins. The winner of the trick leads the next.</td> <div id="collapseEquipment" class="accordion-collapse collapse" aria-labelledby="headingEquipment" data-bs-parent="#rulesAccordion">
</tr> <div class="accordion-body">
<tr> A standard 52-card pack is used.
<td>Leading Trumps</td> </div>
<td>Some rules disallow leading trumps before the suit has been 'broken' (a trump has been played to the lead of another suit). Leading trumps is always permissible if a player holds only trumps.</td> </div>
</tr> </div>
<tr>
<td>Knockout</td> <div class="accordion-item">
<td>At the end of each hand, any player who took no tricks is knocked out and takes no further part in the game.</td> <h2 class="accordion-header" id="headingRanks">
</tr> <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseRanks" aria-expanded="false" aria-controls="collapseRanks">
<tr> Card Ranks
<td>Winning the Game</td> </button>
<td>The game is won when a player takes all the tricks in a round, as all other players are knocked out, leaving only one player remaining.</td> </h2>
</tr> <div id="collapseRanks" class="accordion-collapse collapse" aria-labelledby="headingRanks" data-bs-parent="#rulesAccordion">
<tr> <div class="accordion-body">
<td>Dog Life</td> In each suit, cards rank from highest to lowest: A K Q J 10 9 8 7 6 5 4 3 2.
<td>The first player who takes no tricks is awarded a "dog's life". In the next hand, that player is dealt one card and can decide which trick to play it to. Each time a trick is played the "dog" may either play the card or knock on the table and wait to play it later. If the dog wins a trick, the player to the left leads the next and the dog re-enters the game properly in the next hand. If the dog fails, they are knocked out.</td> </div>
</tr> </div>
</tbody> </div>
</table>
<div class="accordion-item">
<h2 class="accordion-header" id="headingDealFirst">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseDealFirst" aria-expanded="false" aria-controls="collapseDealFirst">
Deal (First Hand)
</button>
</h2>
<div id="collapseDealFirst" class="accordion-collapse collapse" aria-labelledby="headingDealFirst" data-bs-parent="#rulesAccordion">
<div class="accordion-body">
The dealer deals seven cards to each player. One card is turned up to determine the trump suit for the round.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingDealSubsequent">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseDealSubsequent" aria-expanded="false" aria-controls="collapseDealSubsequent">
Deal (Subsequent Hands)
</button>
</h2>
<div id="collapseDealSubsequent" class="accordion-collapse collapse" aria-labelledby="headingDealSubsequent" data-bs-parent="#rulesAccordion">
<div class="accordion-body">
The deal rotates clockwise. The player who took the most tricks in the previous hand selects the trump suit. If there's a tie, players cut cards to decide who calls trumps. One fewer card is dealt in each successive hand until the final hand consists of one card each.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingPlay">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapsePlay" aria-expanded="false" aria-controls="collapsePlay">
Play
</button>
</h2>
<div id="collapsePlay" class="accordion-collapse collapse" aria-labelledby="headingPlay" data-bs-parent="#rulesAccordion">
<div class="accordion-body">
The player to the dealer's left (eldest hand) leads the first trick. Any card can be led. Other players must follow suit if possible. A player with no cards of the suit led may play any card.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingWinningTrick">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseWinningTrick" aria-expanded="false" aria-controls="collapseWinningTrick">
Winning a Trick
</button>
</h2>
<div id="collapseWinningTrick" class="accordion-collapse collapse" aria-labelledby="headingWinningTrick" data-bs-parent="#rulesAccordion">
<div class="accordion-body">
The highest card of the suit led wins, unless a trump is played, in which case the highest trump wins. The winner of the trick leads the next.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingLeadingTrumps">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseLeadingTrumps" aria-expanded="false" aria-controls="collapseLeadingTrumps">
Leading Trumps
</button>
</h2>
<div id="collapseLeadingTrumps" class="accordion-collapse collapse" aria-labelledby="headingLeadingTrumps" data-bs-parent="#rulesAccordion">
<div class="accordion-body">
Some rules disallow leading trumps before the suit has been 'broken' (a trump has been played to the lead of another suit). Leading trumps is always permissible if a player holds only trumps.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingKnockout">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseKnockout" aria-expanded="false" aria-controls="collapseKnockout">
Knockout
</button>
</h2>
<div id="collapseKnockout" class="accordion-collapse collapse" aria-labelledby="headingKnockout" data-bs-parent="#rulesAccordion">
<div class="accordion-body">
At the end of each hand, any player who took no tricks is knocked out and takes no further part in the game.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingWinningGame">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseWinningGame" aria-expanded="false" aria-controls="collapseWinningGame">
Winning the Game
</button>
</h2>
<div id="collapseWinningGame" class="accordion-collapse collapse" aria-labelledby="headingWinningGame" data-bs-parent="#rulesAccordion">
<div class="accordion-body">
The game is won when a player takes all the tricks in a round, as all other players are knocked out, leaving only one player remaining.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingDogLife">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseDogLife" aria-expanded="false" aria-controls="collapseDogLife">
Dog Life
</button>
</h2>
<div id="collapseDogLife" class="accordion-collapse collapse" aria-labelledby="headingDogLife" data-bs-parent="#rulesAccordion">
<div class="accordion-body">
The first player who takes no tricks is awarded a \"dog's life\". In the next hand, that player is dealt one card and can decide which trick to play it to. Each time a trick is played the dog may either play the card or knock on the table and wait to play it later. If the dog wins a trick, the player to the left leads the next and the dog re-enters the game properly in the next hand. If the dog fails, they are knocked out.
</div>
</div>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </main>
</div>
</div>
} }

View File

@@ -27,7 +27,11 @@ GET /game/:id controllers.IngameController.game(id: String
GET /game/:id/join controllers.IngameController.joinGame(id: String) GET /game/:id/join controllers.IngameController.joinGame(id: String)
GET /game/:id/start controllers.IngameController.startGame(id: String) GET /game/:id/start controllers.IngameController.startGame(id: String)
POST /game/:id/kickPlayer controllers.IngameController.kickPlayer(id: String, playerId: String) POST /game/:id/kickPlayer controllers.IngameController.kickPlayer(id: String, playerId: String)
POST /game/:id/trump controllers.IngameController.playTrump(id: String)
POST /game/:id/tie controllers.IngameController.playTie(id: String)
GET /game/:id/leaveGame controllers.IngameController.leaveGame(id: String) GET /game/:id/leaveGame controllers.IngameController.leaveGame(id: String)
POST /game/:id/playCard controllers.IngameController.playCard(id: String) POST /game/:id/playCard controllers.IngameController.playCard(id: String)
# Polling # Polling
GET /polling controllers.IngameController.polling(gameId: String) GET /polling controllers.PollingController.polling(gameId: String)

View File

@@ -93,7 +93,7 @@ function pollForUpdates(gameId) {
setTimeout(() => pollForUpdates(gameId), 5000); setTimeout(() => pollForUpdates(gameId), 5000);
return; return;
} }
const route = jsRoutes.controllers.IngameController.polling(gameId); const route = jsRoutes.controllers.PollingController.polling(gameId);
// Call your specific controller endpoint // Call your specific controller endpoint
fetch(route.url) fetch(route.url)
@@ -106,13 +106,21 @@ function pollForUpdates(gameId) {
} else if (response.ok && response.status === 200) { } else if (response.ok && response.status === 200) {
response.json().then(data => { response.json().then(data => {
if (data.status === "cardPlayed" && data.handData) { if (data.status === "cardPlayed" && data.handData && element) {
console.log("Event received: Card played. Redrawing hand."); console.log("Event received: Card played. Redrawing hand.");
const newHand = data.handData; const newHand = data.handData;
let newHandHTML = ''; let newHandHTML = '';
element.innerHTML = ''; element.innerHTML = '';
if(data.animation) {
if (!element.classList.contains('ingame-cards-slide')) {
element.classList.add('ingame-cards-slide');
}
} else {
element.classList.remove('ingame-cards-slide');
}
newHand.forEach((cardId, index) => { newHand.forEach((cardId, index) => {
const cardHtml = ` const cardHtml = `
<div class="col-auto handcard" style="border-radius: 6px"> <div class="col-auto handcard" style="border-radius: 6px">
@@ -211,8 +219,45 @@ function pollForUpdates(gameId) {
// Clear the container and insert the new image // Clear the container and insert the new image
firstCardContainer.innerHTML = newImageHTML; firstCardContainer.innerHTML = newImageHTML;
} }
} else if (data.status === "gameStart") { } else if (data.status === "reloadEvent") {
window.location.href = data.redirectUrl; window.location.href = data.redirectUrl;
} else if (data.status === "lobbyUpdate") {
const players = document.getElementById("players");
let newHtml = ''
if (data.host) {
data.users.forEach(user => {
const inner = user.self ? `<h5 class="card-title">${user.name} (You)</h5>
<a href="#" class="btn btn-danger disabled" aria-disabled="true" tabindex="-1">Remove</a>`
: ` <h5 class="card-title">${user.name}</h5>
<div class="btn btn-danger" onclick="removePlayer('${gameId}', '${user.id}')">Remove</div>`
newHtml += `<div class="col-auto my-auto m-3">
<div class="card" style="width: 18rem;">
<img src="/assets/images/profile.png" alt="Profile" class="card-img-top w-50 mx-auto mt-3" />
<div class="card-body">
${inner}
</div>
</div>
</div>`
})
} else {
data.users.forEach(user => {
const inner = user.self ? `<h5 class="card-title">${user.name} (You)</h5>` : ` <h5 class="card-title">${user.name}</h5>`
newHtml += `<div class="col-auto my-auto m-3">
<div class="card" style="width: 18rem;">
<img src="/assets/images/profile.png" alt="Profile" class="card-img-top w-50 mx-auto mt-3" />
<div class="card-body">
${inner}
</div>
</div>
</div>`
})
}
players.innerHTML = newHtml;
} }
pollForUpdates(gameId); pollForUpdates(gameId);
}); });
@@ -340,9 +385,11 @@ function sendRemovePlayerRequest(gameId, playersessionId) {
} }
}); });
} }
function leaveGame(gameId) { function leaveGame(gameId) {
sendLeavePlayerRequest(gameId) sendLeavePlayerRequest(gameId)
} }
function sendLeavePlayerRequest(gameId) { function sendLeavePlayerRequest(gameId) {
const route = jsRoutes.controllers.IngameController.leaveGame(gameId); const route = jsRoutes.controllers.IngameController.leaveGame(gameId);

View File

@@ -1,3 +1,3 @@
MAJOR=1 MAJOR=1
MINOR=0 MINOR=1
PATCH=9 PATCH=0