-
Notifications
You must be signed in to change notification settings - Fork 87
Shm #110
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
Open
bartosz-gruszczyk
wants to merge
113
commits into
coders-school:shm
Choose a base branch
from
bartosz-gruszczyk:shm
base: shm
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Shm #110
Changes from all commits
Commits
Show all changes
113 commits
Select commit
Hold shift + click to select a range
b358851
fix #30
ziobron c5340c8
fix #84
ziobron 220bf13
fix #88, module3 almost removed
ziobron 44b8e81
Update 09-operators.md
BarTes8 5fc1b6f
Project start. First concept of files structure
bartosz-gruszczyk ea70a73
Files cargo.cpp and ship.cpp created. Methods impementations moved th…
bartosz-gruszczyk 5f82ef7
Task 'Zadanie 2' completed. Constructor and getters added to the clas…
bartosz-gruszczyk 268dd71
Adding operator ==
ploWoj 1f17478
Initialize files and made first functionality
Regggis 3f5d8f7
Added getPosition, Initialization, default constructor, some addition…
Regggis cd73046
Added island.cpp and island.hpp files
Morfiniusz 92d4e90
Adding player.hpp
ploWoj ae6a443
Adding player.cpp, player.hpp -corrected
ploWoj 99cdf86
getSpeed() implemented
ploWoj daa404b
implemented getCargo()
ploWoj 8637398
corrected
ploWoj ac8dc4b
'shm' and 'shmD4art' (zadanie3) branches megred
bartosz-gruszczyk 52bf2f5
Merge branch 'shmRegis' (zadanie 4) into 'shm'
bartosz-gruszczyk b1fe926
Changed capital letter in fiilenames Map.cpp and Map.hpp. Included is…
bartosz-gruszczyk 75cb5a2
Merge branch 'shmWoj'(zadanie 7) into 'shm'
bartosz-gruszczyk f0bd5b5
some changings in hpp i cpp files
ploWoj 714a9ba
Make some changes, and added getIsland function
Regggis f7233b5
Merge branch 'shmWoj'(with some corrections in Wojtek's tasks) into shm
bartosz-gruszczyk 9967da7
Merge branch 'shm_zad6_regis' into shm
bartosz-gruszczyk c4a1c7b
Changes changes changes
ploWoj 5a4cf38
some cleaning in cargo class
bartosz-gruszczyk 18f68ee
remove 'basePrice' comparison in operator== in Cargo class
bartosz-gruszczyk b212c45
Addign countAvailbaleSpace
ploWoj 3c8a7d7
Changes in Island class: better format-style, and improvemenet of ope…
bartosz-gruszczyk 4c184e8
fixing
ploWoj 54b9ed6
zadanie 5 implementation
bartosz-gruszczyk c63de9d
vector of islands change -> reference added... its probably wrong
bartosz-gruszczyk f12be8a
Merge branch 'shmWoj'(with zadanie 8) into shm
bartosz-gruszczyk ff3c21b
another code-style fixes
bartosz-gruszczyk d946046
Diffrent cargo
ploWoj 680db84
all changes
ploWoj c5f98ae
after hunks
ploWoj 1b9e862
Fixing a bug of operator-=
ploWoj c1b96cc
Fixing the bugs in getCargos()
ploWoj 1ab9d3d
Changes in Player class
ploWoj 5b7353f
Added new files coordinates.hpp/.cpp, modification of island.hpp - mo…
Morfiniusz 8de5823
Revert "Added new files coordinates.hpp/.cpp, modification of island.…
Morfiniusz 9ed1f3c
Added new files coordinates.hpp/.cpp, moved class coordinates to new …
Morfiniusz cd918ff
main
ploWoj 9fbb5a8
Fixing a bug in player, cargo and ship
ploWoj 44eb3f5
In coordinates class added new method distastance and change variable…
Morfiniusz 0fa6324
Map repaired, added Cmake, also changes to cargo, and island and adde…
Regggis c837a38
Vector of objects, map done (i hope)
Regggis 0e7d86e
Merge branch 'shmWoj' into shmFix1AllMerged
bartosz-gruszczyk bb12618
delete alkohol, fruit, item classes files (they're unnecessery for no…
bartosz-gruszczyk aae412a
Merge branch 'shmD4rth_task3_update' into shmFix1AllMerged
bartosz-gruszczyk 188c3b7
Merge branch 'shm_Regis_4_6_update' into shmFix1AllMerged
bartosz-gruszczyk b28eb70
remove 'Store' class files(unnecessery), plus some little style fixes
bartosz-gruszczyk fec6fd5
added Map class fix
bartosz-gruszczyk 763a42d
player chaneged
ploWoj 9bad12c
creating enum Response
ploWoj e7d5614
adding functionalities
ploWoj 3817b97
store.cpp
ploWoj e1ed853
remove unnecessary cout message 'island don't exist'
bartosz-gruszczyk 88acddd
changes
ploWoj 2a02c33
add types of cargos
ploWoj 03c6ce7
changes in store
ploWoj 0516f0e
changes in store
ploWoj eb4149c
some code cleaning
bartosz-gruszczyk 96044fd
Next day method for Ship and Cargo
Regggis f8ed192
adding generating stock_ of store
ploWoj d3dafd9
Another chaneges in Piradise
ploWoj 65e8c68
Next day in Store class
Regggis a34c2d6
Alcohol class added
bartosz-gruszczyk 2885a07
set some methods from cargo as virtual
bartosz-gruszczyk 79e0485
Fruit class added
bartosz-gruszczyk 3912043
Item class added
bartosz-gruszczyk a1fb936
added fruit, alcohol, item cpp files do CMakeLists.txt
bartosz-gruszczyk 5c3f05a
Operators in Cargo class: += -= == set as virtual. Classes Alcohol, I…
bartosz-gruszczyk 3d7c55c
added files time.cpp/hpp iObserver.hpp
Morfiniusz a52b949
Revert "added files time.cpp/hpp iObserver.hpp"
Morfiniusz c2e251d
added new files time.cpp hpp iObserver.hpp
Morfiniusz b1a3aca
modification time.cpp/hpp changed shared_ptr to ptr, cargo class Inhe…
Morfiniusz 0984f02
modification of Ship constructors added time variable and iheritance …
Morfiniusz d320f4e
Better randomizing process in nextDay
Regggis 85d5b75
Merge branch 'shm2_zad2_bart' into shm2_working_branch
bartosz-gruszczyk 7990ddb
fixed mistaken names in Time Class (Obeserver to Observer)
bartosz-gruszczyk 5d99fbc
Merge branch 'StorSHM' into shm2_working_branch
bartosz-gruszczyk 8a129e5
cleaning after merge (build dir)
bartosz-gruszczyk 9e4155f
another small bug fixes (function declarations etc.)
bartosz-gruszczyk 26c4daf
syntax fix in main.cpp
bartosz-gruszczyk 4a3ed88
Merge branch 'shm2_zad_3_regis' into shm2_working_branch
bartosz-gruszczyk 2a51252
another small after-merge fixes
bartosz-gruszczyk eae7cb9
changes in store class
ploWoj 755efc9
adding game class
ploWoj 6dee2fd
teamwork improvements 1
bartosz-gruszczyk fda7c7b
pointer to owner added to class Ship
bartosz-gruszczyk 4dca07a
nextDay() in Fruit class
bartosz-gruszczyk 5c2c99e
teamork final commit
bartosz-gruszczyk 897ac40
nextDay() in store repaired
Regggis f89d725
Vector of shared_ptr removed from Cargos
Regggis 407dc63
Segmentatio fault disaster
Regggis f376156
Adding new functionalities to game
Regggis 482f093
Some more changes and checking of possiblities
Regggis 5fc35a9
Only sell to write (I hope)
Regggis 81bc456
Almost, ALMOSTgit add .
Regggis 83216df
Only some esthetic to done (I hope)
Regggis f78999f
Only some esthetic to done (I hope) vol2
Regggis 3b60c1c
finally done
Regggis a3dff7b
finally done2
Regggis 4a94837
Some changes after review
Regggis f31e2cd
Operators and polymorphism left to do
Regggis 6310af7
Fixed bug where we cannot buy more stuff of the same object
Regggis 4d5803a
Operators removed from Cargo; const shared_ptr reference everywhere; …
Regggis 2a8230f
Ship TEST implementation
ploWoj b058834
Constexpr Coordinates working
Regggis 337b091
Polimorphism / functions commented
Regggis e1399df
All review problems resolved
Regggis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
set (CMAKE_CXX_STANDARD 20) | ||
set (CMAKE_CXX_STANDARD_REQUIRED ON) | ||
project(SHM_2077) | ||
|
||
|
||
include(FetchContent) | ||
FetchContent_Declare( | ||
googletest | ||
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip | ||
) | ||
# For Windows: Prevent overriding the parent project's compiler/linker settings | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
FetchContent_MakeAvailable(googletest) | ||
|
||
set(FILES | ||
island.cpp | ||
map.cpp | ||
player.cpp | ||
ship.cpp | ||
cargo.cpp | ||
store.cpp | ||
alcohol.cpp | ||
item.cpp | ||
fruit.cpp | ||
time.cpp | ||
game.cpp | ||
) | ||
|
||
set(FLAGS | ||
-Wall | ||
#-Wextra | ||
-Wpedantic | ||
-Wconversion | ||
-O0) | ||
|
||
|
||
|
||
add_executable(${PROJECT_NAME} main.cpp ${FILES}) | ||
|
||
add_executable(ShipTest_gt test/ship_gt.cpp ${FILES}) | ||
target_link_libraries(ShipTest_gt gtest_main) | ||
target_link_directories(ShipTest_gt PUBLIC ${CMAKE_SOURCE_DIR}) | ||
add_test(NAME ShipTest COMMAND Ship) | ||
|
||
|
||
target_compile_options(${PROJECT_NAME} PRIVATE ${FLAGS}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "alcohol.hpp" | ||
#include <iostream> | ||
#include <limits> | ||
|
||
Alcohol::Alcohol(const std::string& name, size_t amount, size_t basePrice, size_t percentage) | ||
: Cargo(name, amount, basePrice), percentage_(percentage) {} ; | ||
|
||
size_t Alcohol::getPrice() const { | ||
return static_cast<size_t>(basePrice_ * static_cast<float>(percentage_) / static_cast<float>(MaxPercentage)); | ||
} | ||
|
||
std::shared_ptr<Cargo> Alcohol::clone(const size_t &amount) const { | ||
return std::make_shared<Alcohol>(this->getName(), | ||
amount, | ||
this->getBasePrice(), | ||
this->getPercentage()); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
#include "cargo.hpp" | ||
|
||
constexpr size_t MaxPercentage{96}; | ||
class Alcohol : public Cargo { | ||
public: | ||
Alcohol(const std::string& name, size_t amount, size_t basePrice, size_t percentage); | ||
Alcohol() = default; | ||
~Alcohol() override {}; | ||
|
||
size_t getPercentage() const { return percentage_; }; | ||
void setPercentage(size_t percentage) { percentage_ = percentage; }; | ||
|
||
//Methods override from Cargo class. | ||
size_t getPrice() const override; | ||
|
||
void nextDay() override {}; | ||
|
||
std::shared_ptr<Cargo> clone(const size_t &) const; | ||
|
||
void setTime(const std::shared_ptr<Time>&) override {}; | ||
void detachingObserver() override {}; | ||
private: | ||
size_t percentage_; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "cargo.hpp" | ||
|
||
#include <iostream> | ||
#include <limits> | ||
|
||
|
||
Cargo::Cargo(const std::string& name, size_t amount, size_t basePrice, std::shared_ptr<Time> time) | ||
: name_(name) | ||
, amount_(amount) | ||
, basePrice_(basePrice) | ||
, time_(time) | ||
{ | ||
if (time_) { | ||
time_->attachObserver(this); | ||
} | ||
} | ||
|
||
Cargo::Cargo(const std::string& name, size_t amount, size_t basePrice) | ||
: name_(name) | ||
, amount_(amount) | ||
, basePrice_(basePrice) | ||
{}; | ||
|
||
Cargo& Cargo::operator+=(size_t amount) { | ||
if (amount_ + amount < std::numeric_limits<size_t>::max()) { | ||
amount_ += amount; | ||
} | ||
return *this; | ||
} | ||
|
||
Cargo& Cargo::operator-=(size_t amount) { | ||
if (amount_ >= amount ) { | ||
amount_ -= amount; | ||
} | ||
return *this; | ||
} | ||
|
||
bool Cargo::operator==(const Cargo& cargo) const { | ||
return cargo.getName() == getName(); | ||
} | ||
|
||
std::string Cargo::getName() const { | ||
return name_; | ||
} | ||
|
||
size_t Cargo::getAmount() const { | ||
return amount_; | ||
} | ||
|
||
size_t Cargo::getBasePrice() const { | ||
return basePrice_; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
#pragma once | ||
#include <string> | ||
#include "time.hpp" | ||
#include "iObserver.hpp" | ||
|
||
class Cargo : public IObserver { | ||
public: | ||
Cargo() = default; | ||
Cargo(const std::string& name, size_t amount) : name_(name), amount_(amount) {}; | ||
Cargo(const std::string& name, size_t amount, size_t basePrice, std::shared_ptr<Time> time); | ||
Cargo(const std::string& name, size_t amount, size_t basePrice); | ||
virtual ~Cargo() = default; | ||
|
||
Cargo& operator+=(size_t amount); | ||
Cargo& operator-=(size_t amount); | ||
bool operator==(const Cargo&) const; | ||
|
||
std::string getName() const; | ||
size_t getAmount() const; | ||
size_t getBasePrice() const; | ||
|
||
virtual size_t getPrice() const = 0; | ||
|
||
virtual std::shared_ptr<Cargo> clone(const size_t &) const = 0; | ||
|
||
virtual void setTime(const std::shared_ptr<Time>&) = 0; | ||
|
||
virtual void detachingObserver() = 0; | ||
|
||
protected: | ||
std::string name_; | ||
size_t amount_; | ||
size_t basePrice_; | ||
std::shared_ptr<Time> time_ {nullptr}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
#include <cmath> | ||
|
||
class Coordinates { | ||
public: | ||
constexpr Coordinates(size_t positionX, size_t positionY) | ||
: positionX_(positionX) | ||
, positionY_(positionY) | ||
{} | ||
|
||
constexpr void setPositionX(size_t positionX) { positionX_ = positionX; }; | ||
|
||
constexpr size_t getPositionX() const { return positionX_; }; | ||
|
||
constexpr void setPositionY(size_t positionY) { positionY_ = positionY; }; | ||
constexpr size_t getPositionY() const { return positionY_; }; | ||
|
||
constexpr bool operator== (const Coordinates& n_pos) const { | ||
return positionX_ == n_pos.getPositionX() && positionY_ == n_pos.getPositionY(); | ||
}; | ||
|
||
constexpr size_t distance(const Coordinates& rhs) { | ||
return std::round(std::sqrt(std::pow((static_cast<int>(positionX_) - static_cast<int>(rhs.getPositionX())), 2) + | ||
std::pow((static_cast<int>(positionY_) - static_cast<int>(rhs.getPositionY())), 2))); }; | ||
|
||
private: | ||
size_t positionX_; | ||
size_t positionY_; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "fruit.hpp" | ||
#include <iostream> | ||
#include <limits> | ||
|
||
Fruit::Fruit(const std::string &name, size_t amount, size_t basePrice, size_t expirationDate, std::shared_ptr<Time> time) : Cargo(name, amount, basePrice, time), expirationDate_(expirationDate){ | ||
}; | ||
|
||
Fruit::~Fruit() { time_->detachObserver(this); }; | ||
|
||
size_t Fruit::getPrice() const | ||
{ | ||
return static_cast<size_t>(basePrice_ * static_cast<float>(purchaseDate_) / expirationDate_); | ||
} | ||
|
||
Fruit &Fruit::operator--() | ||
{ | ||
if (purchaseDate_ <= 0) | ||
{ | ||
purchaseDate_ = 0; | ||
} | ||
purchaseDate_--; | ||
return *this; | ||
} | ||
|
||
void Fruit::nextDay() | ||
{ | ||
if (purchaseDate_) | ||
{ | ||
operator--(); | ||
} | ||
} | ||
|
||
std::shared_ptr<Cargo> Fruit::clone(const size_t &amount) const { | ||
return std::make_shared<Fruit>(this->getName(), | ||
amount, | ||
this->getBasePrice(), | ||
this->getExpirationDate(), | ||
time_); | ||
} | ||
|
||
void Fruit::setTime(const std::shared_ptr<Time>& time) { | ||
time_ = time; | ||
} | ||
|
||
void Fruit::detachingObserver() { | ||
time_->detachObserver(this); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "cargo.hpp" | ||
//Class responsible for managing Fruit in the game. | ||
class Fruit : public Cargo { | ||
public: | ||
Fruit(const std::string& name, size_t amount, size_t basePrice, size_t expirationDate, std::shared_ptr<Time> time); | ||
~Fruit() override; | ||
|
||
Fruit& operator--(); | ||
|
||
//Methods override from Cargo class. | ||
size_t getPrice() const override; | ||
|
||
size_t getExpirationDate() const { return expirationDate_; }; | ||
size_t getPurchaseData() const { return purchaseDate_; }; | ||
|
||
void nextDay() override; | ||
|
||
std::shared_ptr<Cargo> clone(const size_t &) const; | ||
|
||
void setTime(const std::shared_ptr<Time>&) override; | ||
|
||
void detachingObserver() override; | ||
|
||
protected: | ||
size_t expirationDate_; | ||
size_t purchaseDate_ = expirationDate_; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You never detach observer. This will cause crash when this object will be deleted