Reputation: 14163
Im making an inventory system for my game. Im not quite sure on how the structure of the classes should be, I already have a weapons, items, and blocks class. Weapons go on the player, Items can be placed on blocks, and blocks can be placed on a tile grid. I have a class called tile to handle placing on the grid. But im wondering how I should make a class to hold each 'thing' together ('things' being, weapons,blocks, and items).
If im unclear or you need more information just comment.
Upvotes: 1
Views: 984
Reputation: 1095
You have a good starting idea, but think out of the box - if you have a typical inventory then you got
Player
+ Inventory
+ [] Items
+ [] Weapons
If you plan to implement a slot based inventory, then you have many possibilities to realize the item-binding, e.g.
1) Item placed in Slot in Inventory
2) Item placed in Item in Slot in Inventory
3) Item placed in Inventory in Inventory (e.g. a Chest or sth. else)
So try to think about a concept which is more flexible - you could do this by creating some interfaces or provider classes which are able to hold other things. A way could be
Player got Inventory Inventory implements IInventory Item implements IInventory (if it is a Chest or sth. else)
If you wanna implement such a grid we know from WoW or so, then you also could write classes which are able to sort and order items...
Inventory implements IOrderedInventory
and your Grid offers an IInventoryAdapter
By handling your actions and classes these ways, you can be sure, that the interconnection works fine.
I hope i was able to give you some ideas.
Greetings,
Upvotes: 2