Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
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 2649 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

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


Check out my Dev Blog:
Offline Huw

Senior Devvie

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


Check out my Dev Blog:
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.

Lethal Running - a RPG about a deadly game show held in a futuristic dystopian society.
Offline actual

JGO Coder

Medals: 25

« 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:
+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:


Sword sword = player.getSword();

Offline Roquen

JGO Kernel

Medals: 517

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

I started to build up some various techniques over here:
Pages: [1]
  ignore  |  Print  

EgonOlsen (1278 views)
2018-06-10 19:43:48

EgonOlsen (1147 views)
2018-06-10 19:43:44

EgonOlsen (881 views)
2018-06-10 19:43:20

DesertCoockie (1291 views)
2018-05-13 18:23:11

nelsongames (1106 views)
2018-04-24 18:15:36

nelsongames (1337 views)
2018-04-24 18:14:32

ivj94 (2077 views)
2018-03-24 14:47:39

ivj94 (1231 views)
2018-03-24 14:46:31

ivj94 (2188 views)
2018-03-24 14:43:53

Solater (798 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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‑
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!