minesweeper 0.4 → 0.4.1
raw patch · 3 files changed
+32/−23 lines, 3 files
Files
- Minesweeper.hs +3/−5
- Table.hs +27/−16
- minesweeper.cabal +2/−2
Minesweeper.hs view
@@ -79,13 +79,13 @@ onFocusOut window $ \_ -> do when' (isActiveTimer tim) $ do stopTimer True tim- doLater hideTableVar (1::Double) (setTableSt asp $ \s -> if s == Fixed then s else Stopped)+ doLater hideTableVar (1::Double) (stopTable asp) return False onFocusIn window $ \_ -> do when' (fmap not $ isActiveTimer tim) $ do cancelAction hideTableVar- setTableSt asp $ \s -> if s == Fixed then s else Normal Nothing+ resumeTable asp startTimer True tim return False @@ -227,12 +227,10 @@ withUState pst f = modifyMVarInSeparateThread (gstate pst) (\x -> f x >>= h) where h s@(g: gs, redos) = do adjustButts (table pst) (board g)- setTableSt (table pst) $ if isEnd g then const Fixed else ff+ setFixTable (table pst) (isEnd g) labelSetText (label pst) $ info g return s - ff (Normal x) = Normal x- ff _ = Normal Nothing ------------------- when' :: Monad m => m Bool -> m a -> m ()
Table.hs view
@@ -2,8 +2,9 @@ module Table ( GameTable , newTable- , St (Stopped, Normal, Fixed)- , setTableSt+ , stopTable+ , resumeTable+ , setFixTable , resizeTable , adjustButts , adjustButtsInc@@ -34,7 +35,7 @@ { size_ :: (Int, Int) , board_ :: Board , focusPos :: Place- , hidden :: St+ , workState :: St } data St @@ -74,19 +75,29 @@ getFocusPos :: GameTable -> IO Place getFocusPos g = fmap focusPos $ readMVar (states g) +stopTable g = setTableSt g $ \s -> if s == Fixed then s else Stopped+resumeTable g = setTableSt g $ \s -> if s == Fixed then s else Normal Nothing+setFixTable g b = setTableSt g f where+ + f _ | b = Fixed+ f Fixed | not b = Normal Nothing+ f x = x++ setTableSt :: GameTable -> (St -> St) -> IO () setTableSt g fx = redrawButts_ g f where f ss- | x == hh = ([], ss)- | Stopped `elem` [x, hh]+ | x == x' = ([], ss)+ | Stopped `elem` [x, x'] = (M.toList $ board_ ss, ss') | otherwise - = (map h $ focusPos ss: ff hh ++ ff x, ss')+ = ([(p, board_ ss M.! p) | p <- focusPos ss: ff x ++ ff x'], ss') where- ss' = ss { hidden = x }- h p = (p, board_ ss M.! p)- x = fx hh- hh = hidden ss+ ss' = ss { workState = x' }++ x = workState ss+ x' = fx x+ ff (Normal (Just x)) = [x] ff _ = [] @@ -100,7 +111,7 @@ { size_ = s , board_ = M.fromList $ zip (placeSetToList $ places s) $ repeat $ Hidden False Nothing , focusPos = place 1 1- , hidden = Normal Nothing+ , workState = Normal Nothing } win <- drawingAreaGetDrawWindow' g@@ -149,7 +160,7 @@ let size = size_ g m = board_ g- b = hidden g+ b = workState g pp = case b of Normal x -> x _ -> Nothing@@ -193,10 +204,10 @@ changeC n g = do ss <- readMVar (states g)- case hidden ss of+ case workState ss of Normal m -> do ss <- takeMVar (states g)- putMVar (states g) $ ss { hidden = Normal n }+ putMVar (states g) $ ss { workState = Normal n } if m /= n then redrawButts g $ catMaybes [m, n]@@ -211,7 +222,7 @@ b <- eventButton liftIO $ do ss <- readMVar (states g)- when (isNormal (hidden ss)) $ do+ when (isNormal (workState ss)) $ do n <- calcPos_ pos g case (n, b) of (Just p, LeftButton) -> reveal g p@@ -234,7 +245,7 @@ where moveFocus (dx, dy) = do ss <- readMVar (states g)- when (isNormal (hidden ss)) $ do+ when (isNormal (workState ss)) $ do ss <- takeMVar (states g) let foc@(coords -> (x, y)) = focusPos ss
minesweeper.cabal view
@@ -1,5 +1,5 @@ name: minesweeper-version: 0.4+version: 0.4.1 category: Game synopsis: Minesweeper game which is always solvable without guessing description: @@ -20,7 +20,7 @@ build-type: Simple executable minesweeper- ghc-options: -Wall -fno-warn-incomplete-patterns -fno-warn-name-shadowing+ ghc-options: -Wall -fno-warn-incomplete-patterns -fno-warn-name-shadowing -fno-warn-missing-signatures build-depends: base >= 3.0, containers, random,