-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
183 lines (163 loc) · 9.89 KB
/
main.cpp
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
#include <GraphicsCore.h>
#include <ctime>
#include <stdio.h>
/// User-defined functions to display his pieces.
/// Ïîëüçîâàòåëüñêèå ôóíêöèè äëÿ îòîáðàæåíèå ñâîèõ ôèãóð.
void drawPlayer(GraphicsCore core, int x, int y){
core.drawOneSymb(point{x,y}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x-2,y}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x+2,y}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x,y+1}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x,y+2}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y+2}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y+3}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y+4}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y+2}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y+3}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y+4}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x,y-1}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x,y-2}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y-2}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y-2}, '*', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y-3}, '$', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y-3}, '$', Color_Red, Color_Black);
core.drawOneSymb(point{x,y-3}, '*', Color_Red, Color_Black);
}
void hidePlayer(GraphicsCore core, int x, int y){
core.drawOneSymb(point{x,y}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x-2,y}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x+2,y}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x,y+1}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x,y+2}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y+2}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y+3}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y+4}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y+2}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y+3}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y+4}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x,y-1}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x,y-2}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y-2}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y-2}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x-1,y-3}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x+1,y-3}, ' ', Color_Red, Color_Black);
core.drawOneSymb(point{x,y-3}, ' ', Color_Red, Color_Black);
}
int main()
{
GraphicsCore GCore;
/// Initialization of the console window. The method is overloaded,
/// if no arguments are passed, then the window size is taken from the system.
/// Èíèöèàëèçàöèÿ îêíà êîíñîëè. Ìåòîä ïåðåãðóæåí, åñëè íå ïåðåäàíû àðãóìåíòû
/// òî ðàçìåð îêíà óñòàíàâëèâàåòñÿ ïî óìîë÷àíèþ ñâîéñòâ êîíñîëè.
GCore.init_graphics(80, 40);
/// An example of building a set of multi-colored lines through a cycle.
/// Entry GraphicsCore_Color (i) allows you to set the color from a number from 0 to 15.
/// Ïðèìåð ïîñòðîåíèÿ ìíîæåñòâà ðàçíîöâåòíûõ ëèíèé ÷åðåç öèêë. Çàïèñü GraphicsCore_Color(i)
/// ïîçâîëÿåò óñòàíàâëèâàòü öâåò èç ÷èñëà îò 0 äî 15.
for (int i=0;i<16;i++){
GCore.drawOrthogonalLine(point{0,i}, point{7,i}, true, GraphicsCore_Color(i), Color_Black);
}
/// Building a vertical line. Only vertical or horizontal lines are available in the class.
/// Ïîñòðîåíèå âåðòèêàëüíîé ëèíèè. Â êëàññå äîñòóïíû òîëüêî âåðòèêàëüíûå èëè ãîðèçîíòàëüíûå ëèíèè.
GCore.drawOrthogonalLine(point{8,0}, point{8,16}, true, Color_Blue, Color_Black);
/// When constructing a rectangle, it is important to specify the upper left corner and
/// lower right corner for correct display.
/// Ïðè ïîñòðîåíèè ïðÿìîóãîëüíèêà âàæíî óêàçûâàòü âåðõíèé ëåâûé óãîë è
/// íèæíèé ïðàâûé óãîë äëÿ êîððåêòíîãî îòîáðàæåíèÿ.
GCore.drawOrthogonalRectangle(point{30,12}, point{45,25}, Color_Green, Color_GreenDark);
GCore.drawOrthogonalRectangle(point{35,5}, point{55,15}, Color_Blue, Color_Black);
/// Simple output of the symbol table at the bottom of the screen.
/// Ïðîñòîé âûâîä ÷àñòè òàáëèöû ñèìâîëîâ â íèæíåé ÷àñòè ýêðàíà.
for (int i=170;i<170+80;i++){
GCore.drawOneSymb(point{i-170,39}, (char)i,Color_Green, Color_Black);
}
/// Demonstration of symbols to simulate the filling of 25%, 50%, 75% and 100%.
/// Äåìîíñòðàöèÿ ñèìâîëîâ äëÿ èìèòàöèè çàïîëíåíèÿ íà 25%, 50%, 75% è 100%.
GCore.drawOneSymb(point{20,2}, (char)176,Color_Green, Color_Black);
GCore.drawOneSymb(point{21,2}, (char)177,Color_Green, Color_Black);
GCore.drawOneSymb(point{22,2}, (char)178,Color_Green, Color_Black);
GCore.drawOneSymb(point{23,2}, (char)219,Color_Green, Color_Black);
/// Examples with text output. Available output from the center of the specified point
/// or aligned to the left of the specified point. Frame and fill are displayed separately.
/// Ïðèìåðû ñ âûâîäîì òåêñòà. Äîñòóïåí âûâîä èç öåíòðà óêàçàííîé òî÷êè
/// èëè ñ âûðàâíèâàíèåì ïî ëåâîìó êðàþ îò óêàçàííîé òî÷êè.
/// Ðàìêà è çàïîëíåíèå îòîáðàæàþòñÿ îòäåëüíî.
GCore.drawOrthogonalRectangle(point{5,29}, point{35,31}, Color_Red, Color_Black);
GCore.drawCentreText("test text", point{20,30}, Color_Red, Color_Black);
GCore.drawOrthogonalRectangle(point{5,33}, point{35,35}, Color_BlueDark, Color_Black);
GCore.drawLeftText("test text2", point{6,34}, Color_BlueDark, Color_Black);
GCore.drawFill(point{40,33}, point{55,35}, Color_GreenDark);
GCore.drawOrthogonalRectangle(point{40,33}, point{55,35}, Color_Green, Color_GreenDark);
GCore.drawCentreText("TEST", point{48,34}, Color_Green, Color_GreenDark);
/// When calling drawing methods write to the buffer. To display the buffer on the screen,
/// you need to call the ShowBuffer () method, when you call it, the buffer is not cleared,
/// to clear it, use the clearBuffer () method.
/// Ïðè âûçîâå ìåòîäîâ ðèñîâàíèÿ ïðîèçâîäèòñÿ çàïèñü â áóôåð. Äëÿ îòîáðàæåíèÿ áóôåðà íà ýêðàí
/// íóæíî âûçâàòü ìåòîä ShowBuffer(), ïðè åãî âûçîâå áóôåð íå î÷èùàåòñÿ, äëÿ î÷èñòêè
/// íóæíî âîñïîëüçîâàòüñÿ ìåòîäîì clearBuffer().
GCore.ShowBuffer();
/// Initialization of the current time (in milliseconds) and timer (current time + time to trigger).
/// Èíèöèàëèçàöèÿ òåêóùåãî âðåìåíè (â ìèëëèñåêóíäàõ) è òàéìåðà (òåêóùåå âðåìÿ + âðåìÿ äî ñðàáàòûâàíèÿ).
int realTimer=clock() / (CLOCKS_PER_SEC/1000);
int timer = realTimer + 3000;
/// Delay for the user to see the initial demo screen.
/// Çàäåðæêà ÷òîáû ïîëüçîâàòåëü óñïåë óâèäåòü íà÷àëüíûé äåìî-ýêðàí.
while (realTimer<timer){
realTimer=clock() / (CLOCKS_PER_SEC/1000);
}
/// Clearing the buffer, while the screen is not cleared.
/// Î÷èñòêà áóôåðà, ïðè ýòîì ýêðàí íå î÷èùàåòñÿ.
GCore.clearBuffer();
GCore.drawOrthogonalRectangle(point{5,29}, point{35,31}, Color_Red, Color_Black);
GCore.drawCentreText("Press arrows for moving", point{20,30}, Color_Red, Color_Black);
char buff[20];
int x=10;
int y=10;
GraphicsCore_Color NowColorRect = Color_Red;
/// In this example of dynamic display, the all buffer is not overwritten.
/// Only certain places are overwritten with hidePlayer () and drawFill ().
///  ýòîì ïðèìåðå äèíàìè÷åñêîãî îòîáðàæåíèÿ âåñü áóôôåð íå çàòèðàåòñÿ.
/// Çàòèðàåòñÿ òîëüêî îòäåëüíûå ìåñòà ñ ïîìîùüþ hidePlayer() è drawFill().
while (1){
/// Actions are triggered in an infinite loop. When you press the keys, the coordinates change.
/// Äåéñòâèÿ îòñëåæèâàþòñÿ â áåñêîíå÷íîì öèêëå. Ïðè íàæàòèè êëàâèø ïðîèñõîäèò èçìåíåíèå êîîðäèíàò.
if (GetAsyncKeyState(VK_ESCAPE)&0x8000!=0) return 0;
hidePlayer(GCore, x, y);
if (GetAsyncKeyState(VK_UP)&0x8000!=0) y--;
if (GetAsyncKeyState(VK_DOWN)&0x8000!=0) y++;
if (GetAsyncKeyState(VK_LEFT)&0x8000!=0) x--;
if (GetAsyncKeyState(VK_RIGHT)&0x8000!=0) x++;
drawPlayer(GCore, x, y);
/// Displays the current time in the right corner of the screen.
/// And the time to trigger the timer. To do this, the field for its output
/// is pre-cleared to wipe the old numbers.
/// Îòîáðàæåíèå òåêóùåãî âðåìåíè â ïðàâîì óãëó ýêðàíà.
/// È âðåìåíè äî ñðàáàòûâàíèÿ òàéìåðà. Äëÿ ýòîãî ïîëå äëÿ åãî âûâîäà
/// ïðåäâàðèòåëüíî î÷èùàåòñÿ, ÷òîáû çàòåðåòü ñòàðûå öèôðû.
realTimer=clock() / (CLOCKS_PER_SEC/1000);
sprintf(buff, "%d ms", realTimer);
GCore.drawOrthogonalRectangle(point{60,0}, point{79,2}, Color_Green, Color_Black);
GCore.drawCentreText(buff, point{70,1}, Color_Green, Color_Black);
sprintf(buff, "%d ms", timer-realTimer);
GCore.drawFill(point{60,3}, point{79,5}, Color_Black);
GCore.drawOrthogonalRectangle(point{60,3}, point{79,5}, Color_Green, Color_Black);
GCore.drawCentreText(buff, point{70,4}, Color_Green, Color_Black);
/// The rectangle draws a frame with no internal space,
/// for cleaning or setting it you need to use drawFill.
/// Ïðÿìîóãîëüíèê ðèñóåò ðàìêó áåç âíóòðåííåãî ïðîñòðàíñòâà,
/// äëÿ î÷èñòêè èëè çàäàíèÿ åãî íóæíî èñïîëüçîâàòü drawFill.
if (realTimer>=timer){
timer = realTimer + 1000;
GCore.drawFill(point{5,5}, point{10,10}, NowColorRect);
GCore.drawOrthogonalRectangle(point{5,5}, point{10,10}, NowColorRect, NowColorRect);
NowColorRect = GraphicsCore_Color(rand()%16);
}
GCore.ShowBuffer();
}
return 0;
}