Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <cmath>
- using namespace System::Drawing;
- class Rectangl
- {
- protected:
- int x, y, a, b;
- public:
- Rectangl() {
- }
- Rectangl(int _x, int _y, int size_x, int size_y) {
- x = _x;
- y = _y;
- a = size_x;
- b = size_y;
- }
- ~Rectangl() {}
- void move(int delta_x)
- {
- x += delta_x;
- }
- void draw(Graphics^ j)
- {
- Color^ col = gcnew Color();
- SolidBrush^ pen = gcnew SolidBrush(col->Blue);
- j->FillRectangle(pen, x, y, a, b);
- };
- };
- class window: public Rectangl {
- public:
- window(int _x, int _y, int h){
- x = _x;
- y = _y;
- a = 4 * h;
- b = 4 * h;
- }
- void draw(Graphics^ j)
- {
- Color^ col = gcnew Color();
- SolidBrush^ pen = gcnew SolidBrush(col->Blue);
- j->FillRectangle(pen, x, y, a, b);
- }
- ~window() {}
- };
- class krug: public Rectangl
- {
- public:
- krug(int _x, int _y, int h)
- {
- x = _x;
- y = _y;
- a = 4 * h;
- b = 4 * h;
- }
- void draw(Graphics^ j)
- {
- Color^ col = gcnew Color();
- SolidBrush^ pen = gcnew SolidBrush(col->Red);
- j->FillEllipse(pen, x, y, a, b);
- }
- };
- class corpus: public Rectangl
- {
- public:
- corpus(int _x, int _y, int h)
- {
- x = _x;
- y = _y;
- a = 21 * h;
- b = 11 * h;
- }
- void draw(Graphics^ j)
- {
- Color^ col = gcnew Color();
- SolidBrush^ pen = gcnew SolidBrush(col->LightGray);
- j->FillRectangle(pen, x, y, a, b);
- }
- };
- class doors: public Rectangl {
- public:
- doors(int _x, int _y, int h)
- {
- x = _x;
- y = _y;
- a = 4 * h;
- b = 7 * h;
- }
- void draw(Graphics^ j)
- {
- Color^ col = gcnew Color();
- SolidBrush^ pen = gcnew SolidBrush(col->Green);
- j->FillRectangle(pen, x, y, a, b);
- }
- };
- class truba: public Rectangl
- {
- public:
- truba() {}
- truba(int _x, int _y, int h)
- {
- x = _x;
- y = _y;
- a = 2 * h;
- b = 3 * h;
- }
- void draw(Graphics^ j)
- {
- Color^ col = gcnew Color();
- SolidBrush^ pen = gcnew SolidBrush(col->Black);
- j->FillRectangle(pen, x, y, a, b);
- }
- };
- class vagon
- {
- private:
- corpus* vag;
- krug* left;
- krug* right;
- window* w_l;
- window* w_r;
- doors* durka;
- public:
- vagon() {}
- vagon(int _x, int _y, int h)
- {
- vag = new corpus(_x, _y, h);
- left = new krug(_x + 1*h, _y + 11*h, h);
- right = new krug(_x + 16*h, _y + 11*h, h);
- w_l = new window(_x + 2*h, _y + 3*h, h);
- w_r = new window(_x + 8*h, _y + 3*h, h);
- durka = new doors(_x + 16*h, _y + 4*h, h);
- }
- void draw(Graphics^ g)
- {
- vag->draw(g);
- left->draw(g);
- right->draw(g);
- w_l->draw(g);
- w_r->draw(g);
- durka->draw(g);
- }
- void move(int dx)
- {
- vag->move(dx);
- left->move(dx);
- right->move(dx);
- w_l->move(dx);
- w_r->move(dx);
- durka->move(dx);
- }
- ~vagon() {}
- };
- class line
- {
- private:
- int x_first; int y_first;
- int x_last; int y_last;
- public:
- line(int xfirst = 0, int yfirst = 0, int xlast = 0, int ylast = 0)
- {
- x_first = xfirst; y_first = yfirst;
- x_last = xlast; y_last = ylast;
- }
- void move(int dx_first, int dy_first = 0, int dx_last = 0, int dy_last = 0)
- {
- x_first += dx_first; y_first += dy_first; x_last += dx_last; y_last += dy_last;
- }
- void draw(Graphics^ g)
- {
- Color^ col = gcnew Color();
- Pen^ pen = gcnew Pen(col->Black, 4);
- g->DrawLine(pen, x_first, y_first, x_last, y_last);
- }
- int lenghts()
- {
- int t = sqrt((x_first - x_last) * (x_first - x_last) + (y_first - y_last) * (y_first - y_last));
- return t;
- }
- int Getxleft()
- {
- return x_first;
- }
- int Getyleft()
- {
- return y_first;
- }
- int Getxright()
- {
- return x_last;
- }
- int Getyright()
- {
- return y_last;
- }
- };
- class engine
- {
- private:
- line left; line right; line middle;
- public:
- engine() {}
- engine(int x, int y, int h)
- {
- left = line(x, y, x, y - h);
- right = line((x + 15 * h), y, (x + 15 * h), y - h);
- middle = line(x, y - h, (x + 15 * h), y - h);
- }
- void move(int dx)
- {
- int lenght = left.lenghts();
- float dx_c = lenght - left.lenghts() * cos(dx / (2 * left.lenghts()));
- float dy_c = left.lenghts() * sin(dx / (2 * left.lenghts()));
- left.move(dx, 0, dx + dx_c, dy_c);
- right.move(dx, 0, dx + dx_c, dy_c);
- middle.move(dx + dx_c, dy_c, dx + dx_c, dy_c);
- }
- void draw(Graphics^ g)
- {
- left.draw(g);
- right.draw(g);
- middle.draw(g);
- }
- };
- class parovoz
- {
- private:
- vagon vg; truba tr; engine eg;
- public:
- parovoz(int x = 0, int y = 0, int h = 0)
- {
- vg = vagon(x, y, h);
- tr = truba(x + h, y - 3 * h, h);
- eg = engine(x + 3 * h, y + 13 * h, h);
- }
- void move(int dx)
- {
- vg.move(dx);
- tr.move(dx);
- eg.move(dx);
- }
- void draw(Graphics^ g)
- {
- vg.draw(g);
- tr.draw(g);
- eg.draw(g);
- }
- };
- //con = cp
- class con
- {
- private:
- line ln;
- public:
- con(int x = 0, int y = 0, int h = 0)
- {
- ln = line(x, y, x + 4 * h, y);
- }
- void draw(Graphics^ g)
- {
- Color^ col = gcnew Color();
- Pen^ pen = gcnew Pen(col->Black);
- g->DrawLine(pen, ln.Getxleft(), ln.Getyleft(), ln.Getxright(), ln.Getyright());
- }
- void move(int dx)
- {
- ln.move(dx, 0, dx, 0);
- }
- };
- // vag = vg
- class train
- {
- private:
- parovoz pr;
- vagon* vag;
- con* c;
- int size;
- public:
- train(int x, int y, int h, int n)
- {
- pr = parovoz(x - 21 * h, y - 11 * h, h);
- vag = new vagon[n];
- c = new con[n];
- for (int i = 0; i < n; i++)
- {
- vag[i] = vagon(x - (i + 2) * 21 * h - (i + 1) * h, y - 11 * h, h);
- c[i] = con(x - (i + 1) * 24 * h, y, h);
- }
- size = n;
- }
- train(const train &tmp)
- {
- size = tmp.size;
- pr = tmp.pr;
- vag = new vagon[tmp.size];
- c = new con[tmp.size];
- for (int i = 0; i < tmp.size; i++)
- {
- vag[i] = tmp.vag[i];
- c[i] = tmp.c[i];
- }
- }
- train& operator=(train tmp)
- {
- if (size != tmp.size)
- {
- if (size != 0)
- {
- delete[] vag;
- delete[] c;
- }
- size = tmp.size;
- vag = new vagon[size];
- c = new con[size];
- }
- for (int i = 0; i < size; i++)
- {
- vag[i] = tmp.vag[i];
- c[i] = tmp.c[i];
- }
- return *this;
- }
- void draw(Graphics^ g)
- {
- pr.draw(g);
- for (int i = 0; i < size; i++)
- {
- vag[i].draw(g);
- c[i].draw(g);
- }
- }
- void move(int dx)
- {
- pr.move(dx);
- for (int i = 0; i < size; i++)
- {
- vag[i].move(dx);
- c[i].move(dx);
- }
- }
- ~train()
- {
- delete[] vag;
- delete[] c;
- }
- };
Add Comment
Please, Sign In to add comment