Skip to content
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

Shm #110

Open
wants to merge 113 commits into
base: shm
Choose a base branch
from
Open

Shm #110

Show file tree
Hide file tree
Changes from 105 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
b358851
fix #30
ziobron Jun 11, 2021
c5340c8
fix #84
ziobron Jun 11, 2021
220bf13
fix #88, module3 almost removed
ziobron Jun 11, 2021
44b8e81
Update 09-operators.md
BarTes8 Jun 14, 2021
5fc1b6f
Project start. First concept of files structure
bartosz-gruszczyk Jun 17, 2021
ea70a73
Files cargo.cpp and ship.cpp created. Methods impementations moved th…
bartosz-gruszczyk Jun 20, 2021
5f82ef7
Task 'Zadanie 2' completed. Constructor and getters added to the clas…
bartosz-gruszczyk Jun 20, 2021
268dd71
Adding operator ==
ploWoj Jun 20, 2021
1f17478
Initialize files and made first functionality
Regggis Jun 22, 2021
3f5d8f7
Added getPosition, Initialization, default constructor, some addition…
Regggis Jun 22, 2021
cd73046
Added island.cpp and island.hpp files
Morfiniusz Jun 22, 2021
92d4e90
Adding player.hpp
ploWoj Jun 23, 2021
ae6a443
Adding player.cpp, player.hpp -corrected
ploWoj Jun 23, 2021
99cdf86
getSpeed() implemented
ploWoj Jun 23, 2021
daa404b
implemented getCargo()
ploWoj Jun 23, 2021
8637398
corrected
ploWoj Jun 23, 2021
ac8dc4b
'shm' and 'shmD4art' (zadanie3) branches megred
bartosz-gruszczyk Jun 26, 2021
52bf2f5
Merge branch 'shmRegis' (zadanie 4) into 'shm'
bartosz-gruszczyk Jun 26, 2021
b1fe926
Changed capital letter in fiilenames Map.cpp and Map.hpp. Included is…
bartosz-gruszczyk Jun 26, 2021
75cb5a2
Merge branch 'shmWoj'(zadanie 7) into 'shm'
bartosz-gruszczyk Jun 26, 2021
f0bd5b5
some changings in hpp i cpp files
ploWoj Jun 26, 2021
714a9ba
Make some changes, and added getIsland function
Regggis Jun 26, 2021
f7233b5
Merge branch 'shmWoj'(with some corrections in Wojtek's tasks) into shm
bartosz-gruszczyk Jun 26, 2021
9967da7
Merge branch 'shm_zad6_regis' into shm
bartosz-gruszczyk Jun 26, 2021
c4a1c7b
Changes changes changes
ploWoj Jun 27, 2021
5a4cf38
some cleaning in cargo class
bartosz-gruszczyk Jun 27, 2021
18f68ee
remove 'basePrice' comparison in operator== in Cargo class
bartosz-gruszczyk Jun 28, 2021
b212c45
Addign countAvailbaleSpace
ploWoj Jun 28, 2021
3c8a7d7
Changes in Island class: better format-style, and improvemenet of ope…
bartosz-gruszczyk Jun 28, 2021
4c184e8
fixing
ploWoj Jun 28, 2021
54b9ed6
zadanie 5 implementation
bartosz-gruszczyk Jun 28, 2021
c63de9d
vector of islands change -> reference added... its probably wrong
bartosz-gruszczyk Jun 28, 2021
f12be8a
Merge branch 'shmWoj'(with zadanie 8) into shm
bartosz-gruszczyk Jun 28, 2021
ff3c21b
another code-style fixes
bartosz-gruszczyk Jun 28, 2021
d946046
Diffrent cargo
ploWoj Jun 30, 2021
680db84
all changes
ploWoj Jul 2, 2021
c5f98ae
after hunks
ploWoj Jul 2, 2021
1b9e862
Fixing a bug of operator-=
ploWoj Jul 2, 2021
c1b96cc
Fixing the bugs in getCargos()
ploWoj Jul 2, 2021
1ab9d3d
Changes in Player class
ploWoj Jul 2, 2021
5b7353f
Added new files coordinates.hpp/.cpp, modification of island.hpp - mo…
Morfiniusz Jul 6, 2021
8de5823
Revert "Added new files coordinates.hpp/.cpp, modification of island.…
Morfiniusz Jul 6, 2021
9ed1f3c
Added new files coordinates.hpp/.cpp, moved class coordinates to new …
Morfiniusz Jul 6, 2021
cd918ff
main
ploWoj Jul 7, 2021
9fbb5a8
Fixing a bug in player, cargo and ship
ploWoj Jul 10, 2021
44eb3f5
In coordinates class added new method distastance and change variable…
Morfiniusz Jul 14, 2021
0fa6324
Map repaired, added Cmake, also changes to cargo, and island and adde…
Regggis Jul 15, 2021
c837a38
Vector of objects, map done (i hope)
Regggis Jul 15, 2021
0e7d86e
Merge branch 'shmWoj' into shmFix1AllMerged
bartosz-gruszczyk Jul 18, 2021
bb12618
delete alkohol, fruit, item classes files (they're unnecessery for no…
bartosz-gruszczyk Jul 18, 2021
aae412a
Merge branch 'shmD4rth_task3_update' into shmFix1AllMerged
bartosz-gruszczyk Jul 18, 2021
188c3b7
Merge branch 'shm_Regis_4_6_update' into shmFix1AllMerged
bartosz-gruszczyk Jul 18, 2021
b28eb70
remove 'Store' class files(unnecessery), plus some little style fixes
bartosz-gruszczyk Jul 18, 2021
fec6fd5
added Map class fix
bartosz-gruszczyk Jul 18, 2021
763a42d
player chaneged
ploWoj Jul 19, 2021
9bad12c
creating enum Response
ploWoj Jul 19, 2021
e7d5614
adding functionalities
ploWoj Jul 19, 2021
3817b97
store.cpp
ploWoj Jul 19, 2021
e1ed853
remove unnecessary cout message 'island don't exist'
bartosz-gruszczyk Jul 19, 2021
88acddd
changes
ploWoj Jul 20, 2021
2a02c33
add types of cargos
ploWoj Jul 20, 2021
03c6ce7
changes in store
ploWoj Jul 21, 2021
0516f0e
changes in store
ploWoj Jul 21, 2021
eb4149c
some code cleaning
bartosz-gruszczyk Jul 21, 2021
96044fd
Next day method for Ship and Cargo
Regggis Jul 29, 2021
f8ed192
adding generating stock_ of store
ploWoj Jul 31, 2021
d3dafd9
Another chaneges in Piradise
ploWoj Aug 1, 2021
65e8c68
Next day in Store class
Regggis Aug 2, 2021
a34c2d6
Alcohol class added
bartosz-gruszczyk Aug 8, 2021
2885a07
set some methods from cargo as virtual
bartosz-gruszczyk Aug 8, 2021
79e0485
Fruit class added
bartosz-gruszczyk Aug 9, 2021
3912043
Item class added
bartosz-gruszczyk Aug 9, 2021
a1fb936
added fruit, alcohol, item cpp files do CMakeLists.txt
bartosz-gruszczyk Aug 9, 2021
5c3f05a
Operators in Cargo class: += -= == set as virtual. Classes Alcohol, I…
bartosz-gruszczyk Aug 9, 2021
3d7c55c
added files time.cpp/hpp iObserver.hpp
Morfiniusz Aug 12, 2021
a52b949
Revert "added files time.cpp/hpp iObserver.hpp"
Morfiniusz Aug 12, 2021
c2e251d
added new files time.cpp hpp iObserver.hpp
Morfiniusz Aug 12, 2021
b1a3aca
modification time.cpp/hpp changed shared_ptr to ptr, cargo class Inhe…
Morfiniusz Aug 12, 2021
0984f02
modification of Ship constructors added time variable and iheritance …
Morfiniusz Aug 12, 2021
d320f4e
Better randomizing process in nextDay
Regggis Aug 13, 2021
85d5b75
Merge branch 'shm2_zad2_bart' into shm2_working_branch
bartosz-gruszczyk Aug 16, 2021
7990ddb
fixed mistaken names in Time Class (Obeserver to Observer)
bartosz-gruszczyk Aug 16, 2021
5d99fbc
Merge branch 'StorSHM' into shm2_working_branch
bartosz-gruszczyk Aug 16, 2021
8a129e5
cleaning after merge (build dir)
bartosz-gruszczyk Aug 16, 2021
9e4155f
another small bug fixes (function declarations etc.)
bartosz-gruszczyk Aug 16, 2021
26c4daf
syntax fix in main.cpp
bartosz-gruszczyk Aug 16, 2021
4a3ed88
Merge branch 'shm2_zad_3_regis' into shm2_working_branch
bartosz-gruszczyk Aug 16, 2021
2a51252
another small after-merge fixes
bartosz-gruszczyk Aug 16, 2021
eae7cb9
changes in store class
ploWoj Aug 27, 2021
755efc9
adding game class
ploWoj Aug 27, 2021
6dee2fd
teamwork improvements 1
bartosz-gruszczyk Aug 29, 2021
fda7c7b
pointer to owner added to class Ship
bartosz-gruszczyk Aug 29, 2021
4dca07a
nextDay() in Fruit class
bartosz-gruszczyk Aug 29, 2021
5c2c99e
teamork final commit
bartosz-gruszczyk Aug 29, 2021
897ac40
nextDay() in store repaired
Regggis Sep 3, 2021
f89d725
Vector of shared_ptr removed from Cargos
Regggis Sep 7, 2021
407dc63
Segmentatio fault disaster
Regggis Sep 7, 2021
f376156
Adding new functionalities to game
Regggis Sep 11, 2021
482f093
Some more changes and checking of possiblities
Regggis Sep 11, 2021
5fc35a9
Only sell to write (I hope)
Regggis Sep 12, 2021
81bc456
Almost, ALMOSTgit add .
Regggis Sep 12, 2021
83216df
Only some esthetic to done (I hope)
Regggis Sep 13, 2021
f78999f
Only some esthetic to done (I hope) vol2
Regggis Sep 13, 2021
3b60c1c
finally done
Regggis Sep 13, 2021
a3dff7b
finally done2
Regggis Sep 13, 2021
4a94837
Some changes after review
Regggis Sep 23, 2021
f31e2cd
Operators and polymorphism left to do
Regggis Sep 26, 2021
6310af7
Fixed bug where we cannot buy more stuff of the same object
Regggis Oct 10, 2021
4d5803a
Operators removed from Cargo; const shared_ptr reference everywhere; …
Regggis Oct 10, 2021
2a8230f
Ship TEST implementation
ploWoj Oct 21, 2021
b058834
Constexpr Coordinates working
Regggis Oct 21, 2021
337b091
Polimorphism / functions commented
Regggis Oct 21, 2021
e1399df
All review problems resolved
Regggis Oct 21, 2021
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
28 changes: 28 additions & 0 deletions shm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.10)

project(SHM_2077)

set(FILES
island.cpp
map.cpp
player.cpp
ship.cpp
coordinates.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})
target_compile_options(${PROJECT_NAME} PRIVATE ${FLAGS})
27 changes: 27 additions & 0 deletions shm/alcohol.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "alcohol.hpp"
#include <iostream>

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));
}

Cargo& Alcohol::operator+=(size_t amount) {
amount_ += amount;
return *this;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happend when you add to much cargo (more then capacity?) Do you handle this somewhere? If yes please move also below logic to this function (with substract) because now you have logic for substract in Cargo and for add in other class this is not god :)


Cargo& Alcohol::operator-=(size_t amount) {
if (amount <= amount_) {
amount_ -= amount;
} else if(amount_ < 0){

}
return *this;
}

bool Alcohol::operator==(const Cargo& cargo) const {
return cargo.getName() == getName();
}
28 changes: 28 additions & 0 deletions shm/alcohol.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#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() {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= default

Alcohol(const std::string& name, size_t amount) : Cargo(name, amount) {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to cpp

~Alcohol() override{};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= default


Cargo& operator+=(size_t amount) override;
Cargo& operator-=(size_t amount) override;
bool operator==(const Cargo&) const override;

size_t getPercentage() const { return percentage_; };
void setPercentage(size_t percentage) { percentage_ = percentage; };

//Methods override from Cargo class.
size_t getPrice() const override;
std::string getName() const override { return name_; };
size_t getAmount() const override { return amount_; };
size_t getBasePrice() const override { return basePrice_; };
void setAmount(const size_t& amount) override { amount_ = amount;};
void nextDay() override {};
private:
size_t percentage_;
};
33 changes: 33 additions & 0 deletions shm/cargo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "cargo.hpp"
#include <iostream>


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);
Copy link
Collaborator

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

}
}

Cargo& Cargo::operator+=(size_t amount) {
amount_ += amount;
return *this;
}

Cargo& Cargo::operator-=(size_t amount) {
if (amount <= amount_) {
amount_ -= amount;
} else {

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant else

return *this;
}

bool Cargo::operator==(const Cargo& cargo) const {
return cargo.getName() == getName();
}

32 changes: 32 additions & 0 deletions shm/cargo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

#pragma once
#include <string>
#include "time.hpp"
#include "iObserver.hpp"

class Cargo : public IObserver {
public:
Cargo() {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
: name_(name), amount_(amount), basePrice_(basePrice) {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to cpp

virtual ~Cargo() = default;

virtual Cargo& operator+=(size_t amount);
virtual Cargo& operator-=(size_t amount);
virtual bool operator==(const Cargo&) const;

virtual size_t getPrice() const = 0;
virtual std::string getName() const = 0;
virtual size_t getAmount() const = 0;
virtual size_t getBasePrice() const = 0;

virtual void setAmount(const size_t& amount) = 0;

protected:
std::string name_;
size_t amount_;
size_t basePrice_;
std::shared_ptr<Time> time_ {nullptr};
};
23 changes: 23 additions & 0 deletions shm/coordinates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "coordinates.hpp"

void Coordinates::setPositionX(size_t positionX) {
positionX_ = positionX;
}
size_t Coordinates::getPositionX() const {
return positionX_;
}

void Coordinates::setPositionY(size_t positionY) {
positionY_ = positionY;
}
size_t Coordinates::getPositionY() const {
return positionY_;
}

bool Coordinates::operator== (const Coordinates& n_pos) const {
return positionX_ == n_pos.getPositionX() && positionY_ == n_pos.getPositionY();
}

size_t Coordinates::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)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split it to 2 lines

}
29 changes: 29 additions & 0 deletions shm/coordinates.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include <cmath>

class Coordinates {
public:
Coordinates()
: positionX_(0)
, positionY_(0)
{}

Coordinates(size_t positionX, size_t positionY)
: positionX_(positionX)
, positionY_(positionY)
{}

void setPositionX(size_t );
size_t getPositionX() const;

void setPositionY(size_t );
size_t getPositionY() const;

bool operator== (const Coordinates& ) const;

size_t distance(const Coordinates&);

private:
size_t positionX_;
size_t positionY_;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ideall candidate to constexpr class

61 changes: 61 additions & 0 deletions shm/fruit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "fruit.hpp"
#include <iostream>

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){
};

size_t Fruit::getPrice() const
{
return static_cast<size_t>(basePrice_ * static_cast<float>(purchaseDate_) / expirationDate_);
}

Cargo &Fruit::operator+=(size_t amount)
{
amount_ += amount;
return *this;
}

Cargo &Fruit::operator-=(size_t amount)
{
if (amount <= amount_)
{
amount_ -= amount;
}
else
{
}
return *this;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Please have logic with add/ substract in one place.


bool Fruit::operator==(const Cargo &cargo) const
{
return cargo.getName() == getName();
}

Fruit &Fruit::operator--()
{
if (purchaseDate_ <= 0)
{
purchaseDate_ = 0;
}
purchaseDate_--;
return *this;
}

Fruit &Fruit::operator--(int)
{
if (purchaseDate_ <= 0)
{
purchaseDate_ = 0;
}
purchaseDate_--;
return *this;
}

void Fruit::nextDay()
{
if (purchaseDate_)
{
operator--();
}
}
32 changes: 32 additions & 0 deletions shm/fruit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#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 {};

Cargo& operator+=(size_t amount) override;
Cargo& operator-=(size_t amount) override;
bool operator==(const Cargo&) const override;
Fruit& operator--();
Fruit& operator--(int);

//Methods override from Cargo class.
virtual size_t getPrice() const override;
virtual std::string getName() const override { return name_; };
size_t getAmount() const override { return amount_; };
size_t getBasePrice() const override { return basePrice_; };

size_t getExpirationDate() const { return expirationDate_; };
size_t getPurchaseData() const { return purchaseDate_; };
void setAmount(const size_t& amount) override { amount_ = amount;};

void nextDay() override;

protected:
size_t expirationDate_;
size_t purchaseDate_ = expirationDate_;
};
Loading