mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-08-13 14:27:27 +00:00
Fix hangman: lowercase r swallowed by restart binding during play
The Update key switch bound "r" to restart, but returned early even when the game was still active, so lowercase r could never be entered as a letter guess (Shift+R worked because "R" didn't match the case). Now r only restarts when dead; otherwise it falls through to the guess logic. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
d19c5c4c3e
commit
55ddbbc4de
2 changed files with 14 additions and 1 deletions
|
|
@ -78,10 +78,11 @@ func (h *hangman) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
case "q", "esc":
|
case "q", "esc":
|
||||||
return h, back
|
return h, back
|
||||||
case "r":
|
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 {
|
if h.dead {
|
||||||
return newHangman(h.user, h.ctx), nil
|
return newHangman(h.user, h.ctx), nil
|
||||||
}
|
}
|
||||||
return h, nil
|
|
||||||
case " ", "enter":
|
case " ", "enter":
|
||||||
if h.won {
|
if h.won {
|
||||||
h.deal() // advance to the next word
|
h.deal() // advance to the next word
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
func TestHangmanLowercaseInputAndAdvance(t *testing.T) {
|
||||||
h := newTestHangman("CAT")
|
h := newTestHangman("CAT")
|
||||||
for _, r := range "cat" { // lowercase should still solve
|
for _, r := range "cat" { // lowercase should still solve
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue