Advertisement

inventory system

Started by December 27, 2002 10:46 PM
4 comments, last by Patrick1382 21 years, 10 months ago
I''m fairly new to programming and at the moment I''m workin on a simple text rpg type game. Right now I''m trying to make an inventory system although I''m not sure how I could do this. I''m trying to make an inventory system that is activated by maybe hitting "I" with around 20 slots for items and then depending on what the character has list those items and then maybe bringing up an info screen when the character selects the item with the option to use/equip/drop the item. Any help on this subject would be appreciated.
As one who is new to programming, you are undoubtedly unaware of the rules here regarding crossposting. Thus, you are forgiven. But delete one of your posts, and don''t do it again. Or else.

Don''t listen to me. I''ve had too much coffee.
Advertisement
I would make a structure containing the 20 slots... somethin such as

struct ITEM {.....}

struct INVENTORY
{
ITEM slot1;
ITEM slot2;
...
}


in item, you can have functions defined that will equip, drop, etc

go from here, it should work well
Definitely better to use an array:

class Inventory {static const int NUM_ITEMS = 0;Item items[NUM_ITEMS]; // Array makes operations on the inventory much easierpublic:void dropAll();void equip(Item someItem);void drop(Item someItem);...};// example "bulk" operationvoid Inventory::dropAll() {for(int i = 0;i < NUM_ITEMS;i++) {    items = 0; // (or whatever drops it)}}  


Using AP's way, each slot would be accessed by a different name, making the above function particularly ugly:

slot1 = 0;
slot2 = 0;
slot3 = 0;
slot4 = 0;
...

Ken Murphy

[edited by - Ken Murphy on December 28, 2002 2:33:42 PM]
You cn check my text rpg on my site I have the full source of it and it has sth similar to what you want.
Opps forgot the link I thought it would be on my sig but I also forgot to check the box what a forgetfulness :]


World of Entaria|Shadowy Tree
Omnium rerum principia parva sunt.
Think twice before you code!!
Black Knight

This topic is closed to new replies.

Advertisement