Skip to content

13 cs task3 #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions shm/source/Delegate.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

class Delegate {
public:
// ~Delegate();

virtual void payCrew(size_t price) = 0;
};
10 changes: 6 additions & 4 deletions shm/source/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ Cargo* Player::getCargo(size_t index) const {
return nullptr;
}

//void Player::PayCrew(size_t money) override;
void Player::payCrew(size_t price) {
money_ = (money_ > price)? money_ - price : 0;
}

//void Player::PurchaseCargo(std::unique_ptr<Cargo> cargo, size_t price);
// void Player::PurchaseCargo(std::unique_ptr<Cargo> cargo, size_t price);

//void Player::SellCargo(Cargo* cargo, size_t price);
// void Player::SellCargo(Cargo* cargo, size_t price);

//void Player::PrintCargo() const;
// void Player::PrintCargo() const;

void Player::calculateAvailableSpace() {
if (!ship_) {
Expand Down
12 changes: 7 additions & 5 deletions shm/source/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

#include <memory>

#include "Delegate.hpp"

class Ship;
class Cargo;

class Player {
class Player : Delegate {
Ship* ship_;
size_t money_;
std::pair<size_t, bool> availableSpace_;
Expand All @@ -21,13 +23,13 @@ class Player {

Cargo* getCargo(size_t index) const;

// void PayCrew(size_t money) override;
void payCrew(size_t price) override;

//void PurchaseCargo(std::unique_ptr<Cargo> cargo, size_t price);
// void PurchaseCargo(std::unique_ptr<Cargo> cargo, size_t price);

//void SellCargo(Cargo* cargo, size_t price);
// void SellCargo(Cargo* cargo, size_t price);

//void PrintCargo() const;
// void PrintCargo() const;

private:
void calculateAvailableSpace();
Expand Down
9 changes: 5 additions & 4 deletions shm/source/Ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
#include <algorithm>

Ship::Ship()
: Ship(0, 0, 0, "", -1, nullptr)
: Ship(0, 0, 0, "", -1, nullptr, nullptr)
{}

Ship::Ship(int maxCrew, int speed, size_t id)
: Ship(0, maxCrew, speed, "", id, nullptr)
: Ship(0, maxCrew, speed, "", id, nullptr, nullptr)
{}

Ship::Ship(int capacity, int maxCrew, int speed, const std::string& name, size_t id, Time* time)
Ship::Ship(int capacity, int maxCrew, int speed, const std::string& name, size_t id, Time* time, Delegate* delegate)
: name_(name)
, capacity_(capacity)
, maxCrew_(maxCrew)
, id_(id)
, crew_(0)
, speed_(speed)
, time_(time)
, delegate_(delegate)
, cargo_()
{}

Expand Down Expand Up @@ -91,5 +92,5 @@ Cargo* Ship::getCargo(const size_t index) const {
// void Ship::RemoveFromStorage(Cargo* cargo);

void Ship::nextDay() {

delegate_->payCrew(crew_);
}
6 changes: 3 additions & 3 deletions shm/source/Ship.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "Observer.hpp"
#include "Time.hpp"
//#include "Delegate.hpp"
#include "Delegate.hpp"

#include <memory>
#include <string>
Expand All @@ -18,15 +18,15 @@ class Ship : Observer {
size_t crew_;
size_t speed_;
Time* time_;
//Delegate* delegate_;
Delegate* delegate_;
std::vector<std::unique_ptr<Cargo>> cargo_;

public:
Ship();

Ship(int maxCrew, int speed, size_t id);

Ship(int capacity, int maxCrew, int speed, const std::string& name, size_t id, Time* time);
Ship(int capacity, int maxCrew, int speed, const std::string& name, size_t id, Time* time, Delegate* delegate);

// ~Ship() override;

Expand Down
6 changes: 4 additions & 2 deletions shm/source/Store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

// ~Store() override;

void nextDay() {

void Store::nextDay() {
for (auto& good : cargo_) {
good->nextDay();
}
}

// Cargo* GetCargo(const size_t pos);
Expand Down
4 changes: 2 additions & 2 deletions shm/source/Store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Store : Observer {
Lack_of_space
};

// Time* time_;
// std::vector<std::unique_ptr<Cargo>> cargo_;
Time* time_;
std::vector<std::unique_ptr<Cargo>> cargo_;

public:
// Store(Time* time);
Expand Down