Overview
I created a 2-player board game using Play Framework 2.5. For now, users can only play it locally against each other.
Implementation details
Whenever the users start a new game, an AJAX request is sent to the server, which in turn creates a Game
object, which is a model of the game and keeps track of the state of the game.
Whenever the user interacts with the game in browser, the AJAX request is sent to the server, which in turn updates (existing) Game
object, calculates some things (using Game
object) and sends the response back to the client (client game state is updated).
For every user that is playing the game, I store the Game
objects in memory (no database storage implementation (yet?)), more specifically, in a java HashMap
.
Question
How should I go about storing the game state, in order for the game to be responsive? How people usually implement the backend/storage/models in similar games?
So far
I was thinking about implementing database and storing necessary data in there instead of explicitly creating objects, however it seems to me that it will take too long to query the data from database, format it properly and calculate new state (assuming there are a lot of players).
Another option would be to serialize the Game
objects to a byte array and store in the database, then it will require querying and deserialization, therefore it also seems pretty slow (assuming there are a lot of players).
Aucun commentaire:
Enregistrer un commentaire