Compare commits

..

2 Commits

Author SHA1 Message Date
Branden J Brown 29265a18b7 add status messages for new items 2024-04-07 21:55:49 -05:00
Branden J Brown d0b3cbd47a add adrenaline to dto 2024-04-07 21:27:32 -05:00
5 changed files with 45 additions and 26 deletions

View File

@ -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,
}
}

View File

@ -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)

View File

@ -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.

View File

@ -48,6 +48,11 @@ const actionMessages: Record<Game["action"], (game: Game) => string> = {
Beer: (game) => `THE ${game.dealer ? "DEALER" : "CHALLENGER"} TAKES A SIP AND A ${game.previous ? "LIVE SHELL" : "BLANK"} CLATTERS ON THE TABLE`,
Cuff: (game) => `THE ${game.dealer ? "DEALER" : "CHALLENGER"} HANDS CUFFS ACROSS THE TABLE`,
Knife: (game) => `THE ${game.dealer ? "DEALER" : "CHALLENGER"} CUTS THE BARREL SHORT`,
Adrenaline: (game) => `THE ${game.dealer ? "DEALER" : "CHALLENGER"} INJECTS ADRENALINE`,
Inverter: (game) => `THE ${game.dealer ? "DEALER" : "CHALLENGER"} CRANKS A POLARITY INVERTER`,
Phone: (game) => `THE ${game.dealer ? "DEALER" : "CHALLENGER"} LISTENS TO THE WHISPERS`,
PillsHeal: (game) => `THE ${game.dealer ? "DEALER" : "CHALLENGER"} INHALES A PILL... AND SMILES`,
PillsHurt: (game) => `THE ${game.dealer ? "DEALER" : "CHALLENGER"} INHALES A PILL... AND COLLAPSES`,
DealerConcedes: () => `THE DEALER SUDDENLY TURNS TO DUST`,
ChallengerConcedes: () => `THE CHALLENGER SUDDENLY TURNS TO DUST`,
}

View File

@ -13,6 +13,7 @@ export interface Game {
action: "Start"
| "Shoot" | "GameEnd" | "BeerGameEnd" | "ChallengerWins" | "DealerWins"
| "Lens" | "Cig" | "Beer" | "Cuff" | "Knife"
| "Adrenaline" | "Phone" | "Inverter" | "PillsHeal" | "PillsHurt"
| "DealerConcedes" | "ChallengerConcedes"
/**
* Match winner.
@ -30,6 +31,10 @@ export interface Game {
* Damage that a live round will deal this turn.
*/
damage: number;
/**
* Current player's adrenaline state.
*/
adrenaline: boolean;
/**
* Deadline for the current player's next action in milliseconds since the
* Unix epoch.