Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include "inventory.h"
#include <iostream>>
using namespace std;
Inventory::Inventory()
{
}
void Inventory::addItem( char item[10], int & quantity, int & weapon, int & food, int & potion, int & sum, int & maxsum )
{
sum=weapon+food+potion;
if( sum == 0 )
cout<<"empty inventory"<<endl;
maxsum=maxsum;
if( sum == maxsum )
cout<<"full inventory"<<endl;
else
{
if( strcmp(item,"weapon") == 0 && sum+quantity <= maxsum )
{
weapon+=quantity;
sum+quantity;
}
if( strcmp(item,"food") == 0 && sum+quantity <= maxsum )
{
food+=quantity;
sum+=quantity;
}
if( strcmp(item,"potion") == 0 && sum+quantity <= maxsum)
{
potion+=quantity;
//weight+=quantity;
}
}
}
void Inventory::getItem(char item[10], int & weapon, int & food, int & sum, int & potion, int & quantity)
{
sum=weapon+food+potion;
if( sum == 0 )
cout<<"empty inventory"<<endl;
else
{
if( strcmp(item,"weapon") ==0 && sum-quantity >= 0 )
{
weapon-=quantity;
sum-=quantity;
}
if( strcmp(item,"food") == 0 && sum-quantity >= 0 )
{
food-=quantity;
sum-=quantity;
}
if( strcmp(item,"potion") == 0 && sum-quantity >= 0 )
{
potion-=quantity;
sum-=quantity;
}
}
}
void Inventory::display(int & weapon, int & food, int & potion, int & sum)
{
sum=weapon+food+potion;
if( sum == 0 )
cout<<"your inventory is empty";
else
{
if( weapon == 0 )
cout<<"you have no weapons"<<endl;
if( weapon == 1 )
cout<<"you have "<<weapon<<" weapon"<<endl;
if( weapon > 1 )
cout<<"you have "<<weapon<<" weapons"<<endl;
if( food == 0 )
cout<<"you have no food"<<endl;
if( food == 1 )
cout<<"you have "<<food<<" piece of food"<<endl;
if( food > 1 )
cout<<"you have "<<food<<" pieces of food"<<endl;
if( potion == 0 )
cout<<"you have no potions"<<endl;
if( potion == 1 )
cout<<"you have "<<potion<<" potion"<<endl;
if( potion > 1 )
cout<<"you have "<<potion<<" potions"<<endl;
}
}