diff --git a/src/Bag.cpp b/src/Bag.cpp new file mode 100644 index 0000000..1ae9630 --- /dev/null +++ b/src/Bag.cpp @@ -0,0 +1,77 @@ +// +// Created by gustavomiranda on 27/09/24. +// + +#include "Bag.h" + +void Bag::incrementUsedCapacity() { + usedCapacity++; +} + +void Bag::decrementUsedCapacity() { + usedCapacity--; +} + +void Bag::setMaxCapacity(int n) { + maxCapacity = n; +} + +int Bag::getMaxCapacity() { + return maxCapacity; +} + +int Bag::getUsedCapacity() { + return usedCapacity; +} + +int Bag::getAvailableCapacity() { + return getMaxCapacity() - getUsedCapacity(); +} + +void Bag::addItem(DrugTypes item) { + if (getAvailableCapacity() > 0){ + items[item] += 1; + incrementUsedCapacity(); + } +} + +void Bag::addMultipleItems(DrugTypes item, int n) { + if(getAvailableCapacity() >= n && n > 0){ + for (int i = 0; i < n; i++){ + addItem(item); + } + } + +} + +int Bag::getAmountInBag(DrugTypes item) { + return items[item]; +} + +void Bag::subtractItem(DrugTypes item) { + if (items[item] >= 1){ + items[item] -= 1; + decrementUsedCapacity(); + + } +} + +void Bag::subtractMultipleItems(DrugTypes item, int n) { + if (items[item] >= n ){ + for (int i = 0;i < n;i++){ + subtractItem(item); + } + } +} + +Bag::Bag(int maxcapacity) { + setMaxCapacity(maxcapacity); + items[Acid] = 0; + items[Weed] = 0; + items[Speed] = 0; + items[Cocaine] = 0; + items[Ludes] = 0; + items[Heroin] = 0; +} + +Bag::~Bag() = default; diff --git a/src/include/Bag.h b/src/include/Bag.h new file mode 100644 index 0000000..512465f --- /dev/null +++ b/src/include/Bag.h @@ -0,0 +1,41 @@ +// +// Created by gustavomiranda on 27/09/24. +// + +#ifndef DRUGWARS_BAG_H +#define DRUGWARS_BAG_H + +#include + +enum DrugTypes{ + Acid, + Weed, + Speed, + Cocaine, + Ludes, + Heroin +}; + +class Bag { +private: + int maxCapacity; + int usedCapacity; + std::map items; + void incrementUsedCapacity(); + void decrementUsedCapacity(); + void setMaxCapacity(int n); +public: + Bag(int maxcapacity); + ~Bag(); + int getMaxCapacity(); + int getUsedCapacity(); + int getAvailableCapacity(); + void addItem(DrugTypes item); + void addMultipleItems(DrugTypes item, int n); + int getAmountInBag(DrugTypes item); + void subtractItem(DrugTypes item); + void subtractMultipleItems(DrugTypes item, int n); +}; + + +#endif //DRUGWARS_BAG_H