Skip to content
Snippets Groups Projects
Commit 3659d430 authored by tobiglaser's avatar tobiglaser
Browse files

change Command, add Gear, Direction & Pause

parent b3340bf8
No related branches found
No related tags found
No related merge requests found
#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
#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
#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
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment