transmit game actions and winner in dto

This commit is contained in:
2024-02-03 11:44:11 -06:00
parent 805fdb13c1
commit 1068060e94
6 changed files with 124 additions and 6 deletions

View File

@@ -7,6 +7,10 @@ type Game struct {
// Players is the players in the game.
// The dealer is always the first player.
Players [2]Player `json:"players"`
// Action indicates the previous action taken in the game.
Action string `json:"action"`
// Winner indicates the winner of the current round, if any.
Winner Winner `json:"winner,omitempty"`
// Round is the current round.
Round int8 `json:"round"`
// Dealer indicates whether the current player is the dealer.
@@ -45,3 +49,22 @@ type GameStart struct {
ID GameID `json:"id"`
Dealer bool `json:"dealer"`
}
// Winner is a round winner.
type Winner int8
const (
NoWinner Winner = iota
DealerWins
ChallengerWins
)
var winners = [...][]byte{
NoWinner: []byte("null"),
DealerWins: []byte("0"),
ChallengerWins: []byte("1"),
}
func (w *Winner) MarshalJSON() ([]byte, error) {
return winners[*w], nil
}