Created the Bag Class used to be used as inventory and stash for the game.
This commit is contained in:
parent
559091a806
commit
9bd09b0483
|
|
@ -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;
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
//
|
||||||
|
// Created by gustavomiranda on 27/09/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DRUGWARS_BAG_H
|
||||||
|
#define DRUGWARS_BAG_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
enum DrugTypes{
|
||||||
|
Acid,
|
||||||
|
Weed,
|
||||||
|
Speed,
|
||||||
|
Cocaine,
|
||||||
|
Ludes,
|
||||||
|
Heroin
|
||||||
|
};
|
||||||
|
|
||||||
|
class Bag {
|
||||||
|
private:
|
||||||
|
int maxCapacity;
|
||||||
|
int usedCapacity;
|
||||||
|
std::map<DrugTypes,int> 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
|
||||||
Loading…
Reference in New Issue