Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State passing between levels #69

Open
madjestic opened this issue Jun 16, 2018 · 1 comment
Open

State passing between levels #69

madjestic opened this issue Jun 16, 2018 · 1 comment

Comments

@madjestic
Copy link

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 ->...
@chriz-zeller
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants