-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
66 lines (63 loc) · 2.28 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import Types
import UI
( menuApp,
fileBrowserApp,
editorApp,
gameApp,
menuDialog,
getChoice,
fileTypeFilter,
fileBrowser,
emptyGame,
saveDialog,
saveMenuApp )
import FileIO (loadGame, saveFileLoop)
import Brick (defaultMain)
import Brick.Widgets.FileBrowser(fileBrowserSelection, setFileBrowserEntryFilter, FileInfo(fileInfoFilename))
{- main
Runs the program haskudoku
SIDE EFFECTS: Reads keyboard input
prints to the terminal
reads and writes to files
-}
main :: IO ()
main = do
menuState <- defaultMain menuApp menuDialog
case getChoice menuState of
Just 0 -> do
initBrowserState <- fileBrowser
browserState <- defaultMain fileBrowserApp (setFileBrowserEntryFilter fileTypeFilter initBrowserState)
let choice = fileBrowserSelection browserState
case choice of
(file:files) -> do
gameState <- loadGame ("Puzzles/" ++ fileInfoFilename file)
endGame <- defaultMain gameApp gameState
saveYN <- defaultMain saveMenuApp saveDialog
if getChoice saveYN == Just 0 then do
saveFileLoop endGame
main
else main
[] -> main
Just 1 -> do
endGame <- defaultMain editorApp emptyGame
saveYN <- defaultMain saveMenuApp saveDialog
case getChoice saveYN of
Just 0 -> do
saveFileLoop endGame
main
Just 1 -> main
Nothing -> return ()
_ -> return ()
Just 2 -> do
putStrLn $ unlines
["Load: Loads a previously saved game",
"Editor: Starts the editor. Use this if you want to create an own sudoku to play later.",
"Help: Displays this message",
"Quit: Quit the game"
]
putStr "Press enter to go back> "
userIsDone <- getLine
main
Just 3 -> do return ()
Nothing -> do return ()
_ -> main