Reputation: 795
I wish to be able to keep a score that a player gets when playing my game from game to game and to when they close the game and re-open the scores are still saved. The only way I can think of is to do so using a text file, like I would of done in VB6. However, that then means that they can edit the text file? Or not? My score is stored in a "double" that can be accessed from any class and is being transferred around classes as it is, if that makes a difference.
Hope someone can suggest the best way to go about this.
Upvotes: 0
Views: 269
Reputation: 16060
What have you tried? It seems to be some kind of homework for me.
You can read and write Files with Java. You can also do object-serialization or use an embedded database.
update: I would suggest to store all information within a database at the server. There are many way to do this. The concrete implementation would depend in your backend.
Upvotes: 0
Reputation: 168825
Any app. that has a GUI can be launched using Java Web Start & use the PersistenceService
. Data in the persistence service is not easily accessible to the end user. Here is a small demo. of the persistence service.
As to how to store the data, If it is not absolutely vital to prevent the user from altering it, I would use a Properties
object or XML/POJO.
If it is very important (e.g. gamers competing for a $10,000 prize), encrypt the values, then go with the remote server, encrypted (etc.).
Upvotes: 1
Reputation: 29922
If you store the file on the local machine, obviously every user that have read/write permissions on that file could modify it.
I suggest you to follow one of these ways
Upvotes: 0
Reputation: 6105
If keeping the score secret and non editable is very important, I suggest you either store the score on of all players a secure server that only you control, or if that is outside the scope of your project, use an encryption method and also store the score as binary data (i.e. store your gamestate object, not the score itself) instead of a text file.
Upvotes: 1
Reputation: 32286
You can encrypt the file using one way or another, so it will not be easily editable (and editing attempts may corrupt the score at all, consequently.) Here is a simple example of AES string encryption.
Upvotes: 0