This commit is contained in:
parent
f5e8477bc0
commit
935ee6f7a1
22
src/Main.hs
22
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]
|
||||
|
||||
|
|
|
@ -34,4 +34,20 @@ td {
|
|||
.text-maroon { color: maroon; }
|
||||
.text-turquoise { color: turquoise; }
|
||||
.text-black { color: black; }
|
||||
.text-gray { color: gray; }
|
||||
.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;
|
||||
}
|
Loading…
Reference in New Issue