Making an RPG, need to know the most efficient way to Save/Load

Okay well. I'm in a programming class at the moment, and I've been trying to make an RPG because that's what I've wanted to do since I got in the class.
Some people have been trying it out a bit, though it's still very...young, I suppose. Those people testing said, "Man, I wish I could save my game or something". And I said, "Yea, I know, I've been thinking about it". So at this point I'm thinking that I should find out how to do it and do it already.
So what I'm trying to say is, I would really appreciate it if someone would be able to help me find the best way to implement saving and loading within my game. It's all text-based, and probably going to stay like that for a while.
I'm going to post the code so I can hear other suggestions relating to how I could make my code better, any help will be seriously appreciated.
// Main Class
// I'll put this in in a separate post, I can't fit all the code in one ^_^
// Character Class
// I'll post this in the next post as well -_-
// Player Class
public class Player extends Character implements Cloneable
    // MEMBER DATA
    private String name = "";
    private int health = 100;
    private int maxHealth = 100;
    private int attack = 2;
    private int defense = 0;
    private int speed = 0;
    private Equipment Weapon;
    // CONSTRUCTORS
    public Player()
    public Player(String n, int h, int mH, int a, int d, int s)
        name = n;
        health = h;
        maxHealth = mH;
        attack = a;
        defense = d;
        speed = s;
    public Player(String n, int h, int mH, int a, int d, int s, Equipment w)
        this(n,h,mH,a,d,s);
        Weapon = w;
    // ACCESSOR METHODS
    public int getHealth()
        return health;
    public int getAttack()
        return attack;
    public int getDefense()
        return defense;
    public int getSpeed()
        return speed;
    public Equipment getWeapon()
        return Weapon;
    // MUTATOR METHODS
    public void setWeapon(Equipment wep)
        Weapon = wep;
    // OVERRIDE METHODS
    public String toString()
        String out = "";
        out += "Name " + name;
        out += "\n Health " + health + "/" + maxHealth;
        out += "\n Attack " + attack;
        out += "\n Defense " + defense;
        out += "\n Speed " + speed;
        out += "\n Weapon Equipped: " + Weapon;
        out += "\n ";
        return out;
    public boolean equals()
        boolean outcome = false;
        if (attack == attack && defense == defense && speed == speed && health == health && Weapon == Weapon && name == name)
         {outcome = true;}
         return outcome;
    // OTHER METHODS
    // IMPLEMENTED INTERFACES
    public Object clone()
        return new Player(name,health,maxHealth,attack,defense,speed,Weapon);
// Enemy Class
public class Enemy extends Character implements Cloneable
    // MEMBER DATA
    private String name = "";
    private int level = 1;
    private int health = 100;
    private int maxHealth = 100;
    private int attack = 2;
    private int defense = 0;
    private int speed = 0;
    private int exp = 0;
    // CONSTRUCTORS
    public Enemy()   // washed up rapper group.
    public Enemy(String n, int l,int h, int mH, int a, int d, int s, int e)
        name = n;
        level = l;
        health = h;
        maxHealth = mH;
        attack = a;
        defense = d;
        speed = s;
        exp = e;
    // ACCESSOR METHODS
    //MUTATOR METHODS
    // OVERRIDE METHODS
    public String toString()
        String output = "";
        output += name;
        output += "\n Health: " + health + "/" + maxHealth;
        output += "\n Attack Stat: " + attack;
        output += "\n Defense Stat: " + defense;
        output += "\n Speed Stat: " + speed;
        output += "\n ";
        return output;
    public boolean equals()
        boolean outcome = false;
        if (attack == attack && defense == defense && speed == speed && health == health && name == name)
         {outcome = true;}
         return outcome;
    // OTHER METHODS
    // IMPLEMENTED INTERFACES
    public Object clone()
        return new Enemy(name,level,health,maxHealth,attack,defense,speed,exp);
//Equipment Class
public class Equipment
    // MEMBER DATA
    private String name = "None";
    private int atk = 0;
    private int def = 0;
    private int spd = 0;
    //CONSTRUCTORS
    public Equipment(String n, int a, int d, int s)
        name = n;
        atk = a;
        def = d;
        spd = s;
    // ACCESS MODIFIERS
    public String getName()
        return name;
    public int getAtk()
        return atk;
    public int getDef()
        return def;
    public int getSpd()
        return spd;
    // MUTATOR METHODS
    public void setName(String nam)
        name = nam;
    public void setAtk(int a)
        atk = a;
    public void setDef(int d)
        def = d;
    public void setSpd(int s)
        spd = s;
    // OVERRIDE METHODS
    public String toString()
        String output = "";
        output += "\n";
        output += "\n" + name;
        output += "\n Weapon Attack: " + atk;
        output += "\n Weapon Defense: " + def;
        output += "\n Weapon Speed: " + spd;
        return output;
    public boolean equals(Object o)
        Equipment rS = (Equipment)o;
        return (atk == rS.atk && def == rS.def && spd == rS.spd && name == rS.name);
    // IMPLEMENTED INTERFACES
    public Object clone()
        return new Equipment(name,atk,def,spd);
// Item Class
public class Item
    private String name;
    private String descrip;
    private int price;
    private boolean usable;
    public Item()
    public Item(String nam, String des, int prc, boolean usa)
        name = nam;
        descrip = des;
        price = prc;
        usable = usa;
// Inventory Class
public class Inventory
    public Item item;
    public int amount;
    public Inventory()
    public Inventory(Item itm, int amt)
        item = itm;
        amount = amt;
}I also have an IO class to make input to the console less strenuous, I'll post that if it's really needed.
Many thanks! :D

Ok, My Main class is too long to fit on one post. I will send everyone that posts here with help for the Save/Load portion of this topic the Main Class, and I will just put the Character class by itself.
// Character Class
import java.util.Random;
public class Character
    // Member Data
    private String name = "";
    private int level = 1;
    private int health = 20;
    private int maxHealth = 20;
    private int attack = 2;
    private int defense = 0;
    private int speed = 0;
    private int exp = 0;
    private int toNextLevel = 0;
    private Random rnd = new Random();
    // CONSTRUCTOR
    public Character()
    public Character(String n, int l, int tNL, int h, int mH, int a, int d, int s, int e)
        name = n;
        level = l;
        toNextLevel = tNL;
        health = h;
        maxHealth = mH;
        attack = a;
        defense = d;
        speed = s;
        exp = e;
    // Accessor Methods
    public String getName() //Returns Name
        return name;
    public int getLevel() //Returns Level
        return level;
    public int getHealth() //Returns Health
        return health;
    public int getMaxHealth() //Returns maxHealth
        return maxHealth;
    public int getAttack() //Returns Attack
        return attack;
    public int getDefense() //Returns Defense
        return defense;
    public int getSpeed() //Returns Speed
        return speed;
    public int getExp() //Returns Exp
        return exp;
    public int getNextLevel()
        return toNextLevel = (health + level + attack + defense + speed); //Used to attain the Player's new next level by summing stats
    public String getStats() //Used to show the Player's stats when the menu option "Stats" is chosen
        String sts = "";
        sts += "Name: " + name + "\n";
        sts += "Level: " + level + "\n";
        sts += "Health: " + health + "/" + maxHealth + "\n";
        sts += "Attack: " + attack + "\n";
        sts += "Defense: " + defense + "\n";
        sts += "Speed: " + speed + "\n";
        sts += "Exp: " + exp + "\n";
        sts += "To Next Level: " + toNextLevel + "\n";
        return sts;
    // Mutator Methods
    public void setName(String nam) //Sets Name
        name = nam;
    public void setLevel(int lvl) //Sets Level
        level = lvl;
    public void setHealth(int hp) //Sets Health
        health = hp;
    public void setMaxHealth(int mhp)
        maxHealth = mhp;
    public void setAttack(int atk) //Sets Attack
        attack = atk;
    public void setDefense(int def) //Sets Defense
        defense = def;
    public void setSpeed(int spd) //Sets Speed
        speed = spd;
    public void setStats() //Used to set the Player's stats after a level up
        if (health >0)
          health = maxHealth;
          maxHealth += rnd.nextInt(4) + 2;
          attack += rnd.nextInt(4) + 2;
          defense += rnd.nextInt(4) + 2;
          speed += rnd.nextInt(4) + 2;
          toNextLevel = (this.initNLevel());
    public int initNLevel() //Decides the player's new toNextLevel based on the Player's new leveled up stats
        int nL = (maxHealth + level + attack + defense + speed);
        return toNextLevel = nL;
    public int setNextLevel(int next) //Used to get the Player's next toNextLevel amount
        return toNextLevel = next;
    public void levelUp() //Method used to level up the Player
        level++;
    public int toNext(int exp) //Sets the exp needed to level up
        return toNextLevel - exp;
    public void beginStat(String n, int l,int h, int mH, int a, int d, int s, int e)
        name = n;
        level = l;
        health = h;
        maxHealth = mH;
        attack = a;
        defense = d;
        speed = s;
        exp = e;
    // OVERRIDING METHODS
    public String toString()
        String out = "";
        out += "Name " + name;
        out += "\n Health " + health + "/" + maxHealth;
        out += "\n Attack " + attack;
        out += "\n Defense " + defense;
        out += "\n Speed " + speed;
        out += "\n Exp " + exp;
        return out;
    // FIGHT METHODS
    public void hit(Character e,int d) //The method used to attack another Character object (Player or Enemy)
        int dmg = d;
        e.health -= (dmg > e.defense) ? (dmg - e.defense) : 0;
        /**int dmg = this.getAttack();
        *this.setAttack(dmg);
        e.health -= (dmg > e.defense) ? (dmg - e.defense) : 0;*/
    public void heal() //The method used to heal during battle
        double healBy = maxHealth * .50;
        if ( (healBy + health) > maxHealth)
            health += (maxHealth - health);
        else
            health += healBy;
    // OTHER METHODS
    public void defend1() //Battle command to double defense, and return defense to normal after the turn is over
        defense *= 2;
    public void defend2()
        defense /= 2;
    public void gainExp(int e) //Method to give the Player exp after defeating an enemy
        exp += e;
    public void setEXp() //Sets the enemy's exp
        int xp = (maxHealth + level + attack + defense + speed);
        exp = xp;
    public void initEStat() //Sets the Enemies Stats w/ random numbers varying on the enemy's level
        health = rnd.nextInt((level*15)) + (level*15) -4;
        maxHealth = health;
        attack = rnd.nextInt((level*5)) + (level*5) -4;
        defense = rnd.nextInt((level*5)) + (level*5) -4;
        speed = rnd.nextInt((level*5)) + (level*5) -4;
        toNextLevel = (this.initNLevel());
    // IMPLEMENTED INTERFACES
    public Object clone()
        return new Character(name, level, toNextLevel, health, maxHealth, attack, defense, speed, exp);
}

Similar Messages

  • What's the most efficient way to serve a file from a servlet?

    I have a servlet that does various different things depending on the needs. Sometimes it dynamically generates content, and sometimes all it does is send a file out, with no alteration.
    What is the most efficient way to just send a file?
    One option:
    OutputStream os = response.getOutputStream();
    InputStream is = new FileInputStream(...)
    (send all the bytes from is to os, the regular way using a buffer)Another option is to say:
    RequestDispatcher rd = response.getRequestDispatcher(fileName);
    rd.forward();Any other options? What's the prefered way of doing this?
    I know the rule of "don't optimize too early" but this is a situation where we need to get the maximum amount of files served with the hardware we have, and it's going to be a lot of static files, so efficiency is important.
    Thanks

    Ok, that's what I thought. It would be nice if there were a "response.sendStream(InputStream input)" method in the ServletResponse class. Even nicer would be a sendFile or sendChannel or something. This is probably a common usage and it's a place where the container has many opportunities for optimization. For example, it could call the operating systems send_file kernel call so the entire transfer would be done directly from the disk controller to the ether card (on systems that support that).
    For now I'll just do my own buffered copy.

  • What is the most efficient way to have full access to the front panel on RT Labview?

    I have a RT machine that needs to do its job and also port the front panel to an external machine over the network. What is the most efficient way to do it? Using as little of the RT time as possible but providing full functionality to the RT front panel.
    So far I have been using it directly from Labview - running the VI on a remote (RT) and have the front panel on local Labview (WINDOWS). I know I can do it with also through WWW (not very happy with that though).
    LV2009 SP1.
    Thanks

    Running a compiled executable on the RT target, rather than running it within the development environment, is probably slightly more efficient but limits you to the web interface.  If you're running within the LabVIEW environment, I doubt there's a noticeable difference in efficiency from the RT perspective between the web server and the LabVIEW front panel, although that's mostly a guess (I would expect the RT system to send identical data in each case, once the front panel is loaded).  Those are your only options in modern LabVIEW versions.  In LabVIEW 7.1 you could build an executable that acted as the front panel for an RT system, but that feature does not exist in recent versions.  However, a quick search turned up this document with code to approximately duplicate that behavior, perhaps it will work for you?

  • What is the most efficient way to convert a static site to a responsive site using Dreamweaver?

    I need to convert an old site made in Dreamweaver to be responsive to any monitor size. What is the most efficient way to do this?

    Depending on what you have to work with and how it was coded, it might be doable and then again not.  Suffice it to say, there are no magic buttons that will do this for you. Also consider that mobile & tablet users interact differently with their web devices. So your navigation & forms must be finger friendly.  Also images & content must make mobile users happy without killing their dataplans.  There's a lot of planning that goes into making a good Responsive Web site.
    Nancy O.

  • What is the most efficient way of passing large amounts of data through several subVIs?

    I am acquiring data at a rate of once every 30mS. This data is sorted into clusters with relevant information being grouped together. These clusters are then added to a queue. I have a cluster of queue references to keep track of all the queues. I pass this cluster around to the various sub VIs where I dequeue the data. Is this the most efficient way of moving the data around? I could also use "Obtain Queue" and the queue name to create the reference whenever I need it.
    Or would it be more efficient to create one large cluster which I pass around? Then I can use unbundle by index to pick off the values I need. This large cluster can have all the values individually or it co
    uld be composed of the previously mentioned clusters (ie. a large cluster of clusters).

    > I am acquiring data at a rate of once every 30mS. This data is sorted
    > into clusters with relevant information being grouped together. These
    > clusters are then added to a queue. I have a cluster of queue
    > references to keep track of all the queues. I pass this cluster
    > around to the various sub VIs where I dequeue the data. Is this the
    > most efficient way of moving the data around? I could also use
    > "Obtain Queue" and the queue name to create the reference whenever I
    > need it.
    > Or would it be more efficient to create one large cluster which I pass
    > around? Then I can use unbundle by index to pick off the values I
    > need. This large cluster can have all the values individually or it
    > could be composed of the previously mentioned clusters (i
    e. a large
    > cluster of clusters).
    It sounds pretty good the way you have it. In general, you want to sort
    these into groups that make sense to you. Then if there is a
    performance problem, you can arrange them so that it is a bit better for
    the computer, but lets face it, our performance counts too. Anyway,
    this generally means a smallish number of groups with a reasonable
    number of references or objects in them. If you need to group them into
    one to pass somewhere, bundle the clusters together and unbundle them on
    the other side to minimize the connectors needed. Since the references
    are four bytes, you don't need to worry about the performance of moving
    these around anyway.
    Greg McKaskle

  • What is the most efficient way to compare two Lists?

    List A{itemId,itemName} [1,xyz] [9,iyk] [4,iuo] .......
    List B{itemId,item price} [2,999] [9,888] [1, 444].......
    Assume A will be a much larger list than B
    I am trying to find all the items with same itemiId. what would be the most efficient way to do that?
    Thanks!

    Tinkerbell. wrote:
    BigDaddyLoveHandles wrote:
    You wrote:
    Can we assume that an itemId only occurs once in each list? You're the one making claims and assumptions, not me.No in #4 I asked the OP to verify an assumption.An assumption that couldn't possibly be true. Why are you wasting our time?

  • The most efficient way to search a large String

    Hi All,
    2 Quick Questions
    QUESTION 1:
    I have about 50 String keywords -- I would like to use to search a big String object (between 300-3000 characters)
    Is the most efficient way to search it for my keywords like this ?
    if(myBigString.indexOf("string1")!=1 || myBigString.indexOf("string2")!=1 || myBigString.indexOf("string1")!=1 and so on for 50 strings.)
    System.out.println("it was found");
    QUESTION 2:
    Can someone help me out with a regular expression search of phone number in the format NNN-NNN-NNNN
    I would like it to return all instances of that pattern found on the page .
    I have done regular expressions, in javascript in vbscript but I have never done regular expressions in java.
    Thanks

    Answer 2:
    If you have the option of using Java 1.4, have a look at the new regular expressions library... whose package name I forget :-/ There have been articles published on it, both at JavaWorld and IBM's developerWorks.
    If you can't use Java 1.4, have a look at the jakarta regular expression projects, of which I think there are two (ORO and Perl-like, off the top of my head)
    http://jakarta.apache.org/
    Answer 1:
    If you have n search terms, and are searching through a string of length l (the haystack, as in looking for a needle in a haystack), then searching for each term in turn will take time O(n*l). In particular, it will take longer the more terms you add (in a linear fashion, assuming the haystack stays the same length)
    If this is sufficient, then do it! The simplest solution is (almost) always the easiest to maintain.
    An alternative is to create a finite state machine that defines the search terms (Or multiple parallel finite state machines would probably be easier). You can then loop over the haystack string a single time to find every search term at once. Such an algorithm will take O(n*k) time to construct the finite state information (given an average search term length of k), and then O(l) for the search. For a large number of search terms, or a very large search string, this method will be faster than the naive method.
    One example of a state-search for strings is the Boyer-Moore algorithm.
    http://www-igm.univ-mlv.fr/~lecroq/string/tunedbm.html
    Regards, and have fun,
    -Troy

  • I am giving my old MacBook Air to my granddaughter.  What is the most efficient way to erase all the data on it?

    I am giving my old MacBook Air to my granddaughter.  What is the most efficient way to erase the data?

    You have two options.....
    One is to do a clean reinstall of your OS - if you still have the USB installer that came with your Macbook Air...
    The second option is to create a new user (your granddaugher's name).....Deauthorize your Macbook Air from your Itunes and Appstore.....
    Restart your Macbook after you've created your granddaughter's user name, login under your granddaughter's username and delete your username.
    Search your Macbook for your old files and delete them.....
    Good luck...

  • What is the most efficient way to turn an array of 16 bit unsigned integers into an ASCII string such that...?

    What is the most efficient way to turn a one dimensional array of 16 bit unsigned integers into an ASCII string such that the low byte of the integer is first, then the high byte, then two bytes of hex "00" (that is to say, two null characters in a row)?
    My method seems somewhat ad hoc. I take the number, split it, then interleave it with 2 arrays of 4095 bytes. Easy enough, but it depends on all of these files being exactly 16380 bytes, which theoretically they should be.
    The size of the array is known. However, if it were not, what would be the best method?
    (And yes, I am trying to read in a file format from another program)

    My method:
    Attachments:
    word_array_to_weird_string.vi ‏18 KB

  • What is the most efficient way to post several stories to multiple html pages

    What is the most efficient way to post five stories to multiple html pages?
    Currently they are all html files saved in DW with some divs sharing content and other divs are unique.
    I've experimented with saving stories as library items and dropping into other html but wondered if there is a more efficient or dynamic process.

    Server-Side Includes.
    http://forums.adobe.com/message/2112460#2112460
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • Moving content from iMovie to iMovie - what's the most efficient way?

    If I edit and create movies in iMovie08 on one iMac and I want to transfer the content to iMovie08 another iMac 200 miles away , what's the most efficient way? I prefer not to burn DVDs, because I want to do further work on the movies on the second iMac's iMovie (so I can share them with iTunes and sync them with Apple TV).

    >PDPageAddCosContents(destPage, PDPageGetCosContents(srcPage));
    Does this method (PDPageGetCosContent) exist? It would be easy enough
    to create, but I don't see it in the document.
    More seriously, I have a vague memory that it is a Really Bad Thing to
    share the same Contents objects between multiple pages. Maybe
    something to do with page deletion, can't remember.
    >PDPageAddCosResource(destPage, PDPageGetCosResources(srcPage));
    These two methods are not symmetric, and PDPageAddCosResource doesn't
    work that way, sadly...
    Aandi Inston

  • What's the most efficient way to transfer to personal domain?

    I've been using the cumbersome .Mac address and have spent a lot of time optimizing the site, having also purchased a domain name (which I'll switch to), which is currently masked and forwarded. So what's the most smooth way of using the personal domain without losing all the strides I've made to get bumped up in the rankings? Thanks in advance for your suggestions. www.RedCottageInc.com (that's my future personal domain!)

    I'm saying that you give Google the .Mac URL to get to your sitemap but use the registered domain name for normal access.
    You are promoting your site with www.RedCottageInc.com but, because it is masked, Google needs your web.mac address to access the verification file and the sitemap so that it can spider your site.
    You normally upload your sitemap as "sitemap.xml". You can test its accessibility by entering
    http://web.mac.com/username/WebSiteName/Sitemap.xml in your browser.
    Google needs this URL to get to the sitemap - visitors will use www.RedCottageInc.com.
    Google wants to get to the verification file and the sitemap but your website visitors don't.
    I guess all this is confusing if you haven't done it before and I don't know that I am explaining it very well. The best way to get it is to go through all the steps of creating the verification file and sitemap, uploading them to your site folder and adding and verifying in your Google control panel.
    Here are the relevant Google pages...
    Guidelines...
    http://www.google.com/support/webmasters/bin/answer.py?answer=35769
    Add URL to Google...
    http://www.google.com/addurl/?continue=/addurl
    Verification file....
    http://www.google.com/support/webmasters/bin/answer.py?answer=35658&query=html+f ile&topic=&type=
    Sitemap...
    http://www.google.com/support/webmasters/bin/answer.py?answer=34657&ctx=sibling

  • What is the most efficient way to send an email to our 2000 constituents?

    I have to send out a newsletter to our constituents (between 1,000 and 2,000 contact). I know that with a .mac account I can only send 100 at a time, and 400 a day. That would take 5 days! Anyone know a more efficient way to do this?
    Thanks!

    Server-Side Includes.
    http://forums.adobe.com/message/2112460#2112460
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • I need to know the best, safest way to convert video for Mac.  I just had home movies converted to a DVD format a realize now that I need another step to burn them to my computer.

    I just had home movies converted to a DVD format a realize now that I need another step to burn them to my computer.  This is for a Christmas present!  Help.

    I don't think you need to use a ripper program to read a home movie DVD. Those are primarily for copy-protected commercial DVDs, right?
    I think you just need to transcode the DVD files using a utility like Handbrake, which is free and fast.
    http://handbrake.fr/details.php

  • Need to know the name of DSO used to load Header and Item  level info in LO

    Hi friends ,
    can some one tell me the name of DSO used to load Header and Item Level information from Data sources - 2lis_11_vahdr  and   2lis_11_vaitm  .
    plz make it fast
    Thanks

    Hi ,
    It is 0SD_O03 from 2lis_11_vahdr and 0SD_O01 & 0SD_O02 from 2lis_11_vaitm.
    Bye
    Dinesh

Maybe you are looking for