Tricky class problem with game

I'm tring to work out some method of creating an inventory system for a text game I'm making. This is my first C++ project that I'm using to teach myself. It's going pretty well but no matter how I try to go at this inventory thing it just won't work out. I have the three classes, player, room, and item, the items have a list of aliases they can be reffered to by, so that if there is a coffee mug, typing take cup or take mug will work, along with any other names set for it, so i need to search item.aliases to match the input string, but only if that item is in room.inventory, so i need to do something to search each alias of each item in the inventory of the room and if an alias on an item matches the search string, move that item to the inventory of the player. Unless there is an easier way to acheive the same effect, of course. I'm not sure if I should be using lists or arrays or some combination of the two because I just started learning lists. Any ideas?
An std::list looks like it would work fine. Just have an std::list<item> inside of the player, and another inside the room. Then for example if you get the command "take mug" just iterate through all the items in the list until you find it (or not).
A "set" (ordered or unordered) of aliases associated with each item would probably suit your needs best from what you describe.
Well I think I figured it out. I guess the problem I was having was that I was trying to use a list <string> inventory, then do inventory.front().aliases.front(), thinking it could convert the string and know which item it was, and when it didnt work I thought multiple dots didn't work. I didn't realize I could, and had to, use list<items> inventory. Didn't realize I could do that till I thought about it and the light went on that strings are a class... tried it out again and now that works.
Last edited on
Topic archived. No new replies allowed.