Skip to content

Commit

Permalink
feat: change the state when white card play phase message is sent
Browse files Browse the repository at this point in the history
  • Loading branch information
djpiper28 committed Aug 30, 2024
1 parent 5e17151 commit e016829
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/gameLogic/game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ func TestJudgingSuccess(t *testing.T) {

assert.Equal(t, res.WinnerId, winnerId)

assert.Equal(t, game.GameState, gameLogic.GameStateWhiteCardsBeingSelected)
assert.Equal(t, gameLogic.GameStateWhiteCardsBeingSelected, game.GameState)
assert.Equal(t, 1, game.PlayersMap[winnerId].Points)
assert.Equal(t, uint(2), game.CurrentRound)

Expand Down
2 changes: 1 addition & 1 deletion backend/network/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (c *WsConnection) listenAndHandle() error {
CardCzarId: res.NewCzarId}
encodedMsg, err := EncodeRpcMessage(msg)
if err != nil {
logger.Logger.Errorf("Cannot encode message to send to player")
logger.Logger.Error("Cannot encode message to send to player")
}

go GlobalConnectionManager.SendToPlayer(c.GameId, pid, encodedMsg)
Expand Down
2 changes: 1 addition & 1 deletion backend/network/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (msg RpcCzarSelectCardMsg) Type() RpcMessageType {

type RpcOnWhiteCardPlayPhase struct {
BlackCard *gameLogic.BlackCard `json:"blackCard"`
YourHand []*gameLogic.WhiteCard `json:"whiteCard"`
YourHand []*gameLogic.WhiteCard `json:"yourHand"`
CardCzarId uuid.UUID `json:"cardCzarId"`
}

Expand Down
20 changes: 18 additions & 2 deletions cahfrontend/src/gameState/gameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
RpcOnPlayerDisconnectMsg,
RpcOnPlayerJoinMsg,
RpcOnPlayerLeaveMsg,
RpcOnWhiteCardPlayPhase,
RpcPlayCardsMsg,
RpcRoundInformationMsg,
} from "../rpcTypes";
Expand All @@ -45,6 +46,7 @@ import { apiClient, wsBaseUrl } from "../apiClient";
import WebSocket from "isomorphic-ws";
import { GamePlayerList } from "./gamePlayersList";
import { GameLobbyState } from "./gameLobbyState";
import { WhiteCard } from "../components/gameItems/Card.stories";

export const playerIdCookie = "playerId";
/**
Expand Down Expand Up @@ -346,6 +348,18 @@ class GameState {
);
}

public handleOnWhiteCardPlayPhase(msg: RpcOnWhiteCardPlayPhase) {
this.roundState.totalPlays = 0;
this.roundState.roundNumber++;
this.roundState.blackCard = msg.blackCard!;
this.roundState.yourHand = msg.yourHand as WhiteCard[];
this.roundState.currentCardCzarId = msg.cardCzarId;
this.onRoundStateChange?.(structuredClone(this.roundState));

this.lobbyState.gameState = GameStateWhiteCardsBeingSelected;
this.onLobbyStateChange?.(structuredClone(this.lobbyState));
}

/**
* Handles an RPC message from the server. When testing call the private method and ignore the "error".
*/
Expand Down Expand Up @@ -400,8 +414,10 @@ class GameState {
rpcMessage.data as RpcOnCzarJudgingPhaseMsg,
);
case MsgOnWhiteCardPlayPhase:
console.log("TODO Implement me");
break;
console.log("Handling on white card play phase message");
return this.handleOnWhiteCardPlayPhase(
rpcMessage as RpcOnWhiteCardPlayPhase,
);
default:
throw new Error(
`Cannot handle RPC message as type is not valid ${rpcMessage.type}`,
Expand Down

0 comments on commit e016829

Please sign in to comment.