From d0b3cbd47ab752df8bd56bb8d3445e491953de42 Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Sun, 7 Apr 2024 21:27:32 -0500 Subject: [PATCH] add adrenaline to dto --- game/game.go | 21 +++++++++++---------- game/game_test.go | 38 ++++++++++++++++++++++---------------- serve/dto.go | 2 ++ 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/game/game.go b/game/game.go index 488ed73..eb830f6 100644 --- a/game/game.go +++ b/game/game.go @@ -272,16 +272,17 @@ func (g *Match) DTO(id player.ID, deadline time.Time) serve.Game { g.players[0].dto(), g.players[1].dto(), }, - Action: g.action.String(), - Winner: w, - Round: g.round, - Dealer: g.CurrentPlayer() == &g.players[0], - Damage: g.damage, - Shell: g.Peek(id), - Previous: g.prev, - Deadline: deadline.UnixMilli(), - Live: live, - Blank: blank, + Action: g.action.String(), + Winner: w, + Round: g.round, + Dealer: g.CurrentPlayer() == &g.players[0], + Damage: g.damage, + Adrenaline: g.adrenaline, + Shell: g.Peek(id), + Previous: g.prev, + Deadline: deadline.UnixMilli(), + Live: live, + Blank: blank, } } diff --git a/game/game_test.go b/game/game_test.go index 4f5cfb9..4b60eb8 100644 --- a/game/game_test.go +++ b/game/game_test.go @@ -32,6 +32,7 @@ func TestNewGame(t *testing.T) { {g.hp < 2 || g.hp > 4, "hp is %d, want 2-4", []any{g.hp}}, {g.damage != 1, "damage is %d, want 1", []any{g.damage}}, {g.reveal, "revealed at start", nil}, + {g.adrenaline, "adrenaline at start", nil}, {g.prev != nil, "already discharged", nil}, } for _, c := range checks { @@ -60,6 +61,7 @@ func TestGameStartRound(t *testing.T) { {g.hp < 2 || g.hp > 4, "hp is %d, want 2-4", []any{g.hp}}, {g.damage != 1, "damage is %d, want 1", []any{g.damage}}, {g.reveal, "revealed at start", nil}, + {g.adrenaline, "adrenaline at start", nil}, {g.prev != nil, "already discharged", nil}, } for _, c := range checks { @@ -95,6 +97,7 @@ func TestGameStartGroup(t *testing.T) { {g.turn != 1, "turn is %d, want 1", []any{g.turn}}, {g.damage != 1, "damage is %d, want 1", []any{g.damage}}, {g.reveal, "revealed at start", nil}, + {g.adrenaline, "adrenaline at start", nil}, {g.prev != nil, "already discharged", nil}, } for _, c := range checks { @@ -128,6 +131,7 @@ func TestGameNextTurn(t *testing.T) { {g.turn != i, "turn is %d, want %d", []any{g.turn, i}}, {g.damage != 1, "damage is %d, want 1", []any{g.damage}}, {g.reveal, "revealed at start", nil}, + {g.adrenaline, "adrenaline at start", nil}, {g.CurrentPlayer().cuffs != uncuffed, "cuffs is %d, want %d", []any{g.CurrentPlayer().cuffs, uncuffed}}, } for _, c := range checks { @@ -447,14 +451,15 @@ func TestGameDTO(t *testing.T) { g.players[0].dto(), g.players[1].dto(), }, - Action: "Start", - Round: g.round, - Dealer: false, - Damage: g.damage, - Shell: nil, - Previous: nil, - Live: len(g.shells) / 2, - Blank: (len(g.shells) + 1) / 2, + Action: "Start", + Round: g.round, + Dealer: false, + Damage: g.damage, + Adrenaline: false, + Shell: nil, + Previous: nil, + Live: len(g.shells) / 2, + Blank: (len(g.shells) + 1) / 2, } if got := g.DTO(dealer, time.UnixMilli(0)); want != got { t.Errorf("dealer sees the wrong thing:\nwant %+v\ngot %+v", want, got) @@ -473,14 +478,15 @@ func TestGameDTO(t *testing.T) { g.players[0].dto(), g.players[1].dto(), }, - Action: "Shoot", - Round: g.round, - Dealer: true, - Damage: g.damage, - Shell: nil, - Previous: &g.shellArray[0], - Live: 0, - Blank: 0, + Action: "Shoot", + Round: g.round, + Dealer: true, + Damage: g.damage, + Adrenaline: false, + Shell: nil, + Previous: &g.shellArray[0], + Live: 0, + Blank: 0, } if got := g.DTO(dealer, time.UnixMilli(0)); want != got { t.Errorf("dealer sees the wrong thing:\nwant %+v\ngot %+v", want, got) diff --git a/serve/dto.go b/serve/dto.go index 4d7351b..52c6792 100644 --- a/serve/dto.go +++ b/serve/dto.go @@ -17,6 +17,8 @@ type Game struct { Dealer bool `json:"dealer"` // Damage is the damage a live shell will deal this turn. Damage int8 `json:"damage"` + // Adrenaline indicates whether the current player has adrenaline. + Adrenaline bool `json:"adrenaline"` // Shell gives whether the current shell is live if it is revealed. // Undefined if this game state is not for the current player or if the // current player hasn't revealed it.