From 935ee6f7a160eccb24584fb6c55f9f8b717ea78e Mon Sep 17 00:00:00 2001 From: Jack Harley Date: Sat, 30 Jan 2021 14:02:28 +0000 Subject: [PATCH] UI --- src/Main.hs | 22 +++++++++++++++------- view/css/minesweeper.css | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index d5acf6f..be48735 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -24,15 +24,23 @@ setup w = void $ do UI.addStyleSheet w "minesweeper.css" rng <- liftIO newStdGen - let b = createBoard 30 0.15 rng :: Board + let b = createBoard 20 0.1 rng :: Board + liftIO $ putStrLn $ printBoard b iob <- liftIO $ newIORef b getBody w #+ [ - UI.div #. "container" # set UI.id_ "cont" #+ [ + UI.div #. "container" #+ [ UI.h1 #+ [string "Minesweeper"], UI.h4 #+ [string "Jack Harley jharley@tcd.ie"], - UI.p #+ [string "Instructions: Click to uncover, right click to flag"], - mkElement "table" # set UI.id_ "table" #+ rows iob b 0 + UI.div #. "row" #+ [ + UI.div # set UI.id_ "gameCont" #+ [mkElement "table" # set UI.id_ "table" #+ rows iob b 0], + UI.div # set UI.id_ "infoCont" #+ [ + UI.p #+ [string "Instructions: Click on a square to uncover it. Right click a square to flag it."], + UI.p #+ [string "Flagged squares will turn yellow. If you hit a mine all mines will instantly be revealed as red squares."], + UI.p #+ [string "Refresh the page to start a new game."], + UI.p #+ [string "Good luck!"] + ] + ] ], mkElement "script" # set (attr "src") "/static/custom.js"] @@ -48,12 +56,12 @@ setup w = void $ do #+ [string $ squareAscii b (r,c)] on UI.click cell $ \_ -> do - liftIO $ putStrLn "click" + liftIO $ putStrLn $ "Click (" ++ show r ++ "," ++ show c ++ ")" liftIO $ modifyIORef' iob $ \oldB -> uncover oldB (r,c) refresh iob on UI.contextmenu cell $ \_ -> do - liftIO $ putStrLn "rightclick" + liftIO $ putStrLn $ "Right Click (" ++ show r ++ "," ++ show c ++ ")" liftIO $ modifyIORef' iob $ \oldB -> flag oldB (r,c) refresh iob @@ -65,7 +73,7 @@ setup w = void $ do table <- getElementById w "table" let table' = fromJust table - cont <- getElementById w "cont" + cont <- getElementById w "gameCont" let cont' = return $ fromJust cont cont' #+ [mkElement "table" # set UI.id_ "table" #+ rows iob b 0] diff --git a/view/css/minesweeper.css b/view/css/minesweeper.css index 4f496d5..6e2454b 100644 --- a/view/css/minesweeper.css +++ b/view/css/minesweeper.css @@ -34,4 +34,20 @@ td { .text-maroon { color: maroon; } .text-turquoise { color: turquoise; } .text-black { color: black; } -.text-gray { color: gray; } \ No newline at end of file +.text-gray { color: gray; } + +.row { + padding-top: 10px; +} + +#gameCont { + float: left; + margin-left: 17px; +} + +#infoCont { + float: left; + margin-left: 20px; + font-size: 1.2em; + max-width: 350px; +} \ No newline at end of file