78 lines
1.3 KiB
C++
78 lines
1.3 KiB
C++
//
|
|
// 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;
|