Ok, so this will probably look ugly to some. I am trying to send an item that belongs to a character to a function that takes that item and sends it to another function to use that item. The reason I used the redirection was because I didnt know how to do something such as:
player->inventory[0].useItem(player, inventory[0])
here is the code i am working with.
Code:// item.h struct item { char name[100]; int price; int quantity; int enumValue; void useItem(character *inChar, item *inItem); };Code:// item.cpp void useItem(character *inChar, item *inItem) { using namespace std; switch (inItem->enumValue) { case eMinorHealthPotion: { cout << inChar->showName() << " uses a minor healing potion.\n"; int heal = 32; if (inChar->showIsAlive()) { if ((inChar->showCurrentHealth() + heal) > inChar->showMaxHealth()) { heal = heal - (((inChar->showCurrentHealth() + heal)) - inChar->showMaxHealth()); inChar->changeHealth(true, heal); } else inChar->changeHealth(true, heal); cout << inChar->showName() << " has been healed for " << heal << " hit points!\n"; } else cout << "The minor healing potion has no effect on " << inChar->showName() << '\n'; inItem->quantity--; break; } } }Code:// character.cpp void character::useItem(character *inChar, item *inItem) { if (inItem->quantity > 0) inItem->useItem(inChar, inItem); }Code:// main.cpp player->useItem(player, player->inventory[eMinorHealthPotion]);



LinkBack URL
About LinkBacks


