Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Best way to store Item data  (Read 1221 times)
0 Members and 1 Guest are viewing this topic.
Offline DazKins
« Posted 2012-10-21 20:01:58 »

Im making an RPG game which requires there to be lots of different items in the game. Each item has its own individual properties and i was wondering whats the best way to store them all.

Heres my idea at the moment

1  
2  
3  
4  
public class ItemStorage {
   public static Item nullItem = new Item(-1,"",""); //-1
  public static Item weaponTest = new ItemWeapon(0,"WeaponTest","Weapon"); //0
}


However that would require lots of code to put in all the items.

I thought about using a list or an array but that would be hard to reference in other areas of my code as i would need to knoew the index of each item. Is this the best way of doing it, or am i missing something?

-Many Thanks

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Offline Huw

Senior Member


Medals: 1
Projects: 2



« Reply #1 - Posted 2012-10-21 20:03:55 »

You could have a database/file containing all the item information and load this in your game?

Not sure how you'd do this though.

I'm a java noob, but I'm learning. My little blog. My Games.
Offline DazKins
« Reply #2 - Posted 2012-10-21 20:05:08 »

I feel that would be a waste of time though as i could merely right out the elements of the database in the code instead of in a file

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Agro
« Reply #3 - Posted 2012-10-21 20:08:24 »

Well for starters, all items should be under an Item class like you have. You need to categorize different kinds of things. There should be things like weapons, potions, armor, etc. Each of these should have more attributes and characteristics to tell eachother apart, but if you need to go even more in depth, I think you'd have to create a class for each weapon, for example.

Offline 65K
« Reply #4 - Posted 2012-10-21 20:19:58 »

First you need to refine your requirements.
For example, what kind of items, are there item classes, what are common properties, who needs to access what, when and how frequently, identify dependencies, how should they be accessible, are they dynamically creatable, modifiable, should they be externally editable, what can you do with items, etc. etc.
Anyway, using global item variables is not a good solution.

Offline actual

JGO Coder


Medals: 23



« Reply #5 - Posted 2012-10-22 03:14:10 »

I feel that would be a waste of time though as i could merely right out the elements of the database in the code instead of in a file

I haven't found that to be the case, personally. Although it takes some effort to set up the code for loading the properties file and injecting the values into your objects I find it to be worth it. Once it's set up you can do something as simple as:
1  
2  
3  
4  
5  
6  
7  
8  
9  
+Axe Weapon
name = Battle Axe
attack = 140
weight = 100
minStrength = 13

+MinHealth Potion
name = Minor Potion of Healing
healthIncr = 15

I have found it makes adding and changing things very easy.

Are these items essentially lists of properties or do they have behavior (e.g. methods) as well? And if they have methods, will they be the same for all items or will different types of items have different types of methods. That is will you be doing something like:
1  
2  
3  
4  
5  
6  
player.attack(monster,Player.getSword());

or

Sword sword = player.getSword();
sword.attack(monster);











Offline Roquen
« Reply #6 - Posted 2012-10-22 06:45:27 »

I started to build up some various techniques over here: http://www.java-gaming.org/topics/archtypes-composition-and-code-is-data/26554/view.html
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

UprightPath (21 views)
2014-09-20 20:14:06

BurntPizza (27 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (70 views)
2014-09-10 13:57:51

TehJavaDev (95 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29

BurntPizza (52 views)
2014-09-07 01:13:42

Longarmx (39 views)
2014-09-07 01:12:14

Longarmx (45 views)
2014-09-07 01:11:22
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!