Results 1 to 6 of 6
- 06-16-2012, 06:45 PM #1
Computer Slave
- Join Date
- Jun 2012
- Location
- USA
- Posts
- 17
- Rep Power
- 0
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?
Thanks for any help!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; } }
- 06-16-2012, 07:24 PM #2
Re: Help on ideation of making an appending list of items
If you are creating instances of the ItemObject class, you could save those instances in an array list for later reference.how to write it to a list of items
That sounds like a Map with name as key and the object as the value.I'd like the Objects of the items to have the names set as their specific item ID,If you don't understand my response, don't ignore it, ask a question.
-
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!
- 06-16-2012, 09:41 PM #4
Computer Slave
- Join Date
- Jun 2012
- Location
- USA
- Posts
- 17
- Rep Power
- 0
-
Re: Help on ideation of making an appending list of items
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.
- 06-17-2012, 12:10 AM #6
Computer Slave
- Join Date
- Jun 2012
- Location
- USA
- Posts
- 17
- Rep Power
- 0
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
-
Making Items in World of Zuul
By awesom in forum New To JavaReplies: 9Last Post: 01-16-2012, 09:43 AM -
SORT list on items where frequencies are involved
By emgee in forum Java AppletsReplies: 1Last Post: 11-14-2010, 02:42 PM -
Transfering all items from one List to another
By Bulelakes in forum New To JavaReplies: 6Last Post: 08-23-2010, 08:48 AM -
List of Items in JTextArea
By ŖàΫ ỏƒ Ңόρę in forum New To JavaReplies: 7Last Post: 03-15-2010, 09:03 PM -
Appending and item to a Select List
By Samurai Coder in forum New To JavaReplies: 1Last Post: 12-04-2009, 10:56 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks