Compare commits

..
5 Commits
7 changed files with 255 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.28)
project(Drugwars)
find_package(Doxygen REQUIRED)
set(CMAKE_CXX_STANDARD 20)
add_executable(Drugwars src/main.cpp
src/Bag.cpp
src/Player.cpp
src/Bank.cpp
)
target_include_directories(Drugwars PRIVATE src/include)
if(DOXYGEN_FOUND)
set(DOXYGEN_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/docs")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile @ONLY)
add_custom_target(doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} docs/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
endif()
+77
View File
@@ -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;
+28
View File
@@ -0,0 +1,28 @@
//
// Created by gustavomiranda on 27/09/24.
//
#include <cmath>
#include "Bank.h"
Bank::Bank(double taxvalue) {
setTax(taxvalue);
money = 0;
}
void Bank::depositMoney(int value) {
money += value;
}
void Bank::withdrawMoney(int value) {
if (money >= value){
money -= value;
}
}
int Bank::getMoney() {
return money;
}
void Bank::updateMoney() {
money = std::round(money * (1+tax));
}
+36
View File
@@ -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;
}
+41
View File
@@ -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
+22
View File
@@ -0,0 +1,22 @@
//
// Created by gustavomiranda on 27/09/24.
//
#ifndef DRUGWARS_BANK_H
#define DRUGWARS_BANK_H
class Bank{
private:
int money;
double tax;
void setTax(double value);
public:
Bank(double taxvalue);
void depositMoney(int value);
void withdrawMoney(int value);
int getMoney();
void updateMoney();
};
#endif //DRUGWARS_BANK_H
+26
View File
@@ -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