05_OOa: Testat bestanden

This commit is contained in:
Johannes Theiner 2018-11-06 11:26:26 +01:00
parent 86f07e7b23
commit 72b7ae9a7d
4 changed files with 31 additions and 1 deletions

View File

@ -27,5 +27,7 @@ add_executable(05_OOa_Testat
Testat/Rectangle.h
Testat/Scene.cpp
Testat/Scene.h
Testat/Sign.cpp
Testat/Sign.h
../../helpers/AnsiConsole.cpp
)

View File

@ -0,0 +1,11 @@
#include "Sign.h"
Sign::Sign(int x, int y, int width, int height, Colors color, std::string _text) :
Rectangle::Rectangle(x, y, width, height, color), text(_text) {
}
void Sign::draw() {
Rectangle::draw();
int x = Rectangle::position.x - (text.length()/2);
ansiConsole.printText(x, Rectangle::position.y, text, Rectangle::color);
}

15
src/05_OO/a/Testat/Sign.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef C_C_SIGN_H
#define C_C_SIGN_H
#include "Rectangle.h"
class Sign : public Rectangle {
protected:
std::string text;
public:
Sign(int x = 0, int y = 0, int width = 0, int height = 0, Colors color = Colors::WHITE, std::string text = "Hier Text einfügen");
void draw() override;
};
#endif

View File

@ -4,6 +4,7 @@
#include "Circle.h"
#include "Rectangle.h"
#include "Scene.h"
#include "Sign.h"
int main(int argc, char **argv) {
std::vector<Shape*> shapes;
@ -17,7 +18,8 @@ int main(int argc, char **argv) {
shapes.push_back(new Circle(30, 20, 15, Colors::GREEN));
shapes.push_back(new Rectangle(5, 21, 10, 10, Colors::MAGENTA));
shapes.push_back(new Rectangle(5, 25, 10, 10, Colors::MAGENTA));
shapes.push_back(new Sign(60, 10, 20, 5, Colors::CYAN, "Hallo Welt"));
shapes.push_back(new Point(5, 10, Colors::WHITE));
shapes.push_back(new Point(15, 7, Colors::WHITE));