-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
34 lines (31 loc) · 957 Bytes
/
Main.hs
File metadata and controls
34 lines (31 loc) · 957 Bytes
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
import UI
import Graphics.Vty
import Types
import Brick.BChan
import Control.Concurrent
import Control.Monad
import Brick.Main
import Game
import GHC.IO.Handle
import GHC.IO.FD
main :: IO ()
main = do
rows <- getLineLoop isInteger "How many rows would you like in the grid?"
cols <- getLineLoop isInteger "Columns?"
initGame <- defaultMain editorApp (emptyGame (read rows) (read cols))
chan <- newBChan 10
forkIO $ forever $ do
writeBChan chan Tick
threadDelay 800000 -- decides how fast your game moves
let buildVty = mkVty defaultConfig
initVty <- buildVty
void $ customMain initVty buildVty (Just chan) app initGame
--Provide a func such that if func answer then exit the loop, else try again.
getLineLoop :: (String -> Bool) -> String -> IO String
getLineLoop func prompt = do
putStrLn prompt
answer <- getLine
if func answer then return answer
else
putStrLn "Try again!" >>
getLineLoop func prompt