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
PP [2]Player
Shells []bool
HP int8
Round uint
Group uint
Turn uint
HP int8
Damage int8
Reveal bool
@ -23,8 +23,7 @@ type Game struct {
func NewGame() *Game {
return &Game{
RNG: NewRNG(),
Damage: 1,
RNG: NewRNG(),
}
}
@ -32,6 +31,8 @@ func (g *Game) StartRound() {
g.PP[0].StartRound()
g.PP[1].StartRound()
g.Round++
g.Group = 0
g.StartGroup()
}
func (g *Game) StartGroup() {
@ -50,6 +51,15 @@ func (g *Game) StartGroup() {
ShuffleSlice(&g.RNG, g.Shells)
g.Group++
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.
@ -120,9 +130,9 @@ func (g *Game) Shoot(id player.ID, self bool) error {
live := g.PopShell()
if live {
target.HP -= g.Damage
g.Turn++
g.NextTurn()
} else if !self {
g.Turn++
g.NextTurn()
}
return nil
}

View File

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