mirror of
https://github.com/cjdenio/crossword.git
synced 2026-10-03 11:06:19 +00:00
use "enum" for solve state
This commit is contained in:
1 file changed
+14
-12
+14
-12
@@ -12,15 +12,22 @@ import (
|
|||||||
"github.com/cjdenio/crossword/puz"
|
"github.com/cjdenio/crossword/puz"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SolveState int
|
||||||
|
|
||||||
|
const (
|
||||||
|
Unsolved SolveState = iota
|
||||||
|
FilledNotSolved
|
||||||
|
Solved
|
||||||
|
)
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
Puzzle *puz.Puzzle
|
Puzzle *puz.Puzzle
|
||||||
PuzzleState []rune
|
PuzzleState []rune
|
||||||
SelectedCell int
|
SelectedCell int
|
||||||
SelectedClue *puz.Clue
|
SelectedClue *puz.Clue
|
||||||
Goodbye bool
|
|
||||||
LastKeySequence string
|
LastKeySequence string
|
||||||
DebugMode bool
|
DebugMode bool
|
||||||
SolveState int
|
SolveState SolveState
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *State) MoveCursor(direction int) {
|
func (state *State) MoveCursor(direction int) {
|
||||||
@@ -217,10 +224,10 @@ func (state *State) RenderUI(w io.Writer) int {
|
|||||||
uiHeight += 1
|
uiHeight += 1
|
||||||
|
|
||||||
switch state.SolveState {
|
switch state.SolveState {
|
||||||
case 1:
|
case FilledNotSolved:
|
||||||
fmt.Fprintf(w, "\r\n%s\r\n", AnsiRed("The puzzle was filled, but at least 1 letter is incorrect..."))
|
fmt.Fprintf(w, "\r\n%s\r\n", AnsiRed("The puzzle was filled, but at least 1 letter is incorrect..."))
|
||||||
uiHeight += 2
|
uiHeight += 2
|
||||||
case 2:
|
case Solved:
|
||||||
fmt.Fprintf(w, "\r\n%s\r\n", AnsiGreen("The puzzle was solved!"))
|
fmt.Fprintf(w, "\r\n%s\r\n", AnsiGreen("The puzzle was solved!"))
|
||||||
uiHeight += 2
|
uiHeight += 2
|
||||||
}
|
}
|
||||||
@@ -230,11 +237,6 @@ func (state *State) RenderUI(w io.Writer) int {
|
|||||||
uiHeight += 2
|
uiHeight += 2
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.Goodbye {
|
|
||||||
fmt.Fprint(w, "\r\nsee ya\r\n")
|
|
||||||
uiHeight += 2
|
|
||||||
}
|
|
||||||
|
|
||||||
return uiHeight
|
return uiHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,13 +405,13 @@ func (state *State) HandleInput(buffer []byte) (exited bool) {
|
|||||||
|
|
||||||
if state.GridFilled() {
|
if state.GridFilled() {
|
||||||
if state.CheckPuzzle() {
|
if state.CheckPuzzle() {
|
||||||
state.SolveState = 2
|
state.SolveState = Solved
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
state.SolveState = 1
|
state.SolveState = FilledNotSolved
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state.SolveState = 0
|
state.SolveState = Unsolved
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user