Skip to content

Commit

Permalink
Adding latest improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
klydra committed Mar 15, 2023
1 parent ae02739 commit 12852c8
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 23 deletions.
32 changes: 15 additions & 17 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/components/game/lobby/LobbyCode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";

export default function LobbyCode(props: { game: string }) {
return (
<div className="absolute bottom-[1.5%] inset-x-1/2 flex justify-center items-center gap-x-3">
<p className="whitespace-nowrap">Others can join using code </p>
<b>{props.game}</b>
</div>
);
}
2 changes: 1 addition & 1 deletion src/components/game/lobby/LobbySettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function LobbySettings(props: { session: SessionType }) {
<Switch
disabled={!props.session.me.host}
color="gray"
checked={props.session.rules.ordered}
checked={!props.session.rules.ordered}
onClick={() =>
rules(props.session, {
ordered: !props.session.rules.ordered,
Expand Down
3 changes: 2 additions & 1 deletion src/components/game/session/SessionHold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/components/home/HomeRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function HomeRules(props: { theme: CardColor }) {
<Column>
<Entry
title="stacks"
text="Draw-2 cards and draw-4 cards are stackable."
text="Draw-2 cards and draw-4 cards are stackable and add their draw values together."
>
<CardFront
card={{
Expand Down Expand Up @@ -95,7 +95,7 @@ export default function HomeRules(props: { theme: CardColor }) {
</Entry>
<Entry
title="million cards"
text="You need to draw until you get a matching card."
text="You need to draw again and again until you get a matching card."
>
<div className="h-52">
<CardBack />
Expand Down
4 changes: 2 additions & 2 deletions src/models/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -206,6 +207,7 @@ export default class Game extends Component<GameProps, GameState> {
<LobbyPlayers session={session} />
<LobbySettings session={session} />
<LobbyStart session={session} />
<LobbyCode game={this.props.game} />
<SessionLeave navigate={this.props.navigate} />
</div>
)}
Expand Down

0 comments on commit 12852c8

Please sign in to comment.