Improved the inventory system, adding a methods to add multiple items and a way to store the indexes of the added items for counting and removing
This commit is contained in:
parent
658ca6ae5c
commit
559091a806
53
main.cpp
53
main.cpp
|
|
@ -19,8 +19,14 @@ class Bags{
|
||||||
std::vector<Objects> items;
|
std::vector<Objects> items;
|
||||||
std::map<std::string, std::vector<int>> indexesMap;
|
std::map<std::string, std::vector<int>> indexesMap;
|
||||||
|
|
||||||
|
Bags(){
|
||||||
|
indexesMap["Acid"] = std::vector<int>();
|
||||||
|
indexesMap["Weed"] = std::vector<int>();
|
||||||
|
indexesMap["Speed"] = std::vector<int>();
|
||||||
|
indexesMap["Cocaine"] = std::vector<int>();
|
||||||
|
indexesMap["Ludes"] = std::vector<int>();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void setCapacity(int size){
|
void setCapacity(int size){
|
||||||
this->max_Number_Items = size;
|
this->max_Number_Items = size;
|
||||||
|
|
@ -28,12 +34,33 @@ class Bags{
|
||||||
};
|
};
|
||||||
void addItem(Objects item){
|
void addItem(Objects item){
|
||||||
items.push_back(item);
|
items.push_back(item);
|
||||||
|
addIndexToIndexesMap(item);
|
||||||
|
|
||||||
}
|
}
|
||||||
void addMultipleItems(Objects item, int n){
|
void addIndexToIndexesMap(Objects item){
|
||||||
for (int i = 0; i<= n;i++){
|
switch (item) {
|
||||||
items.push_back(item);
|
case Acid:
|
||||||
|
indexesMap["Acid"].push_back(items.size()-1);
|
||||||
|
break;
|
||||||
|
case Weed:
|
||||||
|
indexesMap["Weed"].push_back(items.size()-1);
|
||||||
|
break;
|
||||||
|
case Speed:
|
||||||
|
indexesMap["Speed"].push_back(items.size()-1);
|
||||||
|
break;
|
||||||
|
case Cocaine:
|
||||||
|
indexesMap["Cocaine"].push_back(items.size()-1);
|
||||||
|
break;
|
||||||
|
case Ludes:
|
||||||
|
indexesMap["Ludes"].push_back(items.size()-1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
void addMultipleItems(Objects item, int n){
|
||||||
|
for (int i = 0; i< n;i++){
|
||||||
|
addItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -49,10 +76,17 @@ public:
|
||||||
class Player{
|
class Player{
|
||||||
private:
|
private:
|
||||||
int Money = 0;
|
int Money = 0;
|
||||||
Bags *inventory = new Basic_Trenchcoat;
|
Bags *inventory = new Basic_Trenchcoat();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
~Player(){
|
||||||
|
delete inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addItemsToInventory(Objects items, int n){
|
||||||
|
inventory->addMultipleItems(items,n);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -64,8 +98,15 @@ class Game{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Run(){
|
void Run(){
|
||||||
|
player->addItemsToInventory(Acid,150);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
~Game(){
|
||||||
|
delete player;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -73,7 +114,9 @@ class Game{
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Game *main = new Game;
|
Game *main = new Game;
|
||||||
|
main->Run();
|
||||||
|
|
||||||
|
delete main;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue