minesweeper-0.9: Transition/Graphics.hs
{-# LANGUAGE PatternGuards #-}
module Transition.Graphics where
import State
--import Configuration
import Preferences
import Table
import State.Functions
import Event
import Core.Square
-------------------------------------------------------------
squareState :: State -> Square -> SquareState
squareState st p
| (r:_) <- revealing st
, p == revSquare r
, Just i <- busyAnimation r
= BusySign focused prelight i
| Just h <- hint st
, Just max <- maxHiddenProb_ g
, Just x <- probability p g
, h == FullHint || x == max || x == 0 || marked'
= (if marked' then HintedBomb else Hint) focused prelight x
| marked'
= Bomb focused prelight
| Just Nothing <- revealed
= Death
| Just (Just i) <- revealed
= if hiddenTable st then HiddenSign else Clear focused i dangerousness
| otherwise
= NoSign focused prelight
where
g = game st
focused = p == focus st && focusMoves st
prelight = maybe False (== p) (mouseFocus st) && mouseFocusShown st
revealed = revealResult g p
marked' = isMarked p g
dangerousness = head $ [x | (q,x)<-redness st, q==p] ++ [0]
getInfo st
| cAndG playerWins st = InfoWin $ luck $ game st
| aliveness (game st) == 0 = InfoLoose True
| cAndG isFinished st = InfoLoose False
| otherwise = InfoPlay (cAndG mines_left st) (cAndG information st) (luck $ game st)
getTimeInfo st
| Just t <- timer st = TimerAt t
| isNew st = TimerInit
| otherwise = TimerStopped