Skip to content
Permalink
Browse files

Allow Saving of Game State

  • Loading branch information...
jhb563 committed May 3, 2019
1 parent f62a82d commit f15d3f8e773e3e7216bb5d4872fb42ce9f4af7b6
Showing with 15 additions and 4 deletions.
  1. +2 −0 MazeGame.cabal
  2. +2 −2 src/Runner.hs
  3. +11 −2 src/WorldParser.hs
@@ -42,11 +42,13 @@ library
, aeson
, array
, containers
, directory
, gloss
, megaparsec
, mtl
, random
, text
, time
default-language: Haskell2010

executable maze-game
@@ -13,8 +13,7 @@ import Graphics.Gloss.Interface.IO.Interact
import MazeParser (generateRandomMaze, sampleMaze)
import MazeUtils (getAdjacentLocations, getShortestPath)
import Types

import Debug.Trace
import WorldParser (unsafeSaveWorldToFile, loadWorldFromFile)

windowDisplay :: RenderParameters -> Display
windowDisplay rp = InWindow "Window"
@@ -168,6 +167,7 @@ inputHandler event w
, worldEnemies = stunEnemyIfClose <$> worldEnemies w
, stunCells = stunAffectedCells
}
(EventKey (Char 's') Down _ _) -> unsafeSaveWorldToFile w
_ -> w
where
playerParams = playerGameParameters . worldParameters $ w
@@ -1,11 +1,20 @@
module WorldParser where

import Data.Aeson
import Data.Time.Clock.POSIX (getPOSIXTime)
import System.Directory (getCurrentDirectory)
import System.IO.Unsafe (unsafePerformIO)

import JSONInstances ()
import Types

loadWorldFromFile :: FilePath -> IO World
loadWorldFromFile = undefined

saveWorldToFile :: World -> FilePath -> IO ()
saveWorldToFile = undefined
unsafeSaveWorldToFile :: World -> World
unsafeSaveWorldToFile w = unsafePerformIO $ do
timeAsString <- show . floor <$> getPOSIXTime
currentDir <- getCurrentDirectory
let filename = currentDir ++ "/maze_game_save_" ++ timeAsString
encodeFile filename w
return w

0 comments on commit f15d3f8

Please sign in to comment.
You can’t perform that action at this time.