From 18e1793b1662149c1387ca262a0425186ae80d71 Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Sun, 21 Jan 2024 01:16:30 -0600 Subject: [PATCH] add shell count info for start of round --- game/game.go | 17 +++++++++++++++++ serve/dto.go | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/game/game.go b/game/game.go index 76e02ca..1827e3e 100644 --- a/game/game.go +++ b/game/game.go @@ -23,6 +23,7 @@ type Game struct { ShellArray [8]bool } +// NewGame creates a new game started at round 1. func NewGame() *Game { g := &Game{ RNG: NewRNG(), @@ -31,6 +32,7 @@ func NewGame() *Game { return g } +// StartRound starts the next round of a game. func (g *Game) StartRound() { g.HP = int8(g.RNG.Intn(3) + 2) g.PP[0].StartRound(g.HP) @@ -40,6 +42,7 @@ func (g *Game) StartRound() { g.StartGroup() } +// StartGroup starts the next shell group of a round. func (g *Game) StartGroup() { items := g.RNG.Intn(4) + 1 g.PP[0].StartGroup(&g.RNG, items) @@ -59,6 +62,7 @@ func (g *Game) StartGroup() { g.NextTurn() } +// NextTurn advances the turn. func (g *Game) NextTurn() { g.Turn++ g.Damage = 1 @@ -165,4 +169,17 @@ func (g *Game) DTO(id player.ID) serve.Game { } } +// ShellCounts returns the number of live and blank shells. +func (g *Game) ShellCounts() serve.ShellCounts { + var counts serve.ShellCounts + for _, s := range g.Shells { + if s { + counts.Live++ + } else { + counts.Blank++ + } + } + return counts +} + var ErrWrongTurn = errors.New("not your turn") diff --git a/serve/dto.go b/serve/dto.go index 98a55dc..770fb8b 100644 --- a/serve/dto.go +++ b/serve/dto.go @@ -26,3 +26,9 @@ type Player struct { // Cuffs is whether the player is currently wearing cuffs. Cuffs bool `json:"cuffs,omitempty"` } + +// ShellCounts is the JSON DTO for shell counts emitted at the start of a round. +type ShellCounts struct { + Live int `json:"live"` + Blank int `json:"blank"` +}