ricardoboss / Prolangle

A game about programming languages.
https://prolangle.ricardoboss.de
MIT License
2 stars 1 forks source link

Persist game history in local storage. Partially implements #22 #42

Closed chucker closed 9 months ago

chucker commented 9 months ago

This partially implements #22.

This splits GuessGame and PlayedGame (not sure about the name; it's used for both currently played games and previously played games), so that the former can be async and the latter can be serialized. Arguably, GuessGame is a controller, and PlayedGame a model.

It then stores games in local storage, which guesses have been made vs. what the target is, and finally whether the game has been won:

image

The idea behind storing TargetLanguageId is to recover, later on, whether it's the same game. This probably isn't a foolproof way. I'm not sure how we want to distinguish game "IDs"; perhaps by seed?

ricardoboss commented 9 months ago

Game ID's could be seeded the same way the GuessGame currently chooses a target language: it gets a seeding function injected in its constructor and seeds a PRNG to randomly select a language from all available. The game ID could just be 16 random bytes interpreted as UUID.

ricardoboss commented 9 months ago

I'm honestly not sure if I really want to keep the GuessGame. This was never meant to be built upon and was just prototyping what could work.

What we could do now:

What do you think?

edit: see also #2

ricardoboss commented 9 months ago

Also, why only partially? It'd say this fixes #22.

chucker commented 9 months ago

Also, why only partially? It'd say this fixes #22.

Chiefly because it doesn't provide an answer to "so you can continue later with the same state." Like, if this implementation is a bad approach to make that possible later, then…

chucker commented 9 months ago
  • Rename GuessGame to LanguageChooser (or sth like that)

GameController? (Pun intended.)

Or GameInitializer, perhaps. But if we name it that, then GuessAsync() should probably move to GameInstance.

  • Rename PlayedGame to GameInstance and make it the base class for all possible game modes. It may keep track of the target language, guesses made and some other metadata not related the any specific game mode

Sure.

ricardoboss commented 9 months ago

Or GameInitializer, perhaps.

Agreed.

chucker commented 9 months ago

GuessAsync() should probably move to GameInstance.

I'm not really sure about this change.

chucker commented 9 months ago

…no I didn't?