Skip to content

Instantly share code, notes, and snippets.

@tarquin-the-brave
Created May 12, 2020 13:25
Show Gist options
  • Select an option

  • Save tarquin-the-brave/1b14fd8bbe3f1d2142a75092c5e4edc6 to your computer and use it in GitHub Desktop.

Select an option

Save tarquin-the-brave/1b14fd8bbe3f1d2142a75092c5e4edc6 to your computer and use it in GitHub Desktop.
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