Skip to content

Commit 5804bfc

Browse files
Merge branch 'TEST_develop' into fix_delegate
2 parents 7a2ad00 + 351f1e2 commit 5804bfc

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

shm/inc/Store.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Player;
1010

1111
constexpr size_t MIN_CARGO_IN_STORE{ 0 };
1212
constexpr size_t MAX_CARGO_IN_STORE{ 100 };
13+
constexpr size_t STORE_CAPACITY { 1000 };
1314

1415
class Store : public Subscriber {
1516
public:

shm/src/Alcohol.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
#include <stdexcept>
44

5-
Alcohol::Alcohol(const std::string& name, size_t amount, size_t basePrice, size_t percentage)
6-
: Cargo(name, amount, basePrice)
7-
, percentage_(percentage)
8-
{}
5+
Alcohol::Alcohol(const std::string& name, size_t amount, size_t basePrice, size_t percentage)
6+
: Cargo(name, amount, basePrice), percentage_(percentage) {}
97

108
Cargo& Alcohol::operator+=(size_t amount) {
119
if (amount_ + amount > MAX_AMOUNT_OF_CARGO) {
@@ -20,9 +18,13 @@ Cargo& Alcohol::operator-=(size_t amount) {
2018
return *this;
2119
}
2220

23-
bool Alcohol::operator==(const Cargo& alcohol) const {
24-
// TODO:
25-
return alcohol.getAmount() == amount_ ? true : false;
21+
bool Alcohol::operator==(const Cargo& cargo) const {
22+
if (typeid(cargo) == typeid(Alcohol)) {
23+
const Alcohol* alcohol = static_cast<const Alcohol*>(&cargo);
24+
return name_ == alcohol->getName() && basePrice_ == alcohol->getBasePrice() &&
25+
percentage_ == alcohol->getPercentage();
26+
}
27+
return false;
2628
}
2729

2830
size_t Alcohol::getPrice() const {
@@ -33,7 +35,6 @@ size_t Alcohol::getPrice() const {
3335
void Alcohol::nextDay() {
3436
}
3537

36-
3738
size_t Alcohol::getPercentage() const {
3839
return percentage_;
3940
}

shm/src/Store.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include "shm/inc/Player.hpp"
77

88
Store::Response Store::buy(Cargo* cargo, size_t amount, Player* player) {
9+
if (!cargo) {
10+
return Response::lack_of_cargo;
11+
}
912
if (amount * cargo->getPrice() > player->getMoney()){
1013
return Response::lack_of_money;
1114
}
@@ -18,6 +21,16 @@ Store::Response Store::buy(Cargo* cargo, size_t amount, Player* player) {
1821
return Response::done;
1922
}
2023

24+
Store::Response Store::sell(Cargo* cargo, size_t amount, Player* player) {
25+
if (!cargo) {
26+
return Response::lack_of_cargo;
27+
}
28+
if (cargo->getAmount() + amount > STORE_CAPACITY) {
29+
return Response::lack_of_space;
30+
}
31+
return Response::done;
32+
}
33+
2134
void Store::nextDay() {
2235
std::mt19937 generator(std::random_device{}());
2336
std::uniform_int_distribution<size_t> distribution{
@@ -29,9 +42,3 @@ void Store::nextDay() {
2942
}
3043
}
3144

32-
Store::Response Store::sell(Cargo* cargo, size_t amount, Player* player) {
33-
if (cargo->getAmount() + amount > MAX_CARGO_IN_STORE) {
34-
return Response::lack_of_space;
35-
}
36-
return Response::done;
37-
}

0 commit comments

Comments
 (0)