distinguish round and match winners
This commit is contained in:
parent
711724bc4d
commit
f7be9beabc
15
game/game.go
15
game/game.go
@ -153,9 +153,9 @@ func (g *Match) Empty() bool {
|
|||||||
return len(g.shells) == 0
|
return len(g.shells) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Winner returns the player who won the current round, or nil if the round is
|
// RoundWinner returns the player who won the current round, or nil if the
|
||||||
// not over.
|
// round is not over.
|
||||||
func (g *Match) Winner() *Player {
|
func (g *Match) RoundWinner() *Player {
|
||||||
if g.players[0].hp <= 0 {
|
if g.players[0].hp <= 0 {
|
||||||
return &g.players[1]
|
return &g.players[1]
|
||||||
}
|
}
|
||||||
@ -165,6 +165,15 @@ func (g *Match) Winner() *Player {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MatchWinner returns the player who has won the match, or nil if the match
|
||||||
|
// is not over.
|
||||||
|
func (g *Match) MatchWinner() *Player {
|
||||||
|
if g.round < 3 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return g.RoundWinner()
|
||||||
|
}
|
||||||
|
|
||||||
// Shoot fires the shotgun, at the opponent if self is false and at the current
|
// Shoot fires the shotgun, at the opponent if self is false and at the current
|
||||||
// player if self is true. Afterward, the round or game may be over.
|
// player if self is true. Afterward, the round or game may be over.
|
||||||
// Returns ErrWrongTurn if id does not correspond to the current player.
|
// Returns ErrWrongTurn if id does not correspond to the current player.
|
||||||
|
@ -310,7 +310,7 @@ func TestGameWinner(t *testing.T) {
|
|||||||
g := New(dealer, chall)
|
g := New(dealer, chall)
|
||||||
g.players[0].hp = c.p0
|
g.players[0].hp = c.p0
|
||||||
g.players[1].hp = c.p1
|
g.players[1].hp = c.p1
|
||||||
if got := g.Winner(); deref(got).id != c.want {
|
if got := g.RoundWinner(); deref(got).id != c.want {
|
||||||
t.Errorf("wrong winner: %#v doesn't have id %#v", got, c.want)
|
t.Errorf("wrong winner: %#v doesn't have id %#v", got, c.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -434,7 +434,7 @@ func TestConcede(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
g := New(dealer, chall)
|
g := New(dealer, chall)
|
||||||
g.Concede(c.p)
|
g.Concede(c.p)
|
||||||
if got := g.Winner(); deref(got).id != c.winner {
|
if got := g.RoundWinner(); deref(got).id != c.winner {
|
||||||
t.Errorf("wrong winner: %#v doesn't have id %#v", got, c.winner)
|
t.Errorf("wrong winner: %#v doesn't have id %#v", got, c.winner)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user