Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/arcade/hangman.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ func (h *hangman) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "q", "esc":
return h, back
case "r":
// Only "restart" once dead; during play, r is a normal letter guess
// and must fall through to the guessing logic below.
if h.dead {
return newHangman(h.user, h.ctx), nil
}
return h, nil
case " ", "enter":
if h.won {
h.deal() // advance to the next word
Expand Down
12 changes: 12 additions & 0 deletions plugins/arcade/hangman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ func TestHangmanDeathAfterSixMisses(t *testing.T) {
}
}

// The "r" restart binding must not swallow r as a letter guess during play.
func TestHangmanLowercaseRIsAGuess(t *testing.T) {
h := newTestHangman("ROUTER")
for _, r := range "router" {
m, _ := h.Update(key(r))
h = m.(*hangman)
}
if !h.won {
t.Fatalf("lowercase r should count as a guess and solve ROUTER")
}
}

func TestHangmanLowercaseInputAndAdvance(t *testing.T) {
h := newTestHangman("CAT")
for _, r := range "cat" { // lowercase should still solve
Expand Down
Loading