From 49f30b85befc31ea4d8b5cbac688d05a4012bb0b Mon Sep 17 00:00:00 2001 From: Akhtyamov Pavel Date: Sun, 16 Feb 2020 21:26:30 +0300 Subject: [PATCH] Examples commited from previous year --- Memento/cpp-source/main.cpp | 3 +++ State/cpp-source/TrafficLight.h | 3 ++- State/cpp-source/main.cpp | 4 +++- Visitor/cpp-source/CMakeLists.txt | 2 +- Visitor/cpp-source/main.cpp | 8 ++++++++ Visitor/cpp-source/rooms/Kitchen.cpp | 1 + Visitor/cpp-source/workers/SanTech.cpp | 21 +++++++++++++++++++++ Visitor/cpp-source/workers/SanTech.h | 18 ++++++++++++++++++ Visitor/cpp-source/workers/Windower.cpp | 22 ++++++++++++++++++++++ Visitor/cpp-source/workers/Windower.h | 17 +++++++++++++++++ 10 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 Visitor/cpp-source/workers/SanTech.cpp create mode 100644 Visitor/cpp-source/workers/SanTech.h create mode 100644 Visitor/cpp-source/workers/Windower.cpp create mode 100644 Visitor/cpp-source/workers/Windower.h diff --git a/Memento/cpp-source/main.cpp b/Memento/cpp-source/main.cpp index 86df4c8..98cf022 100644 --- a/Memento/cpp-source/main.cpp +++ b/Memento/cpp-source/main.cpp @@ -14,10 +14,13 @@ int main() { game.StartNewGame(); game.IncreaseLevel(); + std::cout << "Before first save" << std::endl; game.ShowCurrentProgress(); caretaker.Save("first_save"); + game.IncreaseLevel(); game.ShowCurrentProgress(); + caretaker.Save("second_save"); diff --git a/State/cpp-source/TrafficLight.h b/State/cpp-source/TrafficLight.h index 7bbca7b..2b8bad6 100644 --- a/State/cpp-source/TrafficLight.h +++ b/State/cpp-source/TrafficLight.h @@ -7,6 +7,7 @@ #include "states/State.h" #include + using StatePointer = std::unique_ptr; @@ -25,7 +26,7 @@ class TrafficLight { // TODO(akhtyamovpavel) Refactor this state void PrintState(); private: - std::unique_ptr state_; + StatePointer state_; Direction direction_; }; diff --git a/State/cpp-source/main.cpp b/State/cpp-source/main.cpp index 1bbbdb3..9bce38d 100644 --- a/State/cpp-source/main.cpp +++ b/State/cpp-source/main.cpp @@ -6,7 +6,9 @@ #include "TrafficLight.h" int main() { TrafficLight light; - for (size_t state_switch = 0; state_switch < 10; ++state_switch) { + for (size_t state_switch = 0; + state_switch < 10; + ++state_switch) { light.PrintState(); light.ChangeColor(); } diff --git a/Visitor/cpp-source/CMakeLists.txt b/Visitor/cpp-source/CMakeLists.txt index 6787266..6e05fb4 100644 --- a/Visitor/cpp-source/CMakeLists.txt +++ b/Visitor/cpp-source/CMakeLists.txt @@ -1,4 +1,4 @@ project(Visitor) -set(SOURCES main.cpp rooms/ElementRoom.cpp rooms/ElementRoom.h workers/Visitor.h workers/Visitor.cpp rooms/Kitchen.cpp rooms/Kitchen.h rooms/LivingRoom.cpp rooms/LivingRoom.h rooms/BathRoom.cpp rooms/BathRoom.h workers/Tiler.cpp workers/Tiler.h workers/Painter.cpp workers/Painter.h) +set(SOURCES main.cpp rooms/ElementRoom.cpp rooms/ElementRoom.h workers/Visitor.h workers/Visitor.cpp rooms/Kitchen.cpp rooms/Kitchen.h rooms/LivingRoom.cpp rooms/LivingRoom.h rooms/BathRoom.cpp rooms/BathRoom.h workers/Tiler.cpp workers/Tiler.h workers/Painter.cpp workers/Painter.h workers/Windower.cpp workers/Windower.h workers/SanTech.cpp workers/SanTech.h) add_executable(${PROJECT_NAME} ${SOURCES} main.cpp) \ No newline at end of file diff --git a/Visitor/cpp-source/main.cpp b/Visitor/cpp-source/main.cpp index 576e87e..601d0ce 100644 --- a/Visitor/cpp-source/main.cpp +++ b/Visitor/cpp-source/main.cpp @@ -7,12 +7,17 @@ #include "rooms/LivingRoom.h" #include "workers/Tiler.h" #include "workers/Painter.h" +#include "workers/Windower.h" +#include "workers/SanTech.h" int main() { BathRoom bath_room; Kitchen kitchen; LivingRoom living_room; + SanTech sanTech; + kitchen.Accept(&sanTech); + kitchen.ShowDecorations(); Tiler tiler; kitchen.Accept(&tiler); @@ -28,4 +33,7 @@ int main() { kitchen.ShowDecorations(); living_room.ShowDecorations(); + Windower windower; + kitchen.Accept(&windower); + kitchen.ShowDecorations(); } \ No newline at end of file diff --git a/Visitor/cpp-source/rooms/Kitchen.cpp b/Visitor/cpp-source/rooms/Kitchen.cpp index d6a7d3c..0923479 100644 --- a/Visitor/cpp-source/rooms/Kitchen.cpp +++ b/Visitor/cpp-source/rooms/Kitchen.cpp @@ -7,6 +7,7 @@ void Kitchen::Accept(Visitor *visitor) { visitor->visit(this); } + std::string Kitchen::GetName() { return "Kitchen"; } diff --git a/Visitor/cpp-source/workers/SanTech.cpp b/Visitor/cpp-source/workers/SanTech.cpp new file mode 100644 index 0000000..772c3c3 --- /dev/null +++ b/Visitor/cpp-source/workers/SanTech.cpp @@ -0,0 +1,21 @@ +// +// Created by Pavel Akhtyamov on 2019-04-24. +// + +#include "SanTech.h" +#include "../rooms/Kitchen.h" +#include "../rooms/LivingRoom.h" +#include "../rooms/BathRoom.h" + + +void SanTech::visit(Kitchen *kitchen) { + kitchen->wall.material = "sink"; +} + +void SanTech::visit(LivingRoom *living_room) { + +} + +void SanTech::visit(BathRoom *bath_room) { + bath_room->wall.material = "bath"; +} diff --git a/Visitor/cpp-source/workers/SanTech.h b/Visitor/cpp-source/workers/SanTech.h new file mode 100644 index 0000000..cec748a --- /dev/null +++ b/Visitor/cpp-source/workers/SanTech.h @@ -0,0 +1,18 @@ +// +// Created by Pavel Akhtyamov on 2019-04-24. +// + +#pragma once + +#include "Visitor.h" + +class SanTech : public Visitor { + public: + void visit(Kitchen *kitchen) override; + void visit(LivingRoom *living_room) override; + void visit(BathRoom *bath_room) override; + +}; + + + diff --git a/Visitor/cpp-source/workers/Windower.cpp b/Visitor/cpp-source/workers/Windower.cpp new file mode 100644 index 0000000..27c117c --- /dev/null +++ b/Visitor/cpp-source/workers/Windower.cpp @@ -0,0 +1,22 @@ +// +// Created by Pavel Akhtyamov on 2019-04-23. +// + +#include "Windower.h" +#include "../rooms/Kitchen.h" +#include "../rooms/BathRoom.h" +#include "../rooms/LivingRoom.h" + + +void Windower::visit(Kitchen *kitchen) { + kitchen->wall.material = "window"; +} + +void Windower::visit(LivingRoom *living_room) { + living_room->wall.material = "window"; + living_room->wall.color = "black"; +} + +void Windower::visit(BathRoom *bath_room) { + +} diff --git a/Visitor/cpp-source/workers/Windower.h b/Visitor/cpp-source/workers/Windower.h new file mode 100644 index 0000000..58d2a35 --- /dev/null +++ b/Visitor/cpp-source/workers/Windower.h @@ -0,0 +1,17 @@ +// +// Created by Pavel Akhtyamov on 2019-04-23. +// + +#pragma once + +#include "Visitor.h" +class Windower : public Visitor { + public: + void visit(Kitchen *kitchen) override; + void visit(LivingRoom *living_room) override; + void visit(BathRoom *bath_room) override; + +}; + + +