Applicative functions

This commit is contained in:
Sam Tay 2017-06-17 20:39:40 -04:00
parent 349022a7cc
commit 80e71eb859

View file

@ -13,6 +13,7 @@ import Lens.Micro.TH
import System.Random (getStdRandom, randomR) import System.Random (getStdRandom, randomR)
import Prelude hiding (Left, Right) import Prelude hiding (Left, Right)
import Data.Bool (bool)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Data.Monoid (First(..)) import Data.Monoid (First(..))
@ -161,11 +162,11 @@ isGameOver :: Game -> Bool
isGameOver g = blockStopped g && g ^. block ^. origin == startOrigin isGameOver g = blockStopped g && g ^. block ^. origin == startOrigin
timeStep :: Game -> IO Game timeStep :: Game -> IO Game
timeStep g = if (blockStopped g) timeStep =
then stopUpdater g bool
else return . gravitate $ g <$> (return . gravitate) -- if not stopped
where <*> nextBlock . updateScore . clearFullRows . freezeBlock -- if stopped
stopUpdater = nextBlock . updateScore . clearFullRows . freezeBlock <*> blockStopped -- predicate
-- TODO check if mapKeysMonotonic works -- TODO check if mapKeysMonotonic works
clearFullRows :: Game -> Game clearFullRows :: Game -> Game