Created
May 12, 2020 13:25
-
-
Save tarquin-the-brave/1b14fd8bbe3f1d2142a75092c5e4edc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Monad.State.Lazy (state, StateT) | |
| import Control.Monad.IO.Class (liftIO) | |
| import System.Console.ANSI (cursorUp) | |
| playGame :: [Int] -> StateT Game IO Int | |
| playGame inp = do | |
| liveData <- stepGame inp | |
| game <- get | |
| -- | |
| -- Display the game state in a grid to stdout | |
| -- | |
| let grid = gridDisplay $ gameDisplay game | |
| _ <- liftIO $ mapM print grid | |
| liftIO . print $ ("Your score: " ++ show (sc liveData)) | |
| liftIO . cursorUp $ (length grid) + 1 | |
| case IC.progState (gameProg game) of | |
| IC.AwaitInput -> playGame [joystick (xb liveData) (xp liveData)] | |
| _ -> return $ sc liveData | |
| stepGame :: [Int] -> StateT Game IO LiveData | |
| stepGame = state . stepGame' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment