From 12852c8576d74403b72e911542d7b4398a8200a3 Mon Sep 17 00:00:00 2001 From: Jan Klinge Date: Wed, 15 Mar 2023 17:51:32 +0100 Subject: [PATCH] Adding latest improvements --- server/main.go | 32 ++++++++++----------- src/components/game/lobby/LobbyCode.tsx | 10 +++++++ src/components/game/lobby/LobbySettings.tsx | 2 +- src/components/game/session/SessionHold.tsx | 3 +- src/components/home/HomeRules.tsx | 4 +-- src/models/Card.ts | 4 +-- src/pages/Game.tsx | 2 ++ 7 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 src/components/game/lobby/LobbyCode.tsx diff --git a/server/main.go b/server/main.go index 6241f82..380c58a 100644 --- a/server/main.go +++ b/server/main.go @@ -744,7 +744,6 @@ func main() { if rules.Bottomless { for { drawn = append(drawn, randomCard()) - stack = stack[:len(stack)-2] if drawn[len(drawn)-1][1] == stack[0][1] || drawn[len(drawn)-1][0] == stack[0][0] || drawn[len(drawn)-1][1] == 'd' { break } @@ -994,11 +993,6 @@ func main() { // Applying traits for next player globals.Drawable = true - if card[0] == 'p' { - globals.Stacking = globals.Stacking + 1 - } else { - globals.Stacking = 0 - } globals.Live = players[next].Name } @@ -1181,14 +1175,15 @@ func main() { globals.Live = players[next].Name globals.Drawable = true globals.Swapping = false - if card[0] == 'p' { - globals.Stacking = 1 - } } else { globals.Live = players[playerIndex].Name globals.Drawable = false } + if card[0] == 'p' || card[0] == 'j' { + globals.Stacking = 1 + } + // Check if player has won if rules.King && len(hand) == 0 { // Reset game @@ -1302,6 +1297,11 @@ func main() { return apis.NewBadRequestError("User is still drawable.", err) } + // Update drawing status + if globals.Swapping { + return apis.NewBadRequestError("User is still swapping.", err) + } + // Shifting turn to next player next, err := nextPlayer(player.GetString("name"), players, globals) if err != nil { @@ -1457,11 +1457,6 @@ func main() { return err } - // Checking if player has turn - if err := playing(player, globals); err != nil { - return err - } - // Retrieving player status playerIndex, err := playerIndexByName(player.GetString("name"), players) if err != nil { @@ -1476,6 +1471,11 @@ func main() { // Check if player can call if players[playerIndex].Cards > 2 { return apis.NewBadRequestError("You have too many cards to call.", err) + } else if players[playerIndex].Cards == 2 { + // Checking if player has turn + if err := playing(player, globals); err != nil { + return err + } } // Set player as called @@ -1687,9 +1687,6 @@ func main() { players[targetIndex].Called = called1 players[playerIndex].Called = called2 - // Finish switching - globals.Swapping = false - // Advancing turn next, err := nextPlayer(player.GetString("name"), players, globals) if err != nil { @@ -1699,6 +1696,7 @@ func main() { // Applying traits for next player globals.Live = players[next].Name globals.Drawable = true + globals.Swapping = false // Update state playersUpdate, err := playersFromStruct(players) diff --git a/src/components/game/lobby/LobbyCode.tsx b/src/components/game/lobby/LobbyCode.tsx new file mode 100644 index 0000000..9549f7a --- /dev/null +++ b/src/components/game/lobby/LobbyCode.tsx @@ -0,0 +1,10 @@ +import React from "react"; + +export default function LobbyCode(props: { game: string }) { + return ( +
+

Others can join using code

+ {props.game} +
+ ); +} diff --git a/src/components/game/lobby/LobbySettings.tsx b/src/components/game/lobby/LobbySettings.tsx index 4cd7c34..1c0bc15 100644 --- a/src/components/game/lobby/LobbySettings.tsx +++ b/src/components/game/lobby/LobbySettings.tsx @@ -47,7 +47,7 @@ export default function LobbySettings(props: { session: SessionType }) { rules(props.session, { ordered: !props.session.rules.ordered, diff --git a/src/components/game/session/SessionHold.tsx b/src/components/game/session/SessionHold.tsx index 4bda4dc..d18d986 100644 --- a/src/components/game/session/SessionHold.tsx +++ b/src/components/game/session/SessionHold.tsx @@ -15,7 +15,8 @@ export default function SessionHold(props: { session: SessionType }) { if ( !props.session.me.live || props.session.globals.drawable || - !props.session.rules.hold + !props.session.rules.hold || + props.session.globals.swapping ) return null; diff --git a/src/components/home/HomeRules.tsx b/src/components/home/HomeRules.tsx index f5559a1..b66a387 100644 --- a/src/components/home/HomeRules.tsx +++ b/src/components/home/HomeRules.tsx @@ -52,7 +52,7 @@ export default function HomeRules(props: { theme: CardColor }) {
diff --git a/src/models/Card.ts b/src/models/Card.ts index ed69af6..9d27cf6 100644 --- a/src/models/Card.ts +++ b/src/models/Card.ts @@ -38,7 +38,7 @@ export type CardType = { }; function codeToFace(card: string) { - if (card.length <= 0) return CardFace.NUMBER_0; + if (typeof card !== "string") return CardFace.NUMBER_0; switch (card.charAt(0)) { default: @@ -76,7 +76,7 @@ function codeToFace(card: string) { } function codeToColor(card: string) { - if (card.length <= 0) return CardColor.DARK; + if (typeof card !== "string") return CardColor.DARK; switch (card.charAt(1)) { default: diff --git a/src/pages/Game.tsx b/src/pages/Game.tsx index bef0350..24daf34 100644 --- a/src/pages/Game.tsx +++ b/src/pages/Game.tsx @@ -23,6 +23,7 @@ import SessionBackground from "../components/game/SessionBackground"; import SessionDirection from "../components/game/session/SessionDirection"; import SessionLeave from "../components/game/session/SessionLeave"; import SessionHold from "../components/game/session/SessionHold"; +import LobbyCode from "../components/game/lobby/LobbyCode"; interface GameProps { game: string; @@ -206,6 +207,7 @@ export default class Game extends Component { +
)}