Answer the question
In order to leave comments, you need to log in
What is the best way to implement saving the state of a turn-based game?
There was a desire to write a simple turn-based game and almost immediately the question of saving the state arose. The current state of the game is described by a set of java objects that are interconnected and have internal fields.
When saving, it is important to pack all these objects and links so that they can be restored upon loading.
So far I see only two options
1) Sql DB in which tables objects, links are added and when loading everything is pulled from the DB.
Obvious disadvantages - the complexity of maintaining different versions, you can not just delve into the saves with a text editor.
2) XML. You can dig through the editor, it's easier with support for different versions, but it's not clear how to store links between objects if A refers to B and B refers to A.
If anyone has any experience with this or just thoughts on this topic, please share.
Answer the question
In order to leave comments, you need to log in
For simplicity, serialize Java objects and store them in sqlLite, which in turn is "sewn" into the project.
Pros :
Ease of storage
Resource consumption (does not require the deployment of a DBMS)
Development speed (no need to write java - subd - cell mapping)
Cons :
Performance (but this is not critical for storing states)
And how many "states" should be stored?
Or maybe you need an Ikea box, and not a robotic warehouse complex.
I mean, can write json to a file?
XML in our age looks like a crutch for such purposes. Of course, use a DB.
You can dig into the database and it's very simple. There is a lot of software, and if you use mysql, then different phpmyadmin.
When you grow up, switch to cloud databases ala https://parse.com/ (although you can familiarize yourself with them now).
Version support with a competent structure is not a question at all.
Do not be afraid of the database. Just find your way to them. They are not as difficult as they seem. Select, update, delete, insert are all the commands you'll need. Then there is the issue of structure.
If you are planning your own server, start learning django - there you can almost automatically generate any database. Otherwise, look towards cloud databases (wrote above) - even a householder will figure out how to create a database in them. The rest is up to your client.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question