Results 1 to 7 of 7
  1. #1
    skania is offline Member
    Join Date
    Jun 2013
    Posts
    15
    Rep Power
    0

    Default Select to stop a program, and then restart it at a later time at current location

    I've been tinkering with Java quiet a bit over the passed couple days, and I'm working on a basic, text-based game. I want the user to be able to choose to save and then load the game at a later time. However, I'm not sure how to make it work.

    The program currently runs in main, constructs the player, the text messages, NPCS, quests, and items. I have the code in place that it saves the file as "[playername].save" and in the file is the character's information (profession selection, inventory, etc) - already encrypted.
    So a character with the first quest started would save as:

    Filename: Harry.save
    1:Basic Hammer

    I have the code to decrypt it, but I'm not sure how to make it so the player can resume where they left off. So if there are 3 quests total, and he is done with the 2nd, how can I skip the first couple quests when the character is loaded.

    I originally thought adding a variable to the character file would suffice, and using an if/else if/else statement, or a switch, but it seems like that may be wrong.

    Does anyone have experience with this that has any advice? Thanks in advance!
    Last edited by skania; 06-19-2013 at 04:25 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: Select to stop a program, and then restart it at a later time at current location

    Without knowing how your code works (via an SSCCE) it's going to be pretty impossible to give you any specific help. How are your quests arranged programmatically?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    skania is offline Member
    Join Date
    Jun 2013
    Posts
    15
    Rep Power
    0

    Default Re: Select to stop a program, and then restart it at a later time at current location

    I basically just have the first quest in so far, I wanted to make sure I would be able to start up where I needed to when a player wants to load in. I was originally just going to have a quests object, and then have all the specifics in a method under the class Quests. I would then return an array of QuestName, QuestText, and QuestReward. So the quests would be called linearly from main.
    Java Code:
    	public static void main(String[] args) throws SQLException, InterruptedException {
    		System.out.println("Crafted Spirit is loading...");
    		String charactername = null;
    
    		@SuppressWarnings("unused")
    		String questRewardString  = null;
    ///////////////////////////////////////////////////////////////////////////////
    		/* Connect to the database */
    		try{
    			Class.forName("org.h2.Driver");
    			conn = DriverManager.getConnection("jdbc:h2:lib/bsg", "skania","----");
    		}
    		catch(ClassNotFoundException error){
    			System.out.println("Error: " + error.getMessage());
    		}
    ///////////////////////////////////////////////////////////////////////////////
    		/* Create the text messages that will be displayed to the user. */
    		TextMessages texts = new TextMessages();
    		System.out.println("Finished!\n");
    		try {
    			characterinformation = texts.loadSavedGame();
    		} catch (IOException e1) {
    			e1.printStackTrace();
    		}
    		System.out.println(characterinformation);
    		Thread.sleep(5000);
    		profSelection = texts.intro();
    
    		questRewardString = texts.professionintro(profSelection, conn);
    
    		charactername = texts.getName();
    		System.out.println("The character's name is" + charactername);
    		user = new Player(profSelection, charactername);
    		try {
    		SaveAndLoad.savegame(user);
    		}
    		catch (Exception e){
    			System.out.println("Error: " + e);
    		}

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: Select to stop a program, and then restart it at a later time at current location

    Split your program up into more modular pieces. Each quest can be a method or an Object. Then it'll be easier to choose between them.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    skania is offline Member
    Join Date
    Jun 2013
    Posts
    15
    Rep Power
    0

    Default Re: Select to stop a program, and then restart it at a later time at current location

    I have it set up so that each quest is a method under the Object "Quests". I have no problem being able to choose them, I just need to figure out how to skip ahead in the program to where the play left off.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: Select to stop a program, and then restart it at a later time at current location

    Can't you just have a variable that holds the current quest number, then a method that uses that number to call the appropriate quest function?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    skania is offline Member
    Join Date
    Jun 2013
    Posts
    15
    Rep Power
    0

    Default Re: Select to stop a program, and then restart it at a later time at current location

    Thank you! I was having tunnel vision on the switch or if statements. I'm going to try to implement this.

Similar Threads

  1. Replies: 5
    Last Post: 02-29-2012, 10:07 AM
  2. Replies: 10
    Last Post: 04-21-2011, 01:47 PM
  3. need help with getting current time in Millis
    By Clerek in forum New To Java
    Replies: 11
    Last Post: 01-26-2011, 05:50 AM
  4. Current Time in millisecs
    By jitman in forum New To Java
    Replies: 1
    Last Post: 03-11-2010, 05:16 PM
  5. how to get the current date and time
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 06:05 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
  •