Skip to content

Commit 20e20d1

Browse files
Merge pull request coders-school#102 from lukasz-kukulka/generateStoreInIslands
Generate stores in every islands
2 parents 7a82b26 + 1c33e3e commit 20e20d1

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

shm/inc/Island.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#pragma once
22

33
#include <cstddef>
4+
#include <memory>
5+
6+
#include "shm/inc/Store.hpp"
47

58
// class responsible for manage landmass in game
69
class Island {
710
public:
8-
911
// class responsible for manage coordinates of islands in game
1012
class Coordinates {
1113
public:
@@ -23,7 +25,9 @@ class Island {
2325
explicit Island(const Island::Coordinates& position);
2426

2527
Coordinates getCoordinates() const { return position_; }
26-
28+
std::shared_ptr<Store> getStore() { return store_; }
29+
2730
private:
2831
const Coordinates position_;
32+
std::shared_ptr<Store>store_;
2933
};

shm/inc/Store.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ constexpr size_t STORE_CAPACITY { 1000 };
1515

1616
class Store : public Subscriber {
1717
public:
18-
18+
Store();
1919
enum class Response {
2020
done,
2121
lack_of_money,
@@ -32,13 +32,13 @@ class Store : public Subscriber {
3232
void nextDay() override;
3333
size_t randomGenerate(size_t min, size_t max);
3434
Item::Rarity rarityCoversion(size_t numberForConversion);
35-
35+
36+
private:
3637
void createAllCargo();
3738
void createFruits();
3839
void createAlcohols();
3940
void createItems();
4041
void createDryFruits();
4142

42-
private:
4343
std::vector<std::unique_ptr<Cargo>> cargo_;
4444
};

shm/src/Game.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Game::Game(size_t money, size_t gameDays, size_t finalGoal)
2323
void Game::startGame() {
2424
printWelcomeScreen();
2525
printIntenface();
26-
printMap();
26+
printMap();
2727
// while (game_days_ > current_day_) {
2828
// printMenu();
2929
// if (isGameWon()) {

shm/src/Island.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <cmath>
44

55
Island::Coordinates::Coordinates(size_t positionX, size_t positionY)
6-
76
: positionX_(positionX)
87
, positionY_(positionY)
98
{}
@@ -14,7 +13,9 @@ bool Island::Coordinates::operator==(const Coordinates& position) const {
1413

1514
Island::Island(const Island::Coordinates& position)
1615
: position_(position)
17-
{}
16+
{
17+
store_ = std::make_shared<Store>();
18+
}
1819

1920
size_t Island::Coordinates::distance(const Coordinates& lhs, const Coordinates& rhs) {
2021
size_t result = static_cast<size_t>(std::sqrt(std::pow((int)lhs.positionX_ - (int)rhs.positionX_, 2) + std::pow((int)lhs.positionY_ - (int)rhs.positionY_, 2)));

shm/src/Store.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
#include "shm/inc/Fruit.hpp"
1010
#include "shm/inc/Player.hpp"
1111

12+
Store::Store()
13+
{
14+
createAllCargo();
15+
}
16+
1217
std::ostream& operator<<(std::ostream& out, const Store& store){
1318
for (size_t i = 0; i < store.cargo_.size(); i++) {
1419
out << "|" << std::setfill('-') << std::setw (100) << "|\n";

0 commit comments

Comments
 (0)