Minesweeper/src/Main.hs

45 lines
1.2 KiB
Haskell
Raw Normal View History

2021-01-28 14:17:59 +00:00
module Main where
import Control.Monad
import Control.Concurrent (threadDelay)
2021-01-28 14:17:59 +00:00
import System.Random
import qualified Graphics.UI.Threepenny as UI
import Graphics.UI.Threepenny.Core
import Minesweeper
2021-01-28 14:17:59 +00:00
main :: IO ()
main = do
rng <- newStdGen
startGUI defaultConfig {jsStatic = Just "view"} $ setup rng
setup :: StdGen -> Window -> UI ()
setup rng w = void $ do
return w # set title "Minesweeper"
UI.addStyleSheet w "bootstrap.min.css"
UI.addStyleSheet w "minesweeper.css"
let board = createBoard 10 0.2 rng
getBody w #+ [
UI.div #. "container" #+ [
UI.h1 #+ [string "Minesweeper"],
--UI.h4 #+ [string "By Jack Harley <jharley@tcd.ie>"],
gameGridTable board
]]
gameGridTable :: Board -> UI Element
gameGridTable b = mkElement "table" #+ rows b
rows :: Board -> [UI Element]
rows b = rows2 b 0
rows2 b r | r < size b = (mkElement "tr" #+ cells b r) : rows2 b (r+1)
| otherwise = []
cells :: Board -> Int -> [UI Element]
cells b r = cells2 b r 0
cells2 b r c | c < size b = mkElement "td" #. squareColour b (r,c) #+ [string $ squareAscii b (r,c)] : cells2 b r (c+1)
| otherwise = []