Results 1 to 7 of 7
  1. #1
    newToJava3 is offline Member
    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    Default Ways of doing save for a java game

    Hi all,

    For my project for university I have created a game. I've just finished the game and it works fine its just I'm stuck on how to save the game as were not allowed to use javas serialization.

    Pretty much on my gui when a games started theres a save button and the current game can be saved when its clicked. There are alot of variables to be saved I was just asking for direction on the best way to structure this?


    My only ideas so far are to write every single variable needed on a line in a text file, then somehow read it back to objects when I implement the load later.

    Any guide in the right direction will be greatly appreciated,

    Thanks

  2. #2
    codesmuggler is offline Member
    Join Date
    Feb 2011
    Posts
    30
    Rep Power
    0

    Default

    You can serialize the state with the help of XML or .property file. You can also use XStream to make it more simpler.
    Last edited by codesmuggler; 02-12-2011 at 09:13 PM. Reason: typo.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    You can also use Object Serialization to store entire objects as binary files, and load them again later. The only catch is that every type used in your object (including the object itself) must implement the Serializable interface.

  4. #4
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    were not allowed to use javas serialization.
    @quad: The OP can't use serialization...

    You could probably use XML. If not, you'll have to use text or convert the variables to byte format that can be written out to files.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Oh whoops! Me and my silly spotty reading. My eyes must be getting ready to fall out of my head. :P

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    If you go the XML route, I recommend Simple 2.4.1.

  7. #7
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    Depends how you've structured your game.
    But essentially I'd just define a save file format.
    I doubt I'd even go the XML route (except as a learning exercise), simply because the overhead of XML will create a larger save file for little gain.

    JSON's a possibility.

Similar Threads

  1. Different ways of creating object
    By krashh205 in forum New To Java
    Replies: 1
    Last Post: 12-13-2010, 07:19 PM
  2. Need Help splitting up an Int in a variety of ways
    By JoKeR313 in forum New To Java
    Replies: 9
    Last Post: 11-10-2010, 06:22 AM
  3. ways to load JDBC driver
    By Riyaz.hk77 in forum Advanced Java
    Replies: 3
    Last Post: 11-06-2010, 05:53 PM
  4. ways to get input from console
    By soni in forum New To Java
    Replies: 2
    Last Post: 05-05-2008, 09:44 PM
  5. Displaying characters in many ways.
    By TampaTechGuy in forum New To Java
    Replies: 7
    Last Post: 01-02-2008, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •