Results 1 to 5 of 5
  1. #1
    paris72 is offline Member
    Join Date
    Apr 2012
    Posts
    6
    Rep Power
    0

    Default how to save and load and pause a game ?

    I'm working on a game and I need to save and load and pause it .
    I search but I run out of time so I need some good and easy examples of this .
    I would be really thankful if somebody helps me .
    by the I have a map that consists of 0 , 1 , 2 so I have to save that too.

  2. #2
    paris72 is offline Member
    Join Date
    Apr 2012
    Posts
    6
    Rep Power
    0

    Default Re: how to save and load and pause a game ?

    I found out the answer myself . I saved the map that is a 2D array in a file line by line by the following code :
    public void save() {
    File f1 = new File("savedmap.txt") ;
    FileOutputStream fos ;
    try {
    fos = new FileOutputStream(f1) ;
    PrintStream ps ;
    ps = new PrintStream(fos) ;
    for (int i = 0 ; i < 20 ; i++) {
    for (int j = 0 ; j < 19 ; j++) {
    ps.print(map[i][j]) ;
    }
    ps.println(map[i][19]) ;
    }
    ps.close() ;
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

  3. #3
    mrguy is offline Member
    Join Date
    Jul 2012
    Posts
    27
    Rep Power
    0

    Default Re: how to save and load and pause a game ?

    I did much of the same thing.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: how to save and load and pause a game ?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    165
    Rep Power
    2

    Default Re: how to save and load and pause a game ?

    For the pausing I recommend making states for your game and storing them in a stack. That way you can push() and pop() off the different states, including the pause state.

Similar Threads

  1. Save/Load ArrayList
    By chielt in forum New To Java
    Replies: 3
    Last Post: 05-08-2011, 06:12 PM
  2. Vector load/save with swing
    By petosiso in forum AWT / Swing
    Replies: 0
    Last Post: 04-20-2011, 08:14 AM
  3. Load and Save images
    By shakeel in forum Java 2D
    Replies: 13
    Last Post: 12-29-2010, 06:38 PM
  4. Arraylist Save and Load
    By frankycool in forum Advanced Java
    Replies: 1
    Last Post: 11-14-2009, 10:29 PM
  5. save will work but load wont?!?!
    By Sticks_ll in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 04:19 AM

Posting Permissions

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