add shell count info for start of round

This commit is contained in:
Branden J Brown 2024-01-21 01:16:30 -06:00
parent 9b6b645cfe
commit 18e1793b16
2 changed files with 23 additions and 0 deletions

View File

@ -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")

View File

@ -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"`
}