Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Rectangle { protected: Position _position; int _width; int _height; Colors _color; public: Rectangle(int x=0, int y=0, int width=0, int height=0, Colors color = Colors::MAGENTA); void draw();
- };
- Rectangle::Rectangle(int x, int y, int width, int height, Colors color) { _position = Position(x,y); _width = width; _height = height; _color = color; }
- void Rectangle::draw(){ int x_start = _position.x; int x_stop = _position.x + _width;
- for(int i=x_start; i<x_stop; i++) { //Obere Reihe ansiConsole.printText(i, _position.y, "#", _color); }
- //Position y +1 da die erste Reihe mitgezählt wird _position.y+=1;
- //height>2 abfangen, da es sonst zwei reihen ergibt if (_height>2) { for (int l=1; l<_height; l++) { for(int k=0; k<2; k++){ //Mitte if (k==1){ //Linke Seite zeichnen ansiConsole.printText(_position.x+(_width-1), _position.y-l, "#", _color); } else { //Rechte Seite zeichnen ansiConsole.printText(_position.x, _position.y-l, "#", _color); } } } }
- for(int j=x_start; j<x_stop; j++){ //Untere Reihe ansiConsole.printText(j, _position.y-(_height), "#", _color); } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement