-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoComposition.h
196 lines (169 loc) · 3.1 KB
/
DemoComposition.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#pragma once
#include <iostream>
#include <string>
using namespace std;
class CompositionDemo
{
class PegLeg // äåðåâÿííàÿ íîãà
{
public:
string color; // brown will be OK
bool dirty; // yes / no
double length; // inches
int usability; // 0 - 100%
PegLeg()
{
cout << "Peg Leg C-TOR!\n";
}
~PegLeg()
{
cout << "Peg Leg DESTRUCTOR!\n";
}
};
class HandHook // ðóêà-êðþ÷îê
{
public:
string material;
int usability;
bool dirty;
bool canMakeSelfy;
HandHook()
{
cout << "Hand Hook C-TOR!\n";
}
~HandHook()
{
cout << "Hand Hook DESTRUCTOR!\n";
}
};
class EyePatch // íàãëàçíèê
{
public:
string color; // black is timeless classic
double size; // XXL
bool elastic; // yes / no
bool leather; // yes / no
EyePatch()
{
cout << "Eye Patch C-TOR!\n";
}
~EyePatch()
{
cout << "Eye Patch DESTRUCTOR!\n";
}
};
class Pirate
{
public:
string nickname;
PegLeg leg;
HandHook hand;
EyePatch patch;
Pirate(string nickname)
{
this->nickname = nickname;
cout << "Pirate C-TOR!\n";
}
~Pirate()
{
cout << "Pirate DESTRUCTOR!\n";
}
void CaptureShip()
{
cout << nickname << " says: " << "Prepare a boarding party!!!\n";
}
void SingSong()
{
cout << nickname << " singing: " << "\"...Yo-ho-ho, and a bottle of rum!!!\"\n";
}
};
public:
static void Test()
{
Pirate p("Captain Jack Sparrow");
p.CaptureShip();
p.SingSong();
}
/////////////////////////////////////////////////////////
private:
class Point
{
public:
int X;
int Y;
Point()
{
X = Y = 0;
}
void SetPoint(int iX, int iY)
{
X = iX;
Y = iY;
}
};
class Figure
{
Point* obj;
int count;
int rc, gc, bc;
public:
Figure()
{
count = 0;
obj = nullptr;
}
void CreateFigura(int p_count, int R, int G, int B)
{
if (p_count < 3) p_count = 3;
count = p_count;
rc = R;
gc = G;
bc = B;
// âûäåëåíèå ïàìÿòè ïîä ìàññèâ òî÷åê
obj = new Point[count];
if (!obj) exit(0);
for (int i = 0; i < count; i++) {
obj[i].SetPoint(rand() % 600, rand() % 400);
}
}
// ïîêàç ôèãóðû
void ShowFigure()
{
ReleaseDC(Application::hwnd, Application::hdc);
Application::hdc = GetDC(Application::hwnd);
HPEN pen = CreatePen(rand() % 5, 1, RGB(rc, gc, bc));
HBRUSH brush = CreateSolidBrush(RGB(0, 0, 0));
SelectObject(Application::hdc, brush);
Rectangle(Application::hdc, 0, 0, 610, 410);
SelectObject(Application::hdc, pen);
POINT p;
MoveToEx(Application::hdc, obj[0].X, obj[0].Y, &p);
for (int i = 1; i < count; i++) {
LineTo(Application::hdc, obj[i].X, obj[i].Y);
Sleep(1500 / count);
}
LineTo(Application::hdc, obj[0].X, obj[0].Y);
}
~Figure()
{
if (obj) delete[] obj;
}
};
public:
static void Test2()
{
while (true)
{
system("cls");
COORD c = { 0, 0 };
SetConsoleCursorPosition(Application::h, c);
Figure f;
int points;
cout << "How many points do you want? ";
cin >> points;
f.CreateFigura(points, rand() % 255, rand() % 255, rand() % 255);
f.ShowFigure();
}
}
};
// CompositionDemo::Test2();