Saving map & player data in a 2d tilebased game

Greetings everyone.
I’m currently making a simple 2d tile based game engine in java. My map is stored as an array of tiles ingame and I am looking for good ways to save this data to a file. I have considered the following:

  • Saving to a text file by tile ID. This has the weakness of being easily edited by the player.
  • Serializing. From what i’ve heard this is easily broken if any changes are made.

My questions are: What would be a good way to store data(like the tilemap) in a file? Could any of the listed problems be avoided?
Any suggestions and help for a rookie like me will be greatly appreciated.

Hi

I don’t know if this would work for your purposes, and it would be hard to maintain, but you could try to find some way to use the Java Preferences API, or just encrypt the files including a key every line that if modified would corrupt / reset the file :slight_smile:

Just my thoughts :slight_smile:

CopyableCougar4

If you have serialize-to-text already working, it would be simple to simply use binary sequences (of your own design) instead of characters, utilizing the appropriate [Data]Inputstream/Outputstreams instead of Reader/Writers.

Or you can just compress the files with something like DeflaterOutputStream or GZIPOutputStream and use a non-standard file extension, perhaps even with a few bytes of ‘salt’ ahead of the actual data to foil naive attempts at accessing the files.

Either of these will deter 90.8+% of people who would want to modify the files, which is really the best you can do. There may be fool-proof methods, but there is no perfect method.

[quote=“Magn,post:1,topic:49840”]
Arguably a strength not a weakness :slight_smile: If you get players who like the game enough to want to mess around with the maps that’s a nice problem to have!

Also sticking with straightforward text format is easier to debug because you can read/edit it yourself. You can always whack some encryption on later with very little code change.

[quote=“richierich,post:4,topic:49840”]

Touché :slight_smile:

Thank you! I think this is the path I’m going to take :slight_smile: