0

I am making Pacman in Haskell Gloss. Now I am trying to Exit the game, once all the chips on the gameboard have been eaten by pacman. I have the function to check if that is the case, but I can't find a way to exit the game after that.

This is because I don't have a function that returns an IO a (because exitWith outputs that).

Here is the code of my Main.hs:

window :: Display
window = FullScreen

background :: Color
background = black

fps :: Int
fps = 5

main :: IO ()
main = playIO (InWindow "Pacman" (600, 600) (0, 0)) -- Or FullScreen
          background            -- Background color
          fps               -- Frames per second
          initialState     -- Initial state
          view             -- View function
          input            -- Event function
          step             -- Step function from controller

The playIO function has the following type signature:

playIO :: Display -> 
          Color -> 
          Int -> 
          world -> 
          (world -> IO Picture) ->
          (Event -> world -> IO world) -> 
          (Float -> world -> IO world) -> 
          IO ()

I might be overlooking something, but I would like to exit the loop of the playIO function once there is a winner. The following function might be of help:

exitWith :: ExitCode -> IO a

Any advice is greatly appreciated, I am still new to Haskell/Gloss.

ramon abacherli
  • 199
  • 2
  • 12
  • 2
    just call `exitWith` in `input` or `step` wherever you would check the condition, if all the chips have been eaten. `exitWith` is polymorphic in `a` an can be called in any `IO a` context, whatever `a` is. So `IO world` is ok. – typetetris Nov 06 '18 at 10:15
  • I actually tried that the first time, because I thought that too, and it didn't work then (I think it was a typo somewhere then). Now it works, thank you ;) – ramon abacherli Nov 06 '18 at 10:38

0 Answers0