void use_inventory(enemy &players_enemy,family_member &player)
{
vector<std::string>::const_iterator inv_iter;
cout<<"--------------------------------------"<<endl;
cout<<" Inventory"<<endl;
cout<<"--------------------------------------"<<endl;
for(inv_iter = player.player_inventory.begin();inv_iter != player.player_inventory.end();inv_iter ++)
{
std::cout<<(inv_iter - player.player_inventory.begin())<<": "<<*inv_iter<<std::endl;
}
bool valid_choice = false;
int choice;
while(valid_choice == false)
{
cout<<"Type the name of the item you want to use: ";
cin>>choice;
if(player.player_inventory.at(choice) == "Small Potion")
{
use_small_potion(player,inv_iter,players_enemy,choice);
}
if(player.player_inventory.at(choice) == "Medium Potion")
{
use_medium_potion(player,inv_iter,players_enemy);
}
if(player.player_inventory.at(choice) == "Woma Potion")
{
use_woma_potion(player,inv_iter,players_enemy);
}
if(player.player_inventory.at(choice) == "Granada")
{
//use_granada();
}
}
}
void use_small_potion(family_member &player, vector<string>::const_iterator potion_iter,enemy players_enemy,int choice)
{
potion_iter = player.player_inventory.at(choice);
if(player.health != player.max_health)
{
clear_screen();
cout<<"You used a small potion and heal by 20 health points"<<endl;
player.health += 20;
if(player.health > player.max_health)
{
player.health = player.max_health;
}
clear_and_delay(3500);
player.player_inventory.erase(potion_iter);
fighting_loop(player,players_enemy);
}
if(player.health == player.max_health)
{
cout<<"You are at full health!";
fighting_loop(player,players_enemy);
}
}
void use_medium_potion(family_member &player, vector<string>::const_iterator potion_iter,enemy players_enemy)
{
if(player.health != player.max_health)
{
clear_screen();
cout<<"You used a medium potion and heal by 40 health points"<<endl;
player.health += 40;
if(player.health > player.max_health)
{
player.health = player.max_health;
}
clear_and_delay(3500);
player.player_inventory.erase(potion_iter);
fighting_loop(player,players_enemy);
}
if(player.health == player.max_health)
{
cout<<"You are at full health!";
fighting_loop(player,players_enemy);
}
}
void use_woma_potion(family_member &player, vector<string>::const_iterator potion_iter,enemy players_enemy)
{
if(player.health != player.max_health)
{
clear_screen();
cout<<"You use a woma potion and get fully healed"<<endl;
player.health = player.max_health;
if(player.health > player.max_health)
{
player.health = player.max_health;
}
clear_and_delay(3500);
player.player_inventory.erase(potion_iter);
fighting_loop(player,players_enemy);
}
if(player.health == player.max_health)
{
cout<<"You are at full health!";
fighting_loop(player,players_enemy);
}
}
void use_granada(family_member &player, enemy &players_enemy)
{
}
Deleting a specific element in a string of vectors.
Thank you for that, worked like a charm. I don't know how I didin't think of it, it's fairly simple. I guess my mind hasn't been clear these past few days.
Another question, say I want to acsess the last element in the vector (using at()) and I want to print it, how would I go about doing this.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement