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"
using namespace std;
void removeItem(int inventoryCount[4]);
void openInventory(int inventory[10]);
void addItem();
int inven[10] = {'0','1','0','0','1','0','0','2','2','2'};
std::map<int,std::string> itemDictionary;
int INV::inv()
{
/* string choice;
while (choice != "quit" )
{
cin >> choice;
if (choice == "open")
{*/
system("cls");
openInventory(inven);
/* }
}*/
return 0;
}
void openInventory(int inventory[10])
{
PlayerMenu playermenu;
itemDictionary.insert(std::make_pair(0,"empty slot"));
itemDictionary.insert(std::make_pair(1,"soap"));
itemDictionary.insert(std::make_pair(2,"shiv"));
itemDictionary.insert(std::make_pair(3,"pickaxe"));
int inventoryCount[4]= {0,0,0,0};
cout<<"*****Inventory******" << '\n';
for( int i = 0; i < 10; i = i + 1 )
{
switch(inventory[i])
{
case '0' :
inventoryCount[0] = inventoryCount[0] + 1;
break;
case '1' :
inventoryCount[1] = inventoryCount[1] + 1;
break;
case '2' :
inventoryCount[2] = inventoryCount[2] + 1;
break;
case '3' :
inventoryCount[3] = inventoryCount[3] + 1;
break;
default :
cout << "Invalid item" << '\n';
cout << (inventory[i]) << '\n';
break;
}
}
for( int i = 0; i < 4; i = i + 1 )
{
if (inventoryCount[i]>0)
{
cout << inventoryCount[i]<< " " << itemDictionary[i];
cout << '\n';
}
}
int userchoice;
cout << '\n' << "********************************************"<< '\n';
cout << '\n' << "What would you like to do "<< '\n';
cout <<"1 - drops an item of your choosing" <<'\n';
cout <<"2 - picks up an item of your choosing (option is only here for testing purposes until a legitimate means of getting items is included)" <<'\n';
cout <<"3 - leaves this interface " <<'\n';
cin >>userchoice;
switch(userchoice)
{
case 1 :
removeItem(inventoryCount);
break;
case 2 :
addItem();
cout << '\n';
break;
case 3 :
cout << '\n'<< "exiting inventory..."<< '\n';
Sleep(1000);
system("cls");
playermenu.ppmenu();
break;
default :
cout<< "Invalid input!" << '\n';
break;
}
}
void addItem()
{
cout << '\n' << "********************************************"<< '\n';
cout << '\n' <<"What item would you like added to your inventory?" << '\n';
cout << '\n' << "********************************************"<< '\n';
cout <<"1 - soap" <<'\n';
cout <<"2 - shiv" <<'\n';
cout <<"3 - pickaxe" <<'\n';
char newitem;
cin >> newitem;
switch(newitem)
{
case '1' :
cout << '\n' << "attempting to soap item to inventory"<< '\n';
break;
case '2' :
cout << '\n' << "attempting to shiv item to inventory"<< '\n';
break;
case '3' :
cout << '\n' << "attempting to pickaxe item to inventory"<< '\n';
break;
default :
cout<< "Invalid input!" << '\n';
break;
}
int check= 0;
for( int a = 0; a < 10; a = a + 1 )
{
if (inven[a] == 48)
{
if (check == 0)
{
inven[a] = newitem;
check = 1;
cout << '\n' << "Item added to inventory"<< '\n';
}
}
}
if (check == 0)
{
cout << '\n' << "No empty slots found, item adding failed"<< '\n';
}
}
void removeItem(int inventoryCount[4])
{
std::string itemname;
cout << "What item would you like to drop?"<< '\n';
cin >> itemname;
for( int i = 0; i < 4; i = i + 1 )
{
if (itemDictionary[i] == itemname)
{
if (inventoryCount[i] != 0)
{
int check= 0;
for( int a = 0; a < 10; a = a + 1 )
{
if (inven[a] == (48+i))
{
if (check == 0)
{
cout<< '\n'<< "Item dropped."<< '\n';
inven[a]= '0';
check = 1;
}
}
}
}
else
{
cout << "You dont have any of that item to drop!";
}
}
}
}