consolidate turn advance

This commit is contained in:
Branden J Brown 2024-01-21 00:13:23 -06:00
parent 93aa4b49d0
commit 4d2f5a43dc
2 changed files with 20 additions and 5 deletions

View File

@ -10,10 +10,10 @@ type Game struct {
RNG RNG RNG RNG
PP [2]Player PP [2]Player
Shells []bool Shells []bool
HP int8
Round uint Round uint
Group uint Group uint
Turn uint Turn uint
HP int8
Damage int8 Damage int8
Reveal bool Reveal bool
@ -23,8 +23,7 @@ type Game struct {
func NewGame() *Game { func NewGame() *Game {
return &Game{ return &Game{
RNG: NewRNG(), RNG: NewRNG(),
Damage: 1,
} }
} }
@ -32,6 +31,8 @@ func (g *Game) StartRound() {
g.PP[0].StartRound() g.PP[0].StartRound()
g.PP[1].StartRound() g.PP[1].StartRound()
g.Round++ g.Round++
g.Group = 0
g.StartGroup()
} }
func (g *Game) StartGroup() { func (g *Game) StartGroup() {
@ -50,6 +51,15 @@ func (g *Game) StartGroup() {
ShuffleSlice(&g.RNG, g.Shells) ShuffleSlice(&g.RNG, g.Shells)
g.Group++ g.Group++
g.Turn = 0 g.Turn = 0
g.NextTurn()
}
func (g *Game) NextTurn() {
g.Turn++
g.Damage = 1
g.Reveal = false
cur := g.CurrentPlayer()
cur.Cuffs = cur.Cuffs.NextState()
} }
// CurrentPlayer gets the index of the current player, either 0 or 1. // CurrentPlayer gets the index of the current player, either 0 or 1.
@ -120,9 +130,9 @@ func (g *Game) Shoot(id player.ID, self bool) error {
live := g.PopShell() live := g.PopShell()
if live { if live {
target.HP -= g.Damage target.HP -= g.Damage
g.Turn++ g.NextTurn()
} else if !self { } else if !self {
g.Turn++ g.NextTurn()
} }
return nil return nil
} }

View File

@ -36,3 +36,8 @@ const (
Cuffed Cuffed
CuffedSkip CuffedSkip
) )
func (c CuffState) NextState() CuffState {
var m = [...]CuffState{Uncuffed, Uncuffed, Cuffed}
return m[c]
}