Example #1
0
void MainShop::mainShop(Hero& hero)
{
    //Polymorphism
    //Declare pointer of base class equal to address of derived class object
    
    //NOTE:
    //If you have a pure virtual function declaration in the base class
    //you cannot instantiate objects since its an abstract class
    
    SoldierWeapons sword;
    MageWeapons spell;
    ArcherWeapons bow;
    PotionShop potion;
    SoldierArmor armor_soldier;
    MageArmor armor_mage;
    ArcherArmor armor_archer;
    
    MainShop *SoldierWeaponsPtr = &sword;
    MainShop *Soldier_ArmorShopPtr = &armor_soldier;
    
    MainShop *SpellShopPtr = &spell;
    MainShop *Mage_ArmorShopPtr = &armor_mage;
    
    MainShop *ArcherWeaponsPtr = &bow;
    MainShop *Archer_ArmorShopPtr = &armor_archer;
    
    MainShop *PotionShopPtr = &potion;
    
    cout << "\nDo you wish to Enter the shop? (Y/N)\n";
	cin >> enter;
	if ((enter == 'Y') || (enter == 'y'))
	{
        
		cout << "Welcome to the Claimh Solais Shop!\nThis is where your hard work and dedication pay off!\n";
        
		//MyMap[maps.dungeon_lvl] = Monster_Dungeon1;
		//cout << Maps.begin()->first<<endl;
		//cout << Maps.begin()->second<<endl;
        
		if (hero.getMoney() > 0)//Check to see if broke
		{
            
			cout << "What are you looking for?\n\n";
			cout << "1) Weapons\n2) Armor\n3) Potions\n" << endl;
			cin >> choice1;
            
            cout << "Your current gold is: " << hero.getMoney() << endl;
			if (choice1 == 1)//Weapons
			{
				cout << "What type of weapon are you looking for??\n\n";
				cout << "1) Swords\n2) SpellBooks\n3) Bows\n";
				cin >> choice;
                
				//Display Choices
				switch (choice)
				{
                    case 1: SoldierWeaponsPtr->EnterShop(hero); //Swords
                        break;
                    case 2:SpellShopPtr->EnterShop(hero);//Staffs
                        break;
                    case 3:ArcherWeaponsPtr->EnterShop(hero);//Bows
                        break;
                    default: cout << "Error!, Please try again.";
                        this->mainShop(hero);
				}
			}
void ArcherWeapons::ArcherShop(Hero& hero)
{
    /*this->archer_weapons = {//name, damage, price
        {1, Weapon("Arondight", 4, 150, 1)},
        {2, Weapon("Gugnir", 10, 230, 2)},
        {3, Weapon("Susano'", 16, 300, 3)},
        {4, Weapon("Longinus", 24, 550, 4)},
        {5, Weapon("Hrunting", 32, 610, 5)},
        {6, Weapon("Clarent", 40, 690, 6)},
        {7, Weapon("Shinigami", 52, 750, 7)},
        {8, Weapon("Caliburn", 60, 900, 8)}
    };*/

	this->init_map_values();//Inherits init_map_values from mainshop
	
	this->archer_weapons = {//name, damage, price
        {1, Weapon("Arondight",map_effect_array[0], map_price_array[0],map_sellValue_array[0], 1)},
        {2, Weapon("Gugnir",   map_effect_array[1], map_price_array[1],map_sellValue_array[1], 2)},
        {3, Weapon("Susano'",  map_effect_array[2], map_price_array[2],map_sellValue_array[2], 3)},
        {4, Weapon("Longinus", map_effect_array[3], map_price_array[3],map_sellValue_array[3], 4)},
        {5, Weapon("Hrunting", map_effect_array[4], map_price_array[4],map_sellValue_array[4], 5)},
        {6, Weapon("Clarent",  map_effect_array[5], map_price_array[5],map_sellValue_array[5], 6)},
        {7, Weapon("Shinigami",map_effect_array[6], map_price_array[6],map_sellValue_array[6], 7)},
        {8, Weapon("Caliburn", map_effect_array[7], map_price_array[7],map_sellValue_array[7], 8)}
    };
	
	//Check class
	if (hero.My_class != "Archer")
	{
		cout << "\nNote:You can only buy from this category if you are of a Archer class\n";
		cout << "...\nSorry, you are not of type Archer class, therefore you cannot buy Archer related items.\n";
        MainShop::mainShop(hero);
        return;
	}
	
    this->getArcherWeapons();//Display options
    
	cout << "Select what you would like to buy, or enter 9 to quit!\n";
	cin >> choice2;
	switch (choice2)
	{
        case 1:
            for (map <int, Weapon>::iterator iter = archer_weapons.begin(); iter != archer_weapons.end(); iter++)
            {
                if(iter->first == 1)
                {
                    if (hero.getMoney() >= iter->second._price)
                    {//Add a function-if you already have a weapon, you cannot buy it again
                        add_weapon(iter->second);
                        hero.setMoney(hero.getMoney() - iter->second._price);
                        hero.setAttack(hero.getAttack() + iter->second._damage);
                        cout << "\nYou have Successfully Bought " << iter->second._name << "\nIt has been added to your inventory\n";
                        cout << "your total items are: "<< weapon_inventory.size() << endl;
                        break;//break for loop
                    }
                    
                    else
                    {
                        cout << "You do not have enough money to buy this weapon\nPlease try again\n" << endl;
                        //system("CLS");//cout << string(50, '\n');
                        this->ArcherShop(hero);
                        break;//break for loop
                    }
                }
            }
            break;//break switch
            
        case 2:
            for (map <int, Weapon>::iterator iter = archer_weapons.begin(); iter != archer_weapons.end(); iter++)
            {
                if(iter->first == 2)
                {
                    if (hero.getMoney() >= iter->second._price)
                    {//Add a function-if you already have a weapon, you cannot buy it again
                        add_weapon(iter->second);
                        hero.setMoney(hero.getMoney() - iter->second._price);
                        hero.setAttack(hero.getAttack() + iter->second._damage);
                        cout << "\nYou have Successfully Bought " << iter->second._name << "\nIt has been added to your inventory\n";
                        cout << "your total items are: "<< weapon_inventory.size() << endl;
                        break;//break for loop
                    }
                    
                    else
                    {
                        cout << "You do not have enough money to buy this weapon\nPlease try again\n" << endl;
                        //system("CLS");//cout << string(50, '\n');
                        this->ArcherShop(hero);
                        break;//break for loop
                    }
                }
            }
            break;//break switch
            
        case 3:
            for (map <int, Weapon>::iterator iter = archer_weapons.begin(); iter != archer_weapons.end(); iter++)
            {
                if(iter->first == 3)
                {
                    if (hero.getMoney() >= iter->second._price)
                    {//Add a function-if you already have a weapon, you cannot buy it again
                        add_weapon(iter->second);
                        hero.setMoney(hero.getMoney() - iter->second._price);
                        hero.setAttack(hero.getAttack() + iter->second._damage);
                        cout << "\nYou have Successfully Bought " << iter->second._name << "\nIt has been added to your inventory\n";
                        cout << "your total items are: "<< weapon_inventory.size() << endl;
                        break;//break for loop
                    }
                    
                    else
                    {
                        cout << "You do not have enough money to buy this weapon\nPlease try again\n" << endl;
                        //system("CLS");//cout << string(50, '\n');
                        this->ArcherShop(hero);
                        break;//break for loop
                    }
                }
            }
            break;//break switch
            
        case 4:
            for (map <int, Weapon>::iterator iter = archer_weapons.begin(); iter != archer_weapons.end(); iter++)
            {
                if(iter->first == 4)
                {
                    if (hero.getMoney() >= iter->second._price)
                    {//Add a function-if you already have a weapon, you cannot buy it again
                        add_weapon(iter->second);
                        hero.setMoney(hero.getMoney() - iter->second._price);
                        hero.setAttack(hero.getAttack() + iter->second._damage);
                        cout << "\nYou have Successfully Bought " << iter->second._name << "\nIt has been added to your inventory\n";
                        cout << "your total items are: "<< weapon_inventory.size() << endl;
                        break;//break for loop
                    }
                    
                    else
                    {
                        cout << "You do not have enough money to buy this weapon\nPlease try again\n" << endl;
                        //system("CLS");//cout << string(50, '\n');
                        this->ArcherShop(hero);
                        break;//break for loop
                    }
                }
            }
            break;//break switch
            
        case 5:
            for (map <int, Weapon>::iterator iter = archer_weapons.begin(); iter != archer_weapons.end(); iter++)
            {
                if(iter->first == 5)
                {
                    if (hero.getMoney() >= iter->second._price)
                    {//Add a function-if you already have a weapon, you cannot buy it again
                        add_weapon(iter->second);
                        hero.setMoney(hero.getMoney() - iter->second._price);
                        hero.setAttack(hero.getAttack() + iter->second._damage);
                        cout << "\nYou have Successfully Bought " << iter->second._name << "\nIt has been added to your inventory\n";
                        cout << "your total items are: "<< weapon_inventory.size() << endl;
                        break;//break for loop
                    }
                    
                    else
                    {
                        cout << "You do not have enough money to buy this weapon\nPlease try again\n" << endl;
                        //system("CLS");//cout << string(50, '\n');
                        this->ArcherShop(hero);
                        break;//break for loop
                    }
                }
            }
            break;//break switch
            
        case 6:
            for (map <int, Weapon>::iterator iter = archer_weapons.begin(); iter != archer_weapons.end(); iter++)
            {
                if(iter->first == 6)
                {
                    if (hero.getMoney() >= iter->second._price)
                    {//Add a function-if you already have a weapon, you cannot buy it again
                        add_weapon(iter->second);
                        hero.setMoney(hero.getMoney() - iter->second._price);
                        hero.setAttack(hero.getAttack() + iter->second._damage);
                        cout << "\nYou have Successfully Bought " << iter->second._name << "\nIt has been added to your inventory\n";
                        cout << "your total items are: "<< weapon_inventory.size() << endl;
                        break;//break for loop
                    }
                    
                    else
                    {
                        cout << "You do not have enough money to buy this weapon\nPlease try again\n" << endl;
                        //system("CLS");//cout << string(50, '\n');
                        this->ArcherShop(hero);
                        break;//break for loop
                    }
                }
            }
            break;//break switch
            
        case 7:
            for (map <int, Weapon>::iterator iter = archer_weapons.begin(); iter != archer_weapons.end(); iter++)
            {
                if(iter->first == 7)
                {
                    if (hero.getMoney() >= iter->second._price)
                    {//Add a function-if you already have a weapon, you cannot buy it again
                        add_weapon(iter->second);
                        hero.setMoney(hero.getMoney() - iter->second._price);
                        hero.setAttack(hero.getAttack() + iter->second._damage);
                        cout << "\nYou have Successfully Bought " << iter->second._name << "\nIt has been added to your inventory\n";
                        cout << "your total items are: "<< weapon_inventory.size() << endl;
                        break;//break for loop
                    }
                    
                    else
                    {
                        cout << "You do not have enough money to buy this weapon\nPlease try again\n" << endl;
                        //system("CLS");//cout << string(50, '\n');
                        this->ArcherShop(hero);
                        break;//break for loop
                    }
                }
            }
            break;//break switch
            
        case 8:
            for (map <int, Weapon>::iterator iter = archer_weapons.begin(); iter != archer_weapons.end(); iter++)
            {
                if(iter->first == 8)
                {
                    if (hero.getMoney() >= iter->second._price)
                    {//Add a function-if you already have a weapon, you cannot buy it again
                        add_weapon(iter->second);
                        hero.setMoney(hero.getMoney() - iter->second._price);
                        hero.setAttack(hero.getAttack() + iter->second._damage);
                        cout << "\nYou have Successfully Bought " << iter->second._name << "\nIt has been added to your inventory\n";
                        cout << "your total items are: "<< weapon_inventory.size() << endl;
                        break;//break for loop
                    }
                    
                    else
                    {
                        cout << "You do not have enough money to buy this weapon\nPlease try again\n" << endl;
                        //system("CLS");//cout << string(50, '\n');
                        this->ArcherShop(hero);
                        break;//break for loop
                    }
                }
            }
            break;//break switch
            
        case 9: cout << "Exiting Bow shop...\n\n";
            break;
            
        default:
            cout << "Error! You have entered an invalid answer\nPlease try again";
            this->ArcherShop(hero);
	}
}