From 3659d430de9c8adba2fbe963356bf24f3869b9a2 Mon Sep 17 00:00:00 2001 From: tobiglaser <76131623+tobiglaser@users.noreply.github.com> Date: Fri, 22 Apr 2022 20:33:26 +0200 Subject: [PATCH] change Command, add Gear, Direction & Pause --- src/Command.h | 5 ++++- src/Direction.h | 40 +++++++++++++++++++++++++++++++++++ src/Gear.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ src/Pause.h | 37 +++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/Direction.h create mode 100644 src/Gear.h create mode 100644 src/Pause.h diff --git a/src/Command.h b/src/Command.h index cb9837e..2cd4a39 100644 --- a/src/Command.h +++ b/src/Command.h @@ -1,11 +1,14 @@ #pragma once #include <string> -class Command +#include "commandlib.h" + +class Command : ICommand { private: std::string name; public: Command(std::string _name) { name = _name; } std::string getName() { return name; } + virtual std::string getConfig() = 0; }; \ No newline at end of file diff --git a/src/Direction.h b/src/Direction.h new file mode 100644 index 0000000..a7b45df --- /dev/null +++ b/src/Direction.h @@ -0,0 +1,40 @@ +#pragma once +#include "commandlib.h" +#include "Command.h" +#include <string> + +class Direction : public Command, public IDirection +{ +private: + int degree; +public: + Direction(); + Direction(int newDegree); + void setDegree(int newDegree); + int getDegree() { return degree; } + std::string getConfig(); +}; + +Direction::Direction(int newDegree) : Command(IDirection::direction) +{ + setDegree(newDegree); +} + +void Direction::setDegree(int newDegree) +{ + if (newDegree <= -90) + degree = -90; + else if (newDegree >= 90) + degree = 90; + else + degree = newDegree; +} + +std::string Direction::getConfig() +{ + std::string str = IDirection::direction + + " - Degree: " + + std::to_string(degree) + + '.'; + return str; +}; \ No newline at end of file diff --git a/src/Gear.h b/src/Gear.h new file mode 100644 index 0000000..648cadd --- /dev/null +++ b/src/Gear.h @@ -0,0 +1,55 @@ +#pragma once +#include "commandlib.h" +#include "Command.h" +#include <string> + +class Gear : public Command, public IGear +{ +private: + int speed; + double duration; + +public: + Gear(); + Gear(int newSpeed, double newDuration); + void setSpeed(int newSpeed); + int getSpeed() { return speed; } + void setDuration(double newDuration); + double getDuration() { return duration; } + std::string getConfig(); +}; + +Gear::Gear(int newSpeed, double newDuration) : Command(IGear::gear) +{ + setSpeed(newSpeed); + setDuration(newDuration); +} + +void Gear::setSpeed(int newSpeed) +{ + if (newSpeed <= -100) + speed = -100; + else if (newSpeed >= 100) + speed = 100; + else + speed = newSpeed; +} + +void Gear::setDuration(double newDuration) +{ + if (newDuration < 0) + duration = 0; + else + duration = newDuration; +} + +std::string Gear::getConfig() +{ + std::string str = IGear::gear + + " - Speed: " + + std::to_string(speed) + + " for: " + + std::to_string(duration) + + 's'; + return str; +} \ No newline at end of file diff --git a/src/Pause.h b/src/Pause.h new file mode 100644 index 0000000..1dbf5ba --- /dev/null +++ b/src/Pause.h @@ -0,0 +1,37 @@ +#pragma once +#include "commandlib.h" +#include "Command.h" +#include <string> + +class Pause : public Command, public IPause +{ +private: + double duration; +public: + Pause(); + Pause(double newDuration); + void setDuration(double newDuration); + double getDuration() { return duration; } + std::string getConfig(); +}; + +Pause::Pause(double newDuration) : Command(IPause::pause) +{ + setDuration(newDuration); +} + +void Pause::setDuration(double newDuration) +{ + if (newDuration < 0) + duration = 0; + else + duration = newDuration; +} + +std::string Pause::getConfig() +{ + std::string str = IPause::pause + + " - Duration: " + + std::to_string(duration); + return str; +}; \ No newline at end of file -- GitLab