Created the LoanShark.cpp and LoanShark.h to be used as the LoanShark class and also add a new method on the Player class that check if a value is less the money owned by the player
This commit is contained in:
parent
250d8523ec
commit
9786d5b661
|
|
@ -0,0 +1,52 @@
|
||||||
|
//
|
||||||
|
// Created by gustavomiranda on 27/09/24.
|
||||||
|
//
|
||||||
|
#include <cmath>
|
||||||
|
#include "LoanShark.h"
|
||||||
|
|
||||||
|
|
||||||
|
LoanShark::LoanShark(int money, double taxvalue) {
|
||||||
|
setOwnedMoney(money);
|
||||||
|
setTax(taxvalue);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoanShark::setTax(double taxvalue) {
|
||||||
|
tax = taxvalue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoanShark::setOwnedMoney(int money) {
|
||||||
|
ownedMoney = money;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int LoanShark::getOwnedMoney() {
|
||||||
|
return ownedMoney;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoanShark::payLoan(Player *playerreference, int money) {
|
||||||
|
if (playerreference->checkEnoughMoney(money)) {
|
||||||
|
if (money > ownedMoney) {
|
||||||
|
playerreference->decrementMoney(ownedMoney);
|
||||||
|
setOwnedMoney(0);
|
||||||
|
} else {
|
||||||
|
playerreference->decrementMoney(money);
|
||||||
|
ownedMoney -= money;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoanShark::getLoan(Player *playerreference, int money) {
|
||||||
|
ownedMoney += money;
|
||||||
|
playerreference->incrementMoney(money);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoanShark::updateOwnedMoney() {
|
||||||
|
ownedMoney = std::round(ownedMoney * (1+tax));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -34,3 +34,7 @@ Player::Player(){
|
||||||
Player::~Player() {
|
Player::~Player() {
|
||||||
delete inventory;
|
delete inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Player::checkEnoughMoney(int value) {
|
||||||
|
return money >= value;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
//
|
||||||
|
// Created by gustavomiranda on 27/09/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DRUGWARS_LOANSHARK_H
|
||||||
|
#define DRUGWARS_LOANSHARK_H
|
||||||
|
|
||||||
|
#include "Player.h"
|
||||||
|
|
||||||
|
class LoanShark{
|
||||||
|
private:
|
||||||
|
int ownedMoney;
|
||||||
|
double tax;
|
||||||
|
void setTax(double taxvalue);
|
||||||
|
void setOwnedMoney(int money);
|
||||||
|
public:
|
||||||
|
LoanShark(int money, double taxvalue);
|
||||||
|
int getOwnedMoney();
|
||||||
|
void payLoan(Player *playerreference, int money);
|
||||||
|
void getLoan(Player *playerreference, int money);
|
||||||
|
void updateOwnedMoney();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //DRUGWARS_LOANSHARK_H
|
||||||
Loading…
Reference in New Issue