|
3 | 3 | #include <iomanip>
|
4 | 4 | #include <random>
|
5 | 5 |
|
| 6 | +#include "shm/inc/Alcohol.hpp" |
6 | 7 | #include "shm/inc/Cargo.hpp"
|
| 8 | +#include "shm/inc/DryFruit.hpp" |
| 9 | +#include "shm/inc/Fruit.hpp" |
7 | 10 | #include "shm/inc/Player.hpp"
|
8 | 11 |
|
9 | 12 | std::ostream& operator<<(std::ostream& out, const Store& store){
|
10 | 13 | for (size_t i = 0; i < store.cargo_.size(); i++) {
|
11 | 14 | out << "|" << std::setfill('-') << std::setw (100) << "|\n";
|
12 |
| - out << std::setw (10) << "| ID: " << i + 1; |
| 15 | + out << std::setfill(' ')<< std::setw (10) << "| ID: " << i + 1; |
13 | 16 | out << std::setw (30) << " | CARGO NAME: " << store.cargo_[i]->getName();
|
14 | 17 | out << std::setw (10) << " | AMOUNT: " << store.cargo_[i]->getAmount();
|
15 | 18 | out << std::setw (10) << " | PRICE: " << store.cargo_[i]->getPrice() << " |\n";
|
@@ -45,13 +48,76 @@ Store::Response Store::sell(Cargo* cargo, size_t amount, Player* player) {
|
45 | 48 | }
|
46 | 49 |
|
47 | 50 | void Store::nextDay() {
|
48 |
| - std::mt19937 generator(std::random_device{}()); |
49 |
| - std::uniform_int_distribution<size_t> distribution{ |
50 |
| - MIN_CARGO_IN_STORE, MAX_CARGO_IN_STORE |
51 |
| - }; |
52 |
| - |
53 | 51 | for (const auto& cargo : cargo_) {
|
54 |
| - cargo->setAmount(distribution(generator)); |
| 52 | + cargo->setAmount(randomGenerate(MIN_CARGO_IN_STORE, MAX_CARGO_IN_STORE)); |
55 | 53 | }
|
56 | 54 | }
|
57 | 55 |
|
| 56 | +size_t Store::randomGenerate(size_t min, size_t max) { |
| 57 | + std::mt19937 gen(std::random_device{}()); |
| 58 | + std::uniform_int_distribution<size_t> distribution(min, max); |
| 59 | + return distribution(gen); |
| 60 | +} |
| 61 | + |
| 62 | +Item::Rarity Store::rarityCoversion(size_t numberForConversion) { |
| 63 | + size_t multiplyRarity = 4; |
| 64 | + size_t addRarity = 1; |
| 65 | + return static_cast<Item::Rarity>((numberForConversion * multiplyRarity) + addRarity); |
| 66 | +} |
| 67 | + |
| 68 | +void Store::createAllCargo() { |
| 69 | + cargo_.reserve(40); |
| 70 | + createFruits(); |
| 71 | + createAlcohols(); |
| 72 | + createItems(); |
| 73 | + createDryFruits(); |
| 74 | +} |
| 75 | + |
| 76 | +void Store::createFruits() { |
| 77 | + cargo_.push_back(std::make_unique<Fruit>(Fruit("Orange", randomGenerate(0, 100), randomGenerate(10, 20)))); |
| 78 | + cargo_.push_back(std::make_unique<Fruit>(Fruit("Banana", randomGenerate(0, 100), randomGenerate(10, 20)))); |
| 79 | + cargo_.push_back(std::make_unique<Fruit>(Fruit("Apple", randomGenerate(0, 100), randomGenerate(10, 20)))); |
| 80 | + cargo_.push_back(std::make_unique<Fruit>(Fruit("Mango", randomGenerate(0, 100), randomGenerate(10, 20)))); |
| 81 | + cargo_.push_back(std::make_unique<Fruit>(Fruit("Lemon", randomGenerate(0, 100), randomGenerate(10, 20)))); |
| 82 | + cargo_.push_back(std::make_unique<Fruit>(Fruit("Grapes", randomGenerate(0, 100), randomGenerate(10, 20)))); |
| 83 | + cargo_.push_back(std::make_unique<Fruit>(Fruit("Strawberry", randomGenerate(0, 100), randomGenerate(10, 20)))); |
| 84 | + cargo_.push_back(std::make_unique<Fruit>(Fruit("Blueberry", randomGenerate(0, 100), randomGenerate(10, 20)))); |
| 85 | + cargo_.push_back(std::make_unique<Fruit>(Fruit("Raspberry", randomGenerate(0, 100), randomGenerate(10, 20)))); |
| 86 | + cargo_.push_back(std::make_unique<Fruit>(Fruit("Blackberry", randomGenerate(0, 100), randomGenerate(10, 20)))); |
| 87 | +} |
| 88 | + |
| 89 | +void Store::createAlcohols() { |
| 90 | + cargo_.push_back(std::make_unique<Alcohol>(Alcohol("Light beer", randomGenerate(0, 100), randomGenerate(10, 120), 3))); |
| 91 | + cargo_.push_back(std::make_unique<Alcohol>(Alcohol("Beer", randomGenerate(0, 100), randomGenerate(10, 140), 5))); |
| 92 | + cargo_.push_back(std::make_unique<Alcohol>(Alcohol("Dark beer", randomGenerate(0, 100), randomGenerate(15, 160), 7))); |
| 93 | + cargo_.push_back(std::make_unique<Alcohol>(Alcohol("White wine", randomGenerate(0, 100), randomGenerate(20, 180), 11))); |
| 94 | + cargo_.push_back(std::make_unique<Alcohol>(Alcohol("Red wine", randomGenerate(0, 100), randomGenerate(25, 200), 12))); |
| 95 | + cargo_.push_back(std::make_unique<Alcohol>(Alcohol("Martini", randomGenerate(0, 100), randomGenerate(30, 300), 15))); |
| 96 | + cargo_.push_back(std::make_unique<Alcohol>(Alcohol("Rum", randomGenerate(0, 100), randomGenerate(35, 400), 35))); |
| 97 | + cargo_.push_back(std::make_unique<Alcohol>(Alcohol("Whisky", randomGenerate(0, 100), randomGenerate(40, 500), 39))); |
| 98 | + cargo_.push_back(std::make_unique<Alcohol>(Alcohol("Vodka", randomGenerate(0, 100), randomGenerate(45, 600), 42))); |
| 99 | + cargo_.push_back(std::make_unique<Alcohol>(Alcohol("Gin", randomGenerate(0, 100), randomGenerate(50, 700), 37))); |
| 100 | + cargo_.push_back(std::make_unique<Alcohol>(Alcohol("Pure alcohol", randomGenerate(0, 100), randomGenerate(50, 700), 96))); |
| 101 | +} |
| 102 | + |
| 103 | +void Store::createItems() { |
| 104 | + cargo_.push_back(std::make_unique<Item>(Item("Knife", randomGenerate(0, 2), randomGenerate(1000, 2000), rarityCoversion(randomGenerate(0, 3))))); |
| 105 | + cargo_.push_back(std::make_unique<Item>(Item("Axe", randomGenerate(0, 2), randomGenerate(1000, 2000), rarityCoversion(randomGenerate(0, 3))))); |
| 106 | + cargo_.push_back(std::make_unique<Item>(Item("Lamp", randomGenerate(0, 2), randomGenerate(1000, 2000), rarityCoversion(randomGenerate(0, 3))))); |
| 107 | + cargo_.push_back(std::make_unique<Item>(Item("Helmet", randomGenerate(0, 2), randomGenerate(1000, 2000), rarityCoversion(randomGenerate(0, 3))))); |
| 108 | + cargo_.push_back(std::make_unique<Item>(Item("Gloves", randomGenerate(0, 2), randomGenerate(1000, 2000), rarityCoversion(randomGenerate(0, 3))))); |
| 109 | + cargo_.push_back(std::make_unique<Item>(Item("Shoes", randomGenerate(0, 2), randomGenerate(1000, 2000), rarityCoversion(randomGenerate(0, 3))))); |
| 110 | + cargo_.push_back(std::make_unique<Item>(Item("Pot", randomGenerate(0, 2), randomGenerate(1000, 2000), rarityCoversion(randomGenerate(0, 3))))); |
| 111 | + cargo_.push_back(std::make_unique<Item>(Item("Pan", randomGenerate(0, 2), randomGenerate(1000, 2000), rarityCoversion(randomGenerate(0, 3))))); |
| 112 | + cargo_.push_back(std::make_unique<Item>(Item("Plate", randomGenerate(0, 2), randomGenerate(1000, 2000), rarityCoversion(randomGenerate(0, 3))))); |
| 113 | + cargo_.push_back(std::make_unique<Item>(Item("Brush", randomGenerate(0, 2), randomGenerate(1000, 2000), rarityCoversion(randomGenerate(0, 3))))); |
| 114 | +} |
| 115 | + |
| 116 | +void Store::createDryFruits() { |
| 117 | + cargo_.push_back(std::make_unique<DryFruit>(DryFruit("Dry banana", randomGenerate(0, 300), randomGenerate(10, 20)))); |
| 118 | + cargo_.push_back(std::make_unique<DryFruit>(DryFruit("Raisins", randomGenerate(0, 300), randomGenerate(10, 20)))); |
| 119 | + cargo_.push_back(std::make_unique<DryFruit>(DryFruit("Dry apple", randomGenerate(0, 300), randomGenerate(10, 20)))); |
| 120 | + cargo_.push_back(std::make_unique<DryFruit>(DryFruit("Hazelnuts", randomGenerate(0, 300), randomGenerate(10, 20)))); |
| 121 | + cargo_.push_back(std::make_unique<DryFruit>(DryFruit("Cranberry", randomGenerate(0, 300), randomGenerate(10, 20)))); |
| 122 | +} |
| 123 | + |
0 commit comments