Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Saving and reloading game state from a remote server  (Read 1242 times)
0 Members and 1 Guest are viewing this topic.
Offline cookie

Junior Member


Medals: 1



« Posted 2013-05-01 17:42:18 »

Hello,
I would like to save the state of the game to reload it later. I have found some approaches, but I don't know which is best. Of course I can't save the state of the JVM, so I have to save the state of all objects. How could this be done?
Offline alaslipknot
« Reply #1 - Posted 2013-05-01 18:24:38 »

i'll give you a quick example, then you should be able to apply it to the rest of your game
suppose your whole game  is a square that move with arrow keys,
your start at x = 0 , y = 0 ;
during the game, you moved a little bit to the right,
so let's say
x = 150, y=0
now you want to quit and save your game,
you just have to write the x value in a text or a binary file
then when you re-open the game, you check if the text file contain x or y value, and you apply it to your current x and y

so in the end, saving and loading, are just 2 methods, the one write your values in a file, and the other read values from the file and apply each one to the correct object

good luck

PS :
am not sure you're posting in the correct section

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Offline cookie

Junior Member


Medals: 1



« Reply #2 - Posted 2013-05-01 18:43:51 »

Thanks. You are right, that's not the right section, but I understood "design" in terms of software architecture and not graphical appearance.

I know which data to save, but I don't know how to persist this data. I could write it to a XML file, text file or some other file, but I don't know which way is the best. Maybe I should use java.io.Serializable?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mac70
« Reply #3 - Posted 2013-05-01 18:53:56 »

As far as I know Serializable is the best choice for save/load - I did some tests and it works perfectly in any case. Wink

Check out my Devblog! Smiley
Offline cookie

Junior Member


Medals: 1



« Reply #4 - Posted 2013-05-01 19:06:01 »

Good. Then I know what to focus on. Should I collect the data from all classes that contain information that should be saved or should I copy all relevant data into some kind of game state class?
Offline alaslipknot
« Reply #5 - Posted 2013-05-01 20:03:02 »

Good. Then I know what to focus on. Should I collect the data from all classes that contain information that should be saved or should I copy all relevant data into some kind of game state class?
you're not gonna be writing into your file from the start to the end of the game and i think you can find the proper way by trying and testing what's works best for you  Roll Eyes 

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Offline cookie

Junior Member


Medals: 1



« Reply #6 - Posted 2013-05-05 09:29:32 »

XML works great, but I don't know how I could store it securely on a remote server.

With my limited experience, I would do it like this:
On the server side I would limit the access to the XML file only to specific IP addresses and on the client side I would encrypt the XML file before it is uploaded to the server. However, I don't know if that's the best way to get it done.
Offline nerb
« Reply #7 - Posted 2013-05-06 10:12:42 »

XML works great, but I don't know how I could store it securely on a remote server.

With my limited experience, I would do it like this:
On the server side I would limit the access to the XML file only to specific IP addresses and on the client side I would encrypt the XML file before it is uploaded to the server. However, I don't know if that's the best way to get it done.

Do you need to encrypt it at all? Correct me if I'm wrong, but essentially it is a game save? Providing there isn't any sensitive information contained in it (passwords, contact information, credit cards etc.) I wouldn't stress about encryption, at least from client to server.

Or are you worried about people getting in and modifying it while its on the server? In that case yes, you should certainly limit who & what can access your data/databases, and it should be standard practice. Otherwise you will find all kinds of nasty things happening when you aren't looking, such as your data disappearing completely. But once again I wouldn't panic about encryption, as people should be stopped from accessing it well before encryption comes in to play.

If however you do need to encrypt it for whatever reason, there are a few things to keep in mind. (This is a topic and field of study of its own, of which I know bugger all, but others on here might). If people have access to your client-side application, there is nothing stoping them from decompling it, wading through obfuscation if present, and nutting out your encryption method, and ultimately decoding your file. If the encryption is weak, it will just slow them down a bit. As such you should consider encrypting it again on the server prior to storage, using a different key or method (with the expense of extra performance overhead). You should also be thinking towards using SSL for transmitting the data if it is sensitive, to prevent interception.

But before you do anything like that, consider if 1) Would people would want to intercept & decode the file in the first place, and 2) what are the consequences if they did?

nerb.
Offline SHC
« Reply #8 - Posted 2013-05-06 13:35:46 »

I have a few questions about how you want to save. (loading is fine).

  • Save the whole game like the current map and the positions of each and every object?
  • Just save the current map number? (Most games do this)

If you are going to save the whole map state, then serialization is the best option. But I strongly recommend the second one. Just save the map number to a file and read it when you want to load your game.

As a side note, if I was playing a game and am I just going to lose some health, I save the game and closes it. I prefer to play from the first of the level again but if I was playing a game in which the saving is implemented in serialization, when I reload the game, I'll again fall and lose health.

I like the latter option and it's much easier too.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (36 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (41 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (60 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (35 views)
2014-09-21 00:26:15

UprightPath (48 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!