implement round end

This commit is contained in:
Branden J Brown 2024-01-20 23:52:58 -06:00
parent 56f8387385
commit a0608dac03
1 changed files with 31 additions and 1 deletions

View File

@ -70,11 +70,41 @@ func (g *Game) Apply(item int) {
// PopShell removes a shell from the shotgun. // PopShell removes a shell from the shotgun.
// This may cause the shotgun to be empty, but does not start the next group // This may cause the shotgun to be empty, but does not start the next group
// if so. // if so.
func (g *Game) PopShell() { func (g *Game) PopShell() bool {
r := g.Shells[0]
g.Shells = g.Shells[1:] g.Shells = g.Shells[1:]
return r
} }
// Empty returns whether the shotgun is empty. // Empty returns whether the shotgun is empty.
func (g *Game) Empty() bool { func (g *Game) Empty() bool {
return len(g.Shells) == 0 return len(g.Shells) == 0
} }
// Winner returns the player who won, or nil if the round is not over.
func (g *Game) Winner() *Player {
if g.PP[0].HP <= 0 {
return &g.PP[1]
}
if g.PP[1].HP <= 0 {
return &g.PP[0]
}
return nil
}
// Shoot fires the shotgun, at the opponent if self is false and at the current
// player if self is true. Afterward, the round may be over, or the shotgun may
// be empty.
func (g *Game) Shoot(self bool) {
target := g.Opponent()
if self {
target = g.CurrentPlayer()
}
live := g.PopShell()
if live {
target.HP -= g.Damage
g.Turn++
} else if !self {
g.Turn++
}
}