haskanoid icon indicating copy to clipboard operation
haskanoid copied to clipboard

State passing between levels

Open madjestic opened this issue 6 years ago • 1 comments

gameWithLives :: Int -> Int -> Int -> SF Controller GameState
gameWithLives numLives level pts = dSwitch
  -- Run normal game until level is completed
  (gamePlayOrPause numLives level pts >>> (arr id &&& isLevelCompleted))

  -- Take last game state, extract basic info, and load the next level
  (\g -> let level' = level + 1
             lives' = gameLives  $ gameInfo g
             pts    = gamePoints $ gameInfo g
         in runLevel lives' level' pts)

Is there a reason, why state-passing is done with 3 explicit arguments, instead of packing them into a state-holding datatype?

For instance, can we not, instead of this:

gameWithLives :: Int -> Int -> Int -> ...

Have this?:

gameWithLives :: GameState ->...

madjestic avatar Jun 16 '18 07:06 madjestic

Hi Vladmir,

thanks for the suggestion. The reason is very simple. The code grew over time and could be cleaned. So you are absolutely right---these three values could be stored together in a type. However, it should not be GameState since there already exists a data type GameState which is more than these three values (gameObjects, gameStatus).

I haven't found a good name yet. It could be something like startingValues, initialValues, ... I don't like the word 'values'. Any suggestions? So let's come up with a reasonable name and if you want, send us a pull request. We highly welcome any suggestions and new ideas to improve the game.

Best, Christina

chriz-zeller avatar Jun 18 '18 08:06 chriz-zeller