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 00d780e commit 18729f9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
9 changes: 6 additions & 3 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func main() {
for {
drawn = append(drawn, resetCard(stack[len(stack)-1]))
stack = stack[:len(stack)-2]
if len(stack) > 1 && drawn[len(drawn)-1][1] != stack[0][1] {
if len(stack) <= 1 || drawn[len(drawn)-1][1] == stack[0][1] {
break
}
}
Expand All @@ -667,7 +667,7 @@ func main() {
index := rand.Intn(len(stack) - 2)
drawn = append(drawn, resetCard(stack[index]))
stack = append(stack[:index], stack[index+1:]...)
if len(stack) <= 1 && drawn[len(drawn)-1][1] != stack[0][1] {
if len(stack) <= 1 || drawn[len(drawn)-1][1] == stack[0][1] {
break
}
}
Expand Down Expand Up @@ -1056,7 +1056,7 @@ func main() {
}

// 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] {
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 @@ -1100,6 +1100,9 @@ func main() {
if card[0] == 'p' {
globals.Stacking = true
}
} else {
globals.Live = players[playerIndex].Name
globals.Drawable = false
}

// Check if player has won
Expand Down
5 changes: 2 additions & 3 deletions src/components/game/session/SessionLeave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default function SessionLeave(props: { navigate: NavigateFunction }) {
<div
className="absolute top-[2rem] left-[2rem] p-3 -z-10 rounded-2xl w-16 aspect-square bg-table-leave duration-200 hover:scale-110 cursor-pointer"
onClick={async () => {
props.navigate("/");

const swap = await sessionLeave();
if (swap["code"] !== 200) {
showNotification({
Expand All @@ -17,10 +19,7 @@ export default function SessionLeave(props: { navigate: NavigateFunction }) {
color: "red",
icon: <SettingsOutlined />,
});
return;
}

props.navigate("/");
}}
>
<svg viewBox="0 0 1000 1000">
Expand Down
36 changes: 27 additions & 9 deletions src/components/game/session/rows/RowBottom.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { SessionType } from "../../../../models/Session";
import { CardType, codeToType, typeToCode } from "../../../../models/Card";
import { API_NOTIFICATION_GAME_TIMEOUT, gamePlay } from "../../../../api/API";
import {
API_NOTIFICATION_GAME_TIMEOUT,
gamePlay,
gameThrow,
} from "../../../../api/API";
import { showNotification } from "@mantine/notifications";
import { PlayArrow } from "@mui/icons-material";
import CardFront from "../../../card/front/CardFront";
Expand Down Expand Up @@ -41,14 +45,28 @@ export default function RowBottom(props: {
<div
className="cursor-pointer hover:-translate-y-3 hover:scale-110 duration-200 w-fit ease-out"
onClick={async () => {
const play = await gamePlay(typeToCode(card));
if (play["code"] !== 200) {
showNotification({
autoClose: API_NOTIFICATION_GAME_TIMEOUT,
message: play["message"] ?? "An unknown error occurred.",
color: "red",
icon: <PlayArrow />,
});
if (!props.session.me.live) {
const smash = await gameThrow(typeToCode(card));
if (smash["code"] !== 200) {
showNotification({
autoClose: API_NOTIFICATION_GAME_TIMEOUT,
message:
smash["message"] ?? "An unknown error occurred.",
color: "red",
icon: <PlayArrow />,
});
}
} else {
const play = await gamePlay(typeToCode(card));
if (play["code"] !== 200) {
showNotification({
autoClose: API_NOTIFICATION_GAME_TIMEOUT,
message:
play["message"] ?? "An unknown error occurred.",
color: "red",
icon: <PlayArrow />,
});
}
}
}}
>
Expand Down

0 comments on commit 18729f9

Please sign in to comment.