72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package game
|
|
|
|
type Game struct {
|
|
RNG RNG
|
|
PP [2]Player
|
|
Shells []bool
|
|
HP int8
|
|
Round uint
|
|
Group uint
|
|
Turn uint
|
|
Damage int8
|
|
Reveal bool
|
|
|
|
// Backing storage for shells.
|
|
ShellArray [8]bool
|
|
}
|
|
|
|
func NewGame() *Game {
|
|
return &Game{
|
|
RNG: NewRNG(),
|
|
Damage: 1,
|
|
}
|
|
}
|
|
|
|
func (g *Game) StartRound() {
|
|
g.PP[0].StartRound()
|
|
g.PP[1].StartRound()
|
|
}
|
|
|
|
func (g *Game) StartGroup() {
|
|
items := g.RNG.Intn(4) + 1
|
|
g.HP = int8(g.RNG.Intn(3) + 2)
|
|
g.PP[0].StartGroup(&g.RNG, g.HP, items)
|
|
g.PP[1].StartGroup(&g.RNG, g.HP, items)
|
|
shells := g.RNG.Intn(6) + 2
|
|
for i := 0; i < shells/2; i++ {
|
|
g.ShellArray[i] = true
|
|
}
|
|
for i := shells / 2; i < shells; i++ {
|
|
g.ShellArray[i] = false
|
|
}
|
|
g.Shells = g.ShellArray[:shells]
|
|
ShuffleSlice(&g.RNG, g.Shells)
|
|
g.Group++
|
|
}
|
|
|
|
// CurrentPlayer gets the index of the current player, either 0 or 1.
|
|
func (g *Game) CurrentPlayer() uint {
|
|
return g.Turn % 2
|
|
}
|
|
|
|
// Opponent returns the player who is not the current player.
|
|
func (g *Game) Opponent() *Player {
|
|
return &g.PP[1^g.CurrentPlayer()]
|
|
}
|
|
|
|
// Apply uses an item by index for the current player.
|
|
func (g *Game) Apply(item int) {
|
|
}
|
|
|
|
// PopShell removes a shell from the shotgun.
|
|
// This may cause the shotgun to be empty, but does not start the next group
|
|
// if so.
|
|
func (g *Game) PopShell() {
|
|
g.Shells = g.Shells[1:]
|
|
}
|
|
|
|
// Empty returns whether the shotgun is empty.
|
|
func (g *Game) Empty() bool {
|
|
return len(g.Shells) == 0
|
|
}
|