From 644ce0d2739864fc94e3842416ae38425000e828 Mon Sep 17 00:00:00 2001 From: Caleb Denio Date: Fri, 11 Sep 2026 21:58:52 -0500 Subject: [PATCH] fix bug --- README.md | 3 +-- game/game.go | 44 ++++++++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 95e5e4d..a7c9e09 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ todo -- fix bug with that one 6x6 puzzle - correctly calculate uiHeight with multi-line clues - timer - reveal grid/word - .puz checksums -- fix shift+enter / short+tab in other terminals +- fix shift+enter / shift+tab in other terminals - clear grid diff --git a/game/game.go b/game/game.go index 889d4f8..1bd3adb 100644 --- a/game/game.go +++ b/game/game.go @@ -348,6 +348,23 @@ func (state *State) LoadSaveFile(f []byte) error { return nil } +func (state *State) SwitchDirections() bool { + switch state.SelectedClue.Direction { + case puz.DirectionAcross: + if state.Puzzle.Cells[state.SelectedCell][1] != nil { + state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][1] + } + return true + case puz.DirectionDown: + if state.Puzzle.Cells[state.SelectedCell][0] != nil { + state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][0] + } + return true + } + + return false +} + func (state *State) HandleInput(buffer []byte) (exited bool) { if len(buffer) == 0 { return false @@ -360,16 +377,7 @@ func (state *State) HandleInput(buffer []byte) (exited bool) { } if buffer[0] == ' ' { - switch state.SelectedClue.Direction { - case puz.DirectionAcross: - if state.Puzzle.Cells[state.SelectedCell][1] != nil { - state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][1] - } - case puz.DirectionDown: - if state.Puzzle.Cells[state.SelectedCell][0] != nil { - state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][0] - } - } + state.SwitchDirections() } if buffer[0] >= 0x61 && buffer[0] <= 0x7a { @@ -427,9 +435,9 @@ func (state *State) HandleInput(buffer []byte) (exited bool) { if string(buffer[0:2]) == "\x1b[" { if (buffer[2] == 68 || buffer[2] == 67) && state.SelectedClue != nil && state.SelectedClue.Direction == puz.DirectionDown { - state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][0] + state.SwitchDirections() } else if (buffer[2] == 65 || buffer[2] == 66) && state.SelectedClue != nil && state.SelectedClue.Direction == puz.DirectionAcross { - state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][1] + state.SwitchDirections() } else { switch buffer[2] { case 68: // left @@ -444,9 +452,17 @@ func (state *State) HandleInput(buffer []byte) (exited bool) { switch state.SelectedClue.Direction { case puz.DirectionAcross: - state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][0] + if state.Puzzle.Cells[state.SelectedCell][0] != nil { + state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][0] + } else { + state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][1] + } case puz.DirectionDown: - state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][1] + if state.Puzzle.Cells[state.SelectedCell][1] != nil { + state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][1] + } else { + state.SelectedClue = state.Puzzle.Cells[state.SelectedCell][0] + } } } }