Skip to content

Commit

Permalink
feat: reset amount of points on round start
Browse files Browse the repository at this point in the history
  • Loading branch information
djpiper28 committed Aug 31, 2024
1 parent 1012945 commit 4d9026b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
13 changes: 12 additions & 1 deletion backend/gameLogic/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,12 @@ func (g *Game) newBlackCard() error {
// Not thread safe, gives each player new cards
func (g *Game) newWhiteCards() error {
for pid, p := range g.PlayersMap {
cards, err := g.CardDeck.GetNewWhiteCards(uint(HandSize - len(p.Hand)))
numberOfCardsRequired := HandSize - len(p.Hand)
if numberOfCardsRequired < 0 {
continue
}

cards, err := g.CardDeck.GetNewWhiteCards(uint(numberOfCardsRequired))
if err != nil {
return errors.New(fmt.Sprintf("Cannot create game: %s", err))
}
Expand Down Expand Up @@ -487,6 +492,11 @@ func (g *Game) StartGame() (RoundInfo, error) {
g.newCzar()
g.GameState = GameStateWhiteCardsBeingSelected

// Reset scores
for _, player := range g.PlayersMap {
player.Points = 0
}

err = g.newWhiteCards()
if err != nil {
return RoundInfo{}, err
Expand Down Expand Up @@ -596,6 +606,7 @@ func (g *Game) moveToCzarJudgingPhase() (CzarJudingPhaseInfo, error) {

newHand := make(map[int]*WhiteCard)
for _, playerCard := range player.Hand {
// Remove cards in current play from the hand
found := false
for _, card := range player.CurrentPlay {
if card.Id == playerCard.Id {
Expand Down
1 change: 1 addition & 0 deletions backend/gameLogic/game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ func TestPlayingCardCausesCzarJudingPhase(t *testing.T) {

for _, hand := range resp.CzarJudingPhaseInfo.PlayerHands.Hands {
assert.NotNil(t, hand)
assert.Len(t, hand, 7)
}
}

Expand Down
3 changes: 3 additions & 0 deletions backend/game_in_game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,6 @@ func (s *ServerTestSuite) TestPlayingCardInGame() {
assert.NoError(t, err)
assert.Equal(t, client.PlayerId, cardPlayedMsg.PlayerId)
}

// TODO: test czar can select a winner
// TODO: test czar can select a winner and cause a game to end
2 changes: 1 addition & 1 deletion cahfrontend/src/gameState/gameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ class GameState {
bodyText: x?.bodyText ?? "Cannot load this card :(",
};
});
this.onRoundStateChange?.(structuredClone(this.roundState));

this.lobbyState.gameState = GameStateCzarJudgingCards;
this.onLobbyStateChange?.(structuredClone(this.lobbyState));
this.onRoundStateChange?.(structuredClone(this.roundState));
this.onAllPlaysChanged?.(
data.allPlays.map((x) =>
x.map((card) => {
Expand Down

0 comments on commit 4d9026b

Please sign in to comment.