mirror of
https://github.com/cjdenio/crossword.git
synced 2026-10-03 11:06:19 +00:00
jump to unfilled cell + handle panics
This commit is contained in:
2 files changed
+17
-4
No files matched your search
@@ -3,7 +3,5 @@ todo
|
||||
- When pressing enter, skip filled words
|
||||
- Shift-enter
|
||||
- check puzzle when grid is filled
|
||||
- when pressing enter, jump to _first unfilled cell_ in next clue
|
||||
- fix bug with that one 6x6 puzzle
|
||||
- correctly calculate uiHeight with multi-line clues
|
||||
- properly handle panics
|
||||
@@ -143,6 +143,15 @@ func (state *State) MoveCursor(direction int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) FirstUnfilledCellForClue(clue *puz.Clue) int {
|
||||
for _, cell := range clue.Cells {
|
||||
if state.PuzzleState[cell] == '-' {
|
||||
return cell
|
||||
}
|
||||
}
|
||||
return clue.Cells[0]
|
||||
}
|
||||
|
||||
func (state *State) NextWord() {
|
||||
if state.SelectedClue == nil {
|
||||
return
|
||||
@@ -158,7 +167,7 @@ func (state *State) NextWord() {
|
||||
|
||||
if foundSelectedClue && clue.Direction == state.SelectedClue.Direction {
|
||||
state.SelectedClue = clue
|
||||
state.SelectedCell = clue.Cells[0]
|
||||
state.SelectedCell = state.FirstUnfilledCellForClue(clue)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -166,7 +175,7 @@ func (state *State) NextWord() {
|
||||
for _, clue := range state.Puzzle.Clues {
|
||||
if clue.Direction != state.SelectedClue.Direction {
|
||||
state.SelectedClue = clue
|
||||
state.SelectedCell = clue.Cells[0]
|
||||
state.SelectedCell = state.FirstUnfilledCellForClue(clue)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -223,6 +232,12 @@ func main() {
|
||||
|
||||
defer term.Restore(int(os.Stdin.Fd()), termState)
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Print("!!! PROGRAM CRASHED !!! Error:\r\n", r, "\r\n")
|
||||
}
|
||||
}()
|
||||
|
||||
debugMode := flag.Bool("debug", false, "")
|
||||
flag.Parse()
|
||||
|
||||
|
||||
Reference in new issue
Block a user