Implementing Text Based RPG Item Menus

Hello. Say I'm writing a text based rpg, and when players activate an Item in their inventory I want it to open up a menu with options, such as if it is a potion it should say: Drink, Drop, etc., or if it is a weapon or armor piece: Equip, Drop, etc., but I don't know how to implement this. Should I overload a function, creating a function with the same name in each respective class (not sure if it's called overloading in this context), but then how would I make it activate on the player? Should I pass a pointer referencing the player in the function opening the menu, or should I create the function in the player class, setting a pointer on the item? If I did this, how would I know what menu to open by detecting it's type?
I'd say that the item should have a list of options associated with it. Just have a function that display a "list" and have the object send the list/pointer to the list/however you're storing the list. Or maybe have the base "item" class (if you have one) have a method that prints a "list". There would be no need to overload it if every inventory item derived from that class. Each item would use the same function print their own respective list.

Part of this really depends on the structure of your game.
Storing a list of options in the item class is one way. However I am not sure if the options really belong to the item. If you want to add some more options to some items it can be quite a hassle.

However If you find good reasons to store the options in the item class it would be better not to let the item class print the list of options but just return the list of options and/or as a string.
It provides greater flexibility when you keep the data and the display separate. For example if you later want to create GUI for the game you don't have to make changes in the item class.

Another option would be to create a std::map to map the options to an item.
1
2
typedef vector<string> OptionList;
map<item, OptionsList>
Topic archived. No new replies allowed.