Skip to content

Commit

Permalink
feat: setup ring to order who has to play
Browse files Browse the repository at this point in the history
  • Loading branch information
PapePathe committed Nov 2, 2023
1 parent b846c4c commit a269870
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
17 changes: 10 additions & 7 deletions pkg/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ var (
)

type Game struct {
Cartes [32]cards.Card
CartesDistribuees int
nombrePli int
pliCardsCount int
Decks [8]Deck
Plis [8][4]cards.Card
CartesDistribuees int
NombreJoueurs int
TakesFinished bool
Cartes [32]cards.Card
Decks [8]Deck
Plis [8][4]cards.Card
players [4]*player.Player
ring [4]int
take gametake.GameTake
}

Expand Down Expand Up @@ -79,9 +80,10 @@ func (g *Game) PlayCardNext(playerID int, c cards.Card) error {
return err
}

// if g.Decks[g.nombrePli].cardscount == 4 {
// g.nombrePli++
// }
if g.Decks[g.nombrePli].cardscount == 4 {
g.ring = g.NextRound(g.Decks[g.nombrePli].winner)
g.nombrePli++
}
return nil
}

Expand Down Expand Up @@ -134,6 +136,7 @@ func (g *Game) AddTake(playerID int, take gametake.GameTake) error {

g.players[playerID].Take = &take

fmt.Println(take)
if g.take.GreaterThan(take) && take != gametake.PASSE {
return ErrBadTake
}
Expand Down
20 changes: 9 additions & 11 deletions pkg/game/game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,10 @@ func TestPlayCardNext(t *testing.T) {
require.NoError(t, err)
}

err = game1.PlayCardNext(player1.GetID(), player1.PlayingHand.Cards[0])
require.NoError(t, err)

err = game1.PlayCardNext(player2.GetID(), player2.PlayingHand.Cards[0])
require.NoError(t, err)

err = game1.PlayCardNext(player3.GetID(), player3.PlayingHand.Cards[0])
require.NoError(t, err)

err = game1.PlayCardNext(player4.GetID(), player4.PlayingHand.Cards[0])
require.NoError(t, err)
for _, p := range game1.players {
err := game1.PlayCardNext(p.GetID(), p.PlayingHand.Cards[0])
require.NoError(t, err)
}

pli := [4]cards.Card{
player1.PlayingHand.Cards[0],
Expand All @@ -312,7 +305,12 @@ func TestPlayCardNext(t *testing.T) {
player4.PlayingHand.Cards[0],
}
assert.Equal(t, game1.Decks[0].cards, pli)
assert.Equal(t, 1, game1.nombrePli)
winner := game1.Decks[0].winner

nextRing := game1.NextRound(winner)
assert.Equal(t, nextRing, game1.ring)

fmt.Println("take ", game1.GetTake().Name(), "deck", pli, "winner:", winner)
})
}
Expand Down

0 comments on commit a269870

Please sign in to comment.