Results 1 to 6 of 6
  1. #1
    dddJewelsbbb is offline Computer Slave
    Join Date
    Jun 2012
    Location
    USA
    Posts
    17
    Rep Power
    0

    Default Help on ideation of making an appending list of items

    Hey guys. I'm dealing with this file to instantiate objects. My problem is that I'm stuck on what to do. First, I have a random item generator that generates random values into these fields. However, I don't know how to write it to a list of items. (By list, I don't mean JAVA List, but generally a "list" so that I don't enclose my options to only a list ;P)

    What I'd like to do is have a file or something similar to have a couple of items that will be the same static item ID in every instance of the game whilst being able to add items with a set item ID. I'd like the Objects of the items to have the names set as their specific item ID, and also a way for the file to quickly search through item ID's to load and possibly search (for game console commands). Any ideas?

    Java Code:
    // this will allow for instantiating of any item, and several fields are at your disposal.
    // Drink up.
    package valerian;
    class ItemObject
    {
        private String Name; // ITEM NAME
        private String Comment; // Comment
        private int Str;    // S
        private int Dex;    // D
        private int Int;    // I
        private int Spt;    // S
        private int Ten;    // T
        private int minimumDamage;
        private int maximumDamage;
        private int lifeLeech; //  --  does it leech life per hit? if so, # of life leeched per hit in this object var
        private int speed; // weapon speed
        private int Luck; // luck - increases chance of drops. Dunno how to implement
    					 //the math formula, so I guess it's unused for now
        private int critRating = 0; // critical strike (each point at 60 is +.05%)*** stc
        private int Armor; // armor rating
        private int Resistance = 0; // resistance against spells
        private int levelRequirement;
        
        public String getComment() {
            return Comment;
        }
    
        public String getName() {
            return Name;
        }
    
        public void setComment(String Comment) {
            this.Comment = Comment;
        }
    
        public void setName(String Name) {
            this.Name = Name;
        }
    	
    
        public int getArmor() {
            return Armor;
        }
    
        public int getDex() {
            return Dex;
        }
    
        public int getInt() {
            return Int;
        }
    
        public int getLuck() {
            return Luck;
        }
    
        public int getResistance() {
            return Resistance;
        }
    
        public int getSpt() {
            return Spt;
        }
    
        public int getStr() {
            return Str;
        }
    
        public int getTen() {
            return Ten;
        }
    
        public int getCritRating() {
            return critRating;
        }
    
        public int getLevelRequirement() {
            return levelRequirement;
        }
    
        public int getLifeLeech() {
            return lifeLeech;
        }
    
        public int getMaximumDamage() {
            return maximumDamage;
        }
    
        public int getMinimumDamage() {
            return minimumDamage;
        }
    
        public int getSpeed() {
            return speed;
        }
    
        public void setArmor(int Armor) {
            this.Armor = Armor;
        }
    
        public void setDex(int Dex) {
            this.Dex = Dex;
        }
    
        public void setInt(int Int) {
            this.Int = Int;
        }
    
        public void setLuck(int Luck) {
            this.Luck = Luck;
        }
    
        public void setResistance(int Resistance) {
            this.Resistance = Resistance;
        }
    
        public void setSpt(int Spt) {
            this.Spt = Spt;
        }
    
        public void setStr(int Str) {
            this.Str = Str;
        }
    
        public void setTen(int Ten) {
            this.Ten = Ten;
        }
    
        public void setCritRating(int critRating) {
            this.critRating = critRating;
        }
    
        public void setLevelRequirement(int levelRequirement) {
            this.levelRequirement = levelRequirement;
        }
    
        public void setLifeLeech(int lifeLeech) {
            this.lifeLeech = lifeLeech;
        }
    
        public void setMaximumDamage(int maximumDamage) {
            this.maximumDamage = maximumDamage;
        }
    
        public void setMinimumDamage(int minimumDamage) {
            this.minimumDamage = minimumDamage;
        }
    
        public void setSpeed(int speed) {
            this.speed = speed;
        }
            
        
    }
    Thanks for any help!

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,261
    Rep Power
    25

    Default Re: Help on ideation of making an appending list of items

    how to write it to a list of items
    If you are creating instances of the ItemObject class, you could save those instances in an array list for later reference.
    I'd like the Objects of the items to have the names set as their specific item ID,
    That sounds like a Map with name as key and the object as the value.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help on ideation of making an appending list of items

    It looks like you want to use a HashMap such as a HashMap<String, AbstractItem> so you can have a collection of items held by the map, have the item's "name" serve as the HashMap's key and thus allow your program to easily retrieve an item based on its key. Best would be to declare your map's variable as a Map<String, AbstractItem> so that later you can use a different concrete Map if desired. Note that I'm calling your abstract parent item type AbstractItem, assuming that all Item classes would derive from this.

    Edit: slow, slow, slow!

  4. #4
    dddJewelsbbb is offline Computer Slave
    Join Date
    Jun 2012
    Location
    USA
    Posts
    17
    Rep Power
    0

    Default Re: Help on ideation of making an appending list of items

    Quote Originally Posted by Fubarable View Post
    Edit: slow, slow, slow!
    So that would be extremely slow for the game to render a hashmap?
    And also, what about saving it to a file?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help on ideation of making an appending list of items

    Quote Originally Posted by dddJewelsbbb View Post
    So that would be extremely slow for the game to render a hashmap?
    And also, what about saving it to a file?
    Heck no. It means that I was slow to answer your question as I gave the same answer as Norm but several minutes after him. One of the main advantages toward using HashMaps is that they're fast.

    Regarding saving information to a file, there are various options available including using serialization, XML serialization, database, or properties. For something like this, it would depend on the current and future use of your program. If there's a chance that it could get large, or the amount of data that persists gets large, you'll gravitate towards use of a database.

  6. #6
    dddJewelsbbb is offline Computer Slave
    Join Date
    Jun 2012
    Location
    USA
    Posts
    17
    Rep Power
    0

    Default Re: Help on ideation of making an appending list of items

    Okay. :) So I can implement a database for storing data that is not server-side but rather root-hosting within the program itself as a read-only thing?
    'Cause I'm considering making all the items static (in the sense that they're there and not instantiated on run and created during drops?

Similar Threads

  1. Making Items in World of Zuul
    By awesom in forum New To Java
    Replies: 9
    Last Post: 01-16-2012, 09:43 AM
  2. SORT list on items where frequencies are involved
    By emgee in forum Java Applets
    Replies: 1
    Last Post: 11-14-2010, 02:42 PM
  3. Transfering all items from one List to another
    By Bulelakes in forum New To Java
    Replies: 6
    Last Post: 08-23-2010, 08:48 AM
  4. List of Items in JTextArea
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 7
    Last Post: 03-15-2010, 09:03 PM
  5. Appending and item to a Select List
    By Samurai Coder in forum New To Java
    Replies: 1
    Last Post: 12-04-2009, 10:56 PM

Tags for this Thread

Posting Permissions

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