Permalink
Cannot retrieve contributors at this time
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?
Text-based-Game/inventory (1).cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
89 lines (84 sloc)
2.7 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} | |
} |