use game errors in game actor
This commit is contained in:
parent
09521cb5b0
commit
245109883a
16
game.go
16
game.go
@ -24,13 +24,7 @@ func applyAction(g *game.Match, a action) error {
|
|||||||
case "quit":
|
case "quit":
|
||||||
return g.Concede(a.Player)
|
return g.Concede(a.Player)
|
||||||
case "across", "self":
|
case "across", "self":
|
||||||
if err := g.Shoot(a.Player, a.Action == "self"); err != nil {
|
return g.Shoot(a.Player, a.Action == "self")
|
||||||
return err
|
|
||||||
}
|
|
||||||
if g.RoundWinner() != nil {
|
|
||||||
return errRoundEnded
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
case "0":
|
case "0":
|
||||||
return g.Apply(a.Player, 0)
|
return g.Apply(a.Player, 0)
|
||||||
case "1":
|
case "1":
|
||||||
@ -88,7 +82,7 @@ func gameActor(ctx context.Context, g *game.Match, dealer, chall person, join <-
|
|||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
broadcast(ctx, g, dealer, chall, obs)
|
broadcast(ctx, g, dealer, chall, obs)
|
||||||
case errRoundEnded:
|
case game.ErrRoundEnded:
|
||||||
broadcast(ctx, g, dealer, chall, obs)
|
broadcast(ctx, g, dealer, chall, obs)
|
||||||
if g.MatchWinner() != nil {
|
if g.MatchWinner() != nil {
|
||||||
gameOver(ctx, dealer, chall, obs)
|
gameOver(ctx, dealer, chall, obs)
|
||||||
@ -97,7 +91,10 @@ func gameActor(ctx context.Context, g *game.Match, dealer, chall person, join <-
|
|||||||
}
|
}
|
||||||
g.NextRound()
|
g.NextRound()
|
||||||
broadcast(ctx, g, dealer, chall, obs)
|
broadcast(ctx, g, dealer, chall, obs)
|
||||||
// TODO(zeph): broadcast shell counts?
|
case game.ErrGameEnded:
|
||||||
|
broadcast(ctx, g, dealer, chall, obs)
|
||||||
|
g.NextGame()
|
||||||
|
broadcast(ctx, g, dealer, chall, obs)
|
||||||
case game.ErrWrongTurn: // do nothing
|
case game.ErrWrongTurn: // do nothing
|
||||||
case errWeirdAction:
|
case errWeirdAction:
|
||||||
slog.WarnContext(ctx, "nonsense action", "from", a.Player, "action", a.Action)
|
slog.WarnContext(ctx, "nonsense action", "from", a.Player, "action", a.Action)
|
||||||
@ -159,7 +156,6 @@ func gameOver(ctx context.Context, dealer, chall person, obs []person) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errRoundEnded = errors.New("someone h*ckin died")
|
|
||||||
errWeirdAction = errors.New("unknown action")
|
errWeirdAction = errors.New("unknown action")
|
||||||
errMatchExpired = errors.New("there is a time limit on matches please")
|
errMatchExpired = errors.New("there is a time limit on matches please")
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user