Compare commits
3
Commits
master
...
09810d6449
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09810d6449 | ||
|
|
7887ee2678 | ||
|
|
9bd09b0483 |
+77
@@ -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,36 @@
|
||||
//
|
||||
// Created by gustavomiranda on 27/09/24.
|
||||
//
|
||||
|
||||
#include "Player.h"
|
||||
|
||||
void Player::setMoney(int value){
|
||||
money = value;
|
||||
}
|
||||
|
||||
int Player::getCurrentMoney() {
|
||||
return money;
|
||||
}
|
||||
|
||||
void Player::incrementMoney(int value) {
|
||||
money += value;
|
||||
}
|
||||
|
||||
void Player::decrementMoney(int value) {
|
||||
if(money >= value){
|
||||
money -= value;
|
||||
}
|
||||
}
|
||||
Bag* Player::getInventory(){
|
||||
return inventory;
|
||||
}
|
||||
|
||||
Player::Player(){
|
||||
setMoney(2500);
|
||||
inventory = new Bag(100);
|
||||
|
||||
}
|
||||
|
||||
Player::~Player() {
|
||||
delete inventory;
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by gustavomiranda on 27/09/24.
|
||||
//
|
||||
|
||||
#ifndef DRUGWARS_PLAYER_H
|
||||
#define DRUGWARS_PLAYER_H
|
||||
|
||||
|
||||
#include "Bag.h"
|
||||
|
||||
class Player {
|
||||
private:
|
||||
int money;
|
||||
Bag * inventory;
|
||||
void setMoney(int value);
|
||||
public:
|
||||
Player();
|
||||
~Player();
|
||||
int getCurrentMoney();
|
||||
void incrementMoney(int value);
|
||||
void decrementMoney(int value);
|
||||
Bag *getInventory();
|
||||
};
|
||||
|
||||
|
||||
#endif //DRUGWARS_PLAYER_H
|
||||
Reference in New Issue
Block a user