2021-01-28 14:17:59 +00:00
|
|
|
module Main where
|
|
|
|
|
2021-01-28 19:31:39 +00:00
|
|
|
import Control.Monad
|
|
|
|
import Control.Concurrent (threadDelay)
|
|
|
|
|
2021-01-28 14:17:59 +00:00
|
|
|
import System.Random
|
|
|
|
|
2021-01-28 19:31:39 +00:00
|
|
|
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
|
2021-01-28 19:49:41 +00:00
|
|
|
startGUI defaultConfig {jsStatic = Just "view"} setup
|
2021-01-28 19:31:39 +00:00
|
|
|
|
2021-01-28 19:49:41 +00:00
|
|
|
setup :: Window -> UI ()
|
|
|
|
setup w = void $ do
|
2021-01-28 19:31:39 +00:00
|
|
|
return w # set title "Minesweeper"
|
|
|
|
|
|
|
|
UI.addStyleSheet w "bootstrap.min.css"
|
|
|
|
UI.addStyleSheet w "minesweeper.css"
|
|
|
|
|
2021-01-28 19:49:41 +00:00
|
|
|
rng <- liftIO newStdGen
|
2021-01-28 21:08:17 +00:00
|
|
|
--let board = createBoard 10 0.2 rng
|
|
|
|
let board = uncover (createBoard 10 0.2 rng) (4,4)
|
|
|
|
--let board = uncoverSafeAdjacents board (4,4)
|
|
|
|
--let board = uncoverSafe board [(3,4)]
|
2021-01-28 19:31:39 +00:00
|
|
|
|
|
|
|
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 = []
|