diff --git a/shm/CMakeLists.txt b/shm/CMakeLists.txt new file mode 100644 index 000000000..7e8017dee --- /dev/null +++ b/shm/CMakeLists.txt @@ -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}) \ No newline at end of file diff --git a/shm/alcohol.cpp b/shm/alcohol.cpp new file mode 100644 index 000000000..b3133884c --- /dev/null +++ b/shm/alcohol.cpp @@ -0,0 +1,17 @@ +#include "alcohol.hpp" +#include +#include + +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(basePrice_ * static_cast(percentage_) / static_cast(MaxPercentage)); +} + +std::shared_ptr Alcohol::clone(const size_t &amount) const { + return std::make_shared(this->getName(), + amount, + this->getBasePrice(), + this->getPercentage()); +} diff --git a/shm/alcohol.hpp b/shm/alcohol.hpp new file mode 100644 index 000000000..869fd1f24 --- /dev/null +++ b/shm/alcohol.hpp @@ -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 clone(const size_t &) const; + + void setTime(const std::shared_ptr