本文整理汇总了C++中Hero::getMoney方法的典型用法代码示例。如果您正苦于以下问题:C++ Hero::getMoney方法的具体用法?C++ Hero::getMoney怎么用?C++ Hero::getMoney使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hero
的用法示例。
在下文中一共展示了Hero::getMoney方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mainShop
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);
}
}
示例2: ArcherShop
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
//.........这里部分代码省略.........