module Main where import Control.Monad import Control.Concurrent (threadDelay) import System.Random import qualified Graphics.UI.Threepenny as UI import Graphics.UI.Threepenny.Core import Minesweeper main :: IO () main = do startGUI defaultConfig {jsStatic = Just "view"} setup setup :: Window -> UI () setup w = void $ do return w # set title "Minesweeper" UI.addStyleSheet w "bootstrap.min.css" UI.addStyleSheet w "minesweeper.css" rng <- liftIO newStdGen --let board = createBoard 10 0.2 rng let board = uncover (createBoard 30 0.1 rng) (4,4) --let board = uncoverSafeAdjacents board (4,4) --let board = uncoverSafe board [(3,4)] getBody w #+ [ UI.div #. "container" #+ [ UI.h1 #+ [string "Minesweeper"], --UI.h4 #+ [string "By Jack Harley "], 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) ++ " " ++ squareTextColour b (r,c)) #+ [string $ squareAscii b (r,c)] : cells2 b r (c+1) | otherwise = []