transmit game actions and winner in dto
This commit is contained in:
23
serve/dto.go
23
serve/dto.go
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user