Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
klydra committed Mar 1, 2023
1 parent 4d6ae46 commit b06a19b
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 42 deletions.
44 changes: 34 additions & 10 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,11 @@ func main() {
globals.Stacking = false
globals.Drawable = false

// Checking if called state will be invalidated
if len(hand) > 1 && players[playerIndex].Called {
players[playerIndex].Called = false
}

if rules.Unlimited {
for j := 0; j < len(drawn); j++ {
if drawn[j][0] == stack[0][0] || drawn[j][1] == stack[0][1] {
Expand Down Expand Up @@ -824,8 +829,8 @@ func main() {
return apis.NewBadRequestError("You are currently swapping.", nil)
}

// Check if currently wishing
if !globals.Drawable && stack[0][1] == 'd' && (stack[0][0] == 'w' || stack[0][0] == 'j') {
// Check if currently wishing
return apis.NewBadRequestError("You are currently wishing.", nil)
}

Expand Down Expand Up @@ -1040,6 +1045,16 @@ func main() {
return err
}

// Checking if card is wish or if previous card has matching color
if stack[0][1] == 'd' {
return apis.NewBadRequestError("Player still needs to wish.", nil)
}

// Checking if card is wish or if previous card has matching color
if globals.Swapping {
return apis.NewBadRequestError("Player still needs to swap.", nil)
}

// Checking if card is wish or if previous card has matching color
if card[0] != 'w' && card[0] != 'j' && stack[0][0] != card[0] && stack[0][1] != card[1] {
return apis.NewBadRequestError("Card not matching.", nil)
Expand Down Expand Up @@ -1408,11 +1423,6 @@ func main() {
return err
}

hand, err := handFromPlayer(player)
if err != nil {
return err
}

players, err := playersFromGame(game)
if err != nil {
return err
Expand All @@ -1439,6 +1449,11 @@ func main() {
return err
}

targetHand, err := handFromPlayer(target)
if err != nil {
return err
}

// Retrieving target status
targetIndex, err := playerIndexByName(target.GetString("name"), players)
if err != nil {
Expand All @@ -1464,20 +1479,23 @@ func main() {
draw := 2
for {
if rules.Ordered {
hand = append(hand, stack[len(stack)-1])
targetHand = append(targetHand, stack[len(stack)-1])
stack = append(stack, stack[1:]...)
} else {
index := rand.Intn(len(stack) - 2)
hand = append(hand, stack[index])
targetHand = append(targetHand, stack[index])
stack = append(stack[:index], stack[index+1:]...)
}
draw--

if len(stack) > 1 && draw > 0 {
if len(stack) <= 1 || draw <= 0 {
break
}
}

// Update hand length
players[targetIndex].Cards = len(targetHand)

// Update state
playersUpdate, err := playersFromStruct(players)
if err != nil {
Expand All @@ -1489,7 +1507,7 @@ func main() {
return err
}

handUpdate, err := handFromStruct(hand)
handUpdate, err := handFromStruct(targetHand)
if err != nil {
return err
}
Expand Down Expand Up @@ -1574,6 +1592,12 @@ func main() {
players[targetIndex].Cards = cards1
players[playerIndex].Cards = cards2

// Switch called
called1 := players[playerIndex].Called
called2 := players[targetIndex].Called
players[targetIndex].Called = called1
players[playerIndex].Called = called2

// Finish switching
globals.Swapping = false

Expand Down
10 changes: 10 additions & 0 deletions src/components/game/lobby/LobbySettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function LobbySettings(props: { session: SessionType }) {
text="number of cards that are distributed to everyone"
>
<NumberInput
disabled={!props.session.me.host}
value={props.session.rules.count}
defaultValue={7}
placeholder="7"
Expand All @@ -44,6 +45,7 @@ export default function LobbySettings(props: { session: SessionType }) {
text="Cards drawn, given, etc. are taken from a random position in the stack."
>
<Switch
disabled={!props.session.me.host}
color="gray"
checked={props.session.rules.ordered}
onClick={() =>
Expand All @@ -59,6 +61,7 @@ export default function LobbySettings(props: { session: SessionType }) {
text="There is no cards deck. Every card drawn, given, etc. is purely random."
>
<Switch
disabled={!props.session.me.host}
color="gray"
checked={props.session.rules.bottomless}
onClick={() =>
Expand All @@ -74,6 +77,7 @@ export default function LobbySettings(props: { session: SessionType }) {
text="The game ends when the first player has played out all their cards."
>
<Switch
disabled={!props.session.me.host}
color="gray"
checked={props.session.rules.king}
onClick={() =>
Expand All @@ -89,6 +93,7 @@ export default function LobbySettings(props: { session: SessionType }) {
text="If you draw a matching card you choose to play it instantly or hold onto it."
>
<Switch
disabled={!props.session.me.host}
color="gray"
checked={props.session.rules.hold}
onClick={() =>
Expand All @@ -104,6 +109,7 @@ export default function LobbySettings(props: { session: SessionType }) {
text="You need to draw until you get a matching card."
>
<Switch
disabled={!props.session.me.host}
color="gray"
checked={props.session.rules.unlimited}
onClick={() =>
Expand All @@ -119,6 +125,7 @@ export default function LobbySettings(props: { session: SessionType }) {
text="Draw-2 cards are stackable."
>
<Switch
disabled={!props.session.me.host}
color="gray"
checked={props.session.rules.stack2}
onClick={() =>
Expand All @@ -134,6 +141,7 @@ export default function LobbySettings(props: { session: SessionType }) {
text="Draw-4 cards are stackable."
>
<Switch
disabled={!props.session.me.host}
color="gray"
checked={props.session.rules.stack4}
onClick={() =>
Expand All @@ -149,6 +157,7 @@ export default function LobbySettings(props: { session: SessionType }) {
text="If a 7 is played, the player can choose one opponent to swap cards with."
>
<Switch
disabled={!props.session.me.host}
color="gray"
checked={props.session.rules.swap}
onClick={() =>
Expand All @@ -164,6 +173,7 @@ export default function LobbySettings(props: { session: SessionType }) {
text="If a card is played and a player has the identical card, they may choose to throw it in, even if it isn't their turn. The game will then continue from the player after them."
>
<Switch
disabled={!props.session.me.host}
color="gray"
checked={props.session.rules.throw}
onClick={() =>
Expand Down
11 changes: 7 additions & 4 deletions src/components/game/session/SessionCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import { SettingsOutlined } from "@mui/icons-material";
import React from "react";

export default function SessionCall(props: { session: SessionType }) {
const callable =
!props.session.me.called &&
((props.session.me.hand.length === 2 && props.session.me.live) ||
props.session.me.hand.length === 1);

return (
<div className="fixed flex h-[12.5%] right-[80%] left-[10%] bottom-[6%] justify-center items-center">
{props.session.me.hand.length === 2 &&
!props.session.me.called &&
props.session.me.live ? (
{callable ? (
<Button
uppercase
className={
Expand Down Expand Up @@ -43,4 +46,4 @@ export default function SessionCall(props: { session: SessionType }) {
) : null}
</div>
);
}
}
3 changes: 1 addition & 2 deletions src/components/game/session/rows/RowLeft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default function RowLeft(props: {
props.session.enemies.length === 2 || props.session.enemies.length === 3;
const enemy = full ? props.session.enemies[0] : null;
const callable = full
? enemy!.live &&
!enemy!.called &&
? !enemy!.called &&
enemy!.cards < 2 &&
enemy!.name === sessionLast(props.session)
: null;
Expand Down
3 changes: 1 addition & 2 deletions src/components/game/session/rows/RowRight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default function RowRight(props: {
props.session.enemies.length === 2 || props.session.enemies.length === 3;
const enemy = full ? props.session.enemies[1] : null;
const callable = full
? enemy!.live &&
!enemy!.called &&
? !enemy!.called &&
enemy!.cards < 2 &&
enemy!.name === sessionLast(props.session)
: null;
Expand Down
3 changes: 1 addition & 2 deletions src/components/game/session/rows/RowTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export default function RowTop(props: { session: SessionType; scale: number }) {
? props.session.enemies[props.session.enemies.length === 1 ? 0 : 2]
: null;
const callable = full
? enemy!.live &&
!enemy!.called &&
? !enemy!.called &&
enemy!.cards < 2 &&
enemy!.name === sessionLast(props.session)
: null;
Expand Down
8 changes: 5 additions & 3 deletions src/components/game/session/stacks/StackDraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function StackDraw(props: {
<div className="fixed flex inset-y-1/2 left-[37.5%] right-[50%] inset-y-[42%] justify-center items-center">
<div
key={props.animator.disappear.toString()}
className="cursor-pointer h-full absolute z-10"
className="cursor-pointer min-h-[15rem] h-60 absolute z-10"
onClick={async () => {
const play = await gameDraw();
if (play["code"] !== 200) {
Expand All @@ -28,7 +28,9 @@ export default function StackDraw(props: {
>
<DisappearCard />
</div>
<CardBack />
<div className="min-h-[14rem] h-60">
<CardBack />
</div>
</div>
);
}
Expand All @@ -39,7 +41,7 @@ function DisappearCard() {

return (
<div
className="h-full duration-700 ease-out aria-disabled:scale-[125%] aria-disabled:opacity-0"
className="min-h-[15rem] h-60 duration-700 ease-out aria-disabled:scale-[125%] aria-disabled:opacity-0"
aria-disabled={disappear}
>
<CardBack />
Expand Down
22 changes: 11 additions & 11 deletions src/components/home/HomeMechanics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@ export default function HomeMechanics(props: { theme: CardColor }) {
}}
/>
</Entry>
<Entry
title="rotate"
text="If a rotate card is played, the direction of the game is being swapped."
>
<CardFront
card={{
face: CardFace.DIRECTION_CHANGE,
color: props.theme,
}}
/>
</Entry>
</Column>
<Column>
<Entry
Expand Down Expand Up @@ -107,6 +96,17 @@ export default function HomeMechanics(props: { theme: CardColor }) {
}}
/>
</Entry>
<Entry
title="rotate"
text="If a rotate card is played, the direction of the game is being swapped."
>
<CardFront
card={{
face: CardFace.DIRECTION_CHANGE,
color: props.theme,
}}
/>
</Entry>
</Column>
</Row>
</>
Expand Down
16 changes: 8 additions & 8 deletions src/components/home/HomeRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ export default function HomeRules(props: { theme: CardColor }) {
}}
/>
</Entry>
<Entry
title="million cards"
text="You need to draw until you get a matching card."
>
<div className="h-52">
<CardBack />
</div>
</Entry>
</Column>
<Column>
<Entry
Expand Down Expand Up @@ -101,6 +93,14 @@ export default function HomeRules(props: { theme: CardColor }) {
/>
</div>
</Entry>
<Entry
title="million cards"
text="You need to draw until you get a matching card."
>
<div className="h-52">
<CardBack />
</div>
</Entry>
</Column>
</Row>
</>
Expand Down

0 comments on commit b06a19b

Please sign in to comment.