Im not sure if I should be posting this here or the game programming forum.
Anyway...the deal is... I am using vectors instead of arrays to track PLAYER potions.
here is the code...I commented where the problems lie...there is over 400 lines of code so I am only going to post snippets.
Top of Town.cpp where I declared the vector and its iterator.
Code:
#include "Library.h"
#include "Globals.h"
using std::cin;
using std::cout;
using std::endl;
// I am not too sure of where to declare this vector
std::vector<POTION>potions(15);
std::vector<POTION>::iterator i;
void Armory(PLAYER*);
void ItemShop(PLAYER*);
ItemShop function
Code:
void ItemShop(PLAYER* player)
{
cout << "As you step inside, a pleasant smell wafts up to your nose. You see\n"
<< "a kindly heavyset older woman watering plants, that decorate the shop.\n" << endl;
Pause();
cout << "What would you like to do?\n"
<< "<1> Talk to the woman.\n"
<< "<2> Exit\n"
<< ">";
int answer = -1;
cin >> answer;
cin.clear();
cin.ignore(INT_MAX,'\n');
if (answer == 1)
{
cout << "Hello Traveler! Welcome to Suzies Pots and Herbs.\n"
<< "How may I help you?\n" << endl;
Pause();
Clr_Scrn();
bool shoploop = true;
while (shoploop = true)
{
cout << "What do you want to do?\n"
<< "<1> Buy Potions\n"
<< "<2> Buy Spells\n"
<< "<3> View Stats\n"
<< "<4> Exit\n"
<< ">";
int choice = -1;
cin >> choice;
cin.clear();
cin.ignore(INT_MAX,'\n');
switch(choice)
{
case 1:
{
POTION* potionlist = new POTION[7];
potionlist[0].CreatePotion("Small Health Potion", 10, 30, 50);
potionlist[1].CreatePotion("Medium Health Potion", 30, 100, 100);
potionlist[2].CreatePotion("Large Health Potion", 100, 300, 1000);
potionlist[3].CreatePotion("Elixer", 9999, 9999, 10000);
potionlist[4].CreatePotion("Small Mana Potion", 10, 50, 100);
potionlist[5].CreatePotion("Medium Mana Potion", 30, 100, 100);
potionlist[6].CreatePotion("Large Mana Potion", 100, 300, 1000);
cout << "Name: " << "Restore: " << "Price: " << endl;
for (int loop = 0; loop < 6; loop++)
{
cout << loop + 1 << potionlist[loop].GetName() << " " <<
potionlist[loop].GetMinRestore() << "-" << potionlist[loop].GetMaxRestore()
<< potionlist[loop].GetPrice() << endl;
}
cout << "0: Exit\n"
<< "What do you want to buy?\n";
int decision = -1;
cin >> decision;
cin.clear();
cin.ignore(INT_MAX,'\n');
if (decision > 0 && decision < 8)
{
if (player->GetGold() >= potionlist[decision-1].GetPrice())
{
player->SpendGold(potionlist[decision-1].GetPrice());
// places potion in vector
potions.push_back(potionlist[decision-1]);
// this is only to test to see the capacity of the vector
// for some reason it outputs 30--when should be 15
cout << endl << potions.capacity() << endl;
// to test how much memory is inialized inside the vector
// which for some reason outputs 16--when should be 1
cout << potions.size() << endl << endl;
// put this in just to see what the heck was going on and am now
// more confused than ever!!!!
// first 15 outputs is dobldegook
// the 16th is the potion that you actually bought!!!
for(i = potions.begin(); i != potions.end(); ++i)
{
cout << i->GetName() << endl;
}
cout << "You have purchased a " << potionlist[decision-1].GetName()
<< endl;
cout << "Do you want to make another purchase? 1 for yes 2 for no\n";
cin >> shoploop;
cin.clear();
cin.ignore(INT_MAX,'\n');
Clr_Scrn();
delete [] potionlist;
break;
}
else
{
cout << "You cant afford this!!\n" << endl;
Pause();
Clr_Scrn();
delete [] potionlist;
shoploop = true;
break;
}
}
else if (decision == 0)
{
delete [] potionlist;
shoploop = false;
break;
}
else
cout << "Invalid Selection" << endl;
shoploop = true;
Pause();
Clr_Scrn();
break;
}