-
Notifications
You must be signed in to change notification settings - Fork 88
SHM part 2 #105
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 part 2 #105
Conversation
shm task 2 adding getters for cargo
ziobron
left a comment
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.
Just checking automation
|
Thanks @ziobron for Code Review. |
ziobron
left a comment
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.
Quick additional check
ziobron
left a comment
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.
And the last check
Game loop and vaid data
| std::cin.clear(); | ||
| std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); |
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.
This is repeated few times, maybe create function clearInputStream()?
DRY rule -> don't repeat yourself :)
| Cargo* Alcohol::clone() | ||
| { | ||
| return new Alcohol(*this); |
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.
Avoid raw ptr! and new operator
return std::unique_ptr and use std::make_unique.
shm/fruit.cpp
Outdated
| size_t Fruit::getPrice() const | ||
| { | ||
| return static_cast<size_t>(basePrice_ * ((size_t)(expiry_date_ - time_elapsed_)) / expiry_date_); | ||
| //return static_cast<size_t>(basePrice_ * ((size_t)(expiry_date_ - time_elapsed_)) / expiry_date_); |
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.
remove commented code.
This commented code looks good, why do you return basePrice_ instead?
| Cargo *Fruit::clone() | ||
| { | ||
| return new Fruit(*this); |
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.
unique_ptr
shm/item.cpp
Outdated
| Cargo* Item::clone() | ||
| { | ||
| return new Item(*this); |
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.
unique_ptr
shm/ship.cpp
Outdated
| auto cargoPtr = findMatchCargo(item); | ||
| if(findMatchCargo(item)) | ||
| if(cargoPtr) |
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.
Better
if (cargoPtr = findMatchCargo(item)) {
}
If automatically check if this is not nullptr
shm/ship.cpp
Outdated
| //Cargo * toAdd; | ||
| loadCargo->reduceAmount(amount); | ||
| Cargo* toAdd; | ||
| if(Fruit* f = dynamic_cast<Fruit*>(loadCargo)){ | ||
| toAdd = new Fruit(*f); | ||
|
|
||
| } | ||
| if(Item* i = dynamic_cast<Item*>(loadCargo)){ | ||
| toAdd = new Item(*i); | ||
| } | ||
| if(Alcohol* a = dynamic_cast<Alcohol*>(loadCargo)){ | ||
| toAdd = new Alcohol(*a); | ||
| } | ||
|
|
||
| // if(Fruit* f = dynamic_cast<Fruit*>(loadCargo)){ | ||
| // toAdd = new Fruit(*f); | ||
| // } | ||
| // if(Item* i = dynamic_cast<Item*>(loadCargo)){ | ||
| // toAdd = new Item(*i); | ||
| // } | ||
| // if(Alcohol* a = dynamic_cast<Alcohol*>(loadCargo)){ | ||
| // toAdd = new Alcohol(*a); | ||
| // } |
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.
Remove commented code
We do not use gtest
Tests in catch2
| int x = (int)distrib(gen); | ||
| int y = (int)distrib(gen); |
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.
we should avoid old (C) style casting. Because it unsafe
| { | ||
| Coordinates c (static_cast<float>(distrib(gen)), static_cast<float>(distrib(gen))); | ||
|
|
||
| for (int i = 0; i < (int)constVariables::ISLANDS_COUNT; i++) |
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.
better size_t i = 0 and don't cast to int
| x = (int)distrib(gen); | ||
| y = (int)distrib(gen); |
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.
avoid old (C) style casting
@Kasia9311 @kondorski @Crazyayane07 @pwiatr3 @NikczemnyOkularnik