Search code examples
java2ddata-storage

How to save map data in a tilebased game


I have a bit of a rookie question regarding storage of map data i a java game. I'm making a 2d tile-based game, where each tile has an id (1, 2, 3, 4 and so on...). I currently store the game data in a .txt file, where each number is seperated by a tab. Therefrom i read it via scanners .nextInt.

This method works fine, but it seems to give me a problem:

  • Since the level file is just a normal .txt file it is easily edited by anyone. This means that the user could just change a few numbers in the file with any kind of text editor and thereby easily cheat.

How would this be avoided? Should i store the map data differently or should i use some form of encryption?


Solution

  • One solution to this would be to store the data in a database, such as derby. Once the game has been exported as a jar file the casual player will never even see the file, and if they do get their hands on it, probably wouldn't know what to do with it.

    Here is a nice tutorial on how to set up and connect to a simple derby database.

    http://www.vogella.com/tutorials/ApacheDerby/article.html

    good luck.