Code
#include <windows.h>
#include <iostream>
class Shape
{
public:
Shape(int _x, int _y, char _letter, int _length):
x(_x), y(_y), letter(_letter), length(_length){}
void verLine();
void horLine();
void diagLine(int,int);
void setLetter(char value){ letter = value; }
void setLength(int value) { length = value; }
void gotoxy(int, int);
protected:
char letter;
int x,y, length;
};
void Shape::gotoxy(int x, int y)
{ //To move cursor to certain location
HANDLE hConsole;
COORD cursorLoc;
std::cout.flush();
cursorLoc.X = x;
cursorLoc.Y = y;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsole, cursorLoc);
}
void Shape::horLine()
{
gotoxy(x,y);
for (int i=0; i<length; i++)
std::cout << letter;
}
void Shape::verLine()
{
for (int i=0; i<length; i++)
{
gotoxy(x,y+i);
std::cout << letter;
}
}
void Shape::diagLine(int toX, int toY)
{
int dx = toX - x < 0 ? -1 : 1;
int dy = toY - y < 0 ? -1 : 1;
for(int _x=x,_y=y; _x != toX && _y != toY;_x+=dx,_y+=dy)
{
gotoxy(_x,_y);
std::cout << letter;
}
}
class REctangle : public Shape
{
public:
REctangle(int x, int y, char letter, int _width, int _height):
Shape(x,y,letter,0),
width(_width),height(_height){}
void virtual draw();
protected:
int width, height;
};
void REctangle::draw()
{
setLength(height);
verLine();
setLength(width);
horLine();
x += width-1;
setLength(height);
verLine();
x-=width-1;
y+= height-1;
setLength(width);
horLine();
y-=height-1;
}
class Box : public REctangle
{
public:
Box(int x, int y, char letter, int width, int length, int _depth):
REctangle(x,y,letter,width,length), depth(_depth){}
void draw();
protected:
int depth;
};
void Box::draw()
{
REctangle::draw();
x+=depth;
y+=depth;
REctangle::draw();
x-=depth;
y-=depth;
diagLine(x+depth,y+depth);
x+=width;
diagLine(x+depth,y+depth);
x-=width;
y+=height;
diagLine(x+depth,y+depth);
x+=width;
diagLine(x+depth,y+depth);
x-=width;
y-=height;
}
class Triangle : public Shape
{
public:
Triangle(int x, int y, char letter, int _base, int _height):
Shape(x,y,letter,0), base(_base),height(_height){}
void draw();
protected:
int base, height;
};
void Triangle::draw()
{
diagLine(x-height/2,y+height);
diagLine(x+height/2,y+height);
int _x = x;
int _y = y;
x = x-height/2+1;
y = y+height/2-1;
setLength((base)-1);
horLine();
x = _x;
y = _y;
}
int main()
{
Shape s = Shape(10,50,'|',10);
REctangle r = REctangle(10,50,'*',10,5);
Box b = Box(10,10,'#',50,30,10);
Triangle t = Triangle(40,30,'#',10,10);
Triangle t2 = Triangle(50,30,'#',10,10);
Triangle t3 = Triangle(40,25,'#',10,10);
s.verLine();
r.draw();
b.draw();
t.draw();
t2.draw();
t3.draw();
char c;
std::cin >> c;
}
its a Box with a triforce in it. With like a flag lookin thing outside.