Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. 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();
  2.  };
  3.  Rectangle::Rectangle(int x, int y, int width, int height, Colors color) {    _position = Position(x,y);    _width = width;    _height = height;    _color = color; }
  4.  void Rectangle::draw(){    int x_start = _position.x;    int x_stop = _position.x + _width;
  5.  
  6.  
  7.     for(int i=x_start; i<x_stop; i++) { //Obere Reihe        ansiConsole.printText(i, _position.y, "#", _color);    }
  8.      //Position y +1 da die erste Reihe mitgezählt wird    _position.y+=1;
  9.      //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);                }            }        }    }
  10.      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