implement round end
This commit is contained in:
parent
56f8387385
commit
a0608dac03
32
game/game.go
32
game/game.go
@ -70,11 +70,41 @@ 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() {
|
||||
func (g *Game) PopShell() bool {
|
||||
r := g.Shells[0]
|
||||
g.Shells = g.Shells[1:]
|
||||
return r
|
||||
}
|
||||
|
||||
// Empty returns whether the shotgun is empty.
|
||||
func (g *Game) Empty() bool {
|
||||
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++
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user