I'm adding an item system to my game. It's functional, but I'm not sure if it really is the best way to do it.
My game is written in C#, and this is an example of the system I'm currently using:
In my 'main' class (Game.cs) I make an instance 'ItemManager' class. Kinda like this:
[source lang="csharp"]ItemManager items = new ItemManager();[/source]
In the ItemManager class, I define all the items. (Instances of the 'Item' class)
[source lang="csharp"]class ItemManager{public List<Item> items = new List<Item>();public Item potion = new Item(0, "Potion", potionIcon);public Item bucket = new Item(1, "Empty Bucket", bucketIcon);public Item rope = new Item(2, "Rope", ropeIcon);public ItemManager(){ Items.Add(potion); Items.Add(bucket); Items.Add(rope);}}[/source]
And finaly, this is kinda what my Item class looks like
[source lang="csharp"]public class Item{public int Id;public string Name;public Bitmap Icon;public Item(int id, string name, Bitmap icon){ Id = id; Name = name; Icon = icon;}}[/source]
The system works fine, but there are two main issues:
1. I need to pass the Game.items to every class that has something to do with items, witch are a lot of classes.
2. I need to add the items to the ItemManager.items list in the exact same order as the id's the items have, and I can't skip an item id.
Other than that, I hate to refer to items.items[itemID], but that is mainly just because it looks terrible.
I wonder how you guys would handle this. I have searched around on Google but strangely enough I did not find a good example.
Do you have any suggestions?
Thanks in advance!
Edited by Freeky, 08 October 2012 - 03:05 PM.






