-
Notifications
You must be signed in to change notification settings - Fork 10
/
canvas.pas
340 lines (286 loc) · 7.55 KB
/
canvas.pas
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
unit Canvas;
interface
uses
{$IFDEF WINDOWS}
windows,
{$ELSE}
setlocale,
ncrt,
{$ENDIF}
outputcolor;
const
ConsoleWidth = 79;
ConsoleHeight = 24;
StatsHeight = 10;
CommandsHeight = 7;
PosTransitionBeginY = 12;
PosStatsX = 51;
PosStatX = 72;
PosStatBeginY = 1;
PosEventTextBeginY = 2;
PosCommandsBeginY = 18;
procedure GotoXY(x, y: Integer);
procedure GetXY(var x: Integer; var y: Integer);
procedure LineChar(x, y: Integer; Length: Integer; ch: Char);
procedure CanvasClear();
procedure CanvasResetPos();
procedure CanvasSetReadPos();
procedure CanvasAddLayout();
procedure CanvasAddStats();
procedure CanvasAddEvent();
procedure CanvasAddChooseCommand();
procedure CanvasAddCommands();
procedure CanvasAddLocation();
procedure TestStats();
procedure TestLocation();
procedure TestTransLocation();
procedure TestEvent();
procedure TestCommand();
procedure CanvasFlush();
procedure CanvasForseFlush();
implementation
procedure GotoXY(x, y: Integer);
{$IFDEF WINDOWS}
var
pos: TCoord;
{$ENDIF}
begin
{$IFDEF WINDOWS}
pos.x := x;
pos.y := y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
{$ELSE}
ncrt.GotoXY(x+1,y+1);
{$ENDIF}
end;
procedure GetXY(var x: Integer; var y: Integer);
{$IFDEF WINDOWS}
var
csbi: CONSOLE_SCREEN_BUFFER_INFO;
{$ENDIF}
begin
{$IFDEF WINDOWS}
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), csbi);
x := csbi.dwCursorPosition.x;
y := csbi.dwCursorPosition.y;
{$ELSE}
x := WhereX()-1;
y := WhereY()-1;
{$ENDIF}
end;
procedure LineChar(x, y: Integer; length: Integer; ch: Char);
var
{$IFDEF WINDOWS}
pos: TCoord;
lUnused: LongWord;
{$ELSE}
origX: Integer;
origY: Integer;
I : Integer;
{$ENDIF}
begin
{$IFDEF WINDOWS}
pos.x := x;
pos.y := y;
FillConsoleOutputAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0, length, pos, lUnused);
FillConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE), ch, length, pos, lUnused);
{$ELSE}
GetXY(origX, origY);
GotoXY(x, y);
for I := 1 to length do
begin
Write(ch);
end;
GotoXY(origX, origY);
{$ENDIF}
end;
procedure CanvasClear();
begin
{$IFDEF WINDOWS}
LineChar(0, 0, 2000, ' ');
{$ELSE}
ClrScr();
{$ENDIF}
GotoXY(0, 0);
end;
procedure CanvasResetPos();
begin
GotoXY(0, 0);
end;
procedure CanvasSetReadPos();
begin
GotoXY(17, ConsoleHeight);
end;
procedure CanvasAddLayout();
var
I: Integer;
begin
GotoXY(PosStatsX, 0);
ColorWrite('==ХАРАКТЕРИСТИКИ ПЕРСОНАЖА==', ColorDefault, 1);
for I := 0 to StatsHeight do
begin
GotoXY(PosStatsX - 1, I);
ColorWrite('|',ColorDefault);
end;
for I := 0 to ConsoleWidth do
begin
GotoXY(I, 11);
ColorWrite('=',ColorDefault);
GotoXY(I, 17);
ColorWrite('=',ColorDefault);
end;
for I := PosCommandsBeginY to ConsoleHeight do
begin
GotoXY(PosStatsX - 1, I);
ColorWrite('|',ColorDefault);
end;
end;
procedure CanvasAddStats();
begin
GotoXY(51, 1);
ColorWrite('Здоровье................', ColorAttribute);
GotoXY(51, 2);
ColorWrite('Бодрость................', ColorAttribute);
GotoXY(51, 3);
ColorWrite('Содержание алкоголя.....', ColorAttribute);
GotoXY(51, 4);
ColorWrite('Накуренность............', ColorAttribute);
GotoXY(51, 5);
ColorWrite('Сила....................',ColorAttribute);
GotoXY(51, 6);
ColorWrite('Интеллект...............',ColorAttribute);
GotoXY(51, 7);
ColorWrite('Удача...................',ColorAttribute);
GotoXY(51, 8);
ColorWrite('Счастье.................',ColorAttribute);
GotoXY(51, 9);
ColorWrite('Репутация в группе......',ColorAttribute);
GotoXY(51, 10);
ColorWrite('Репутация в универе.....',ColorAttribute);
end;
procedure CanvasAddEvent();
begin
end;
procedure CanvasAddChooseCommand();
begin
GotoXY(0, ConsoleHeight);
ColorWrite('Введите команду: ', ColorDefault);
end;
procedure CanvasAddCommands();
begin
end;
procedure CanvasAddLocation();
begin
GotoXY(62, 19);
ColorWrite('Локация', ColorTransLocation);
end;
procedure TestStats();
var
I: Integer;
const
a: array [1..10] of Integer = (7, 3, 0, 0, 6, 5, 0, 5, 5, 6);
begin
for I := 1 to StatsHeight do
begin
GotoXY(PosStatX - 2, I);
ColorWrite(a[I], ColorNumber);
ColorWrite('0%', ColorNumber);
end;
GotoXY(PosStatX + 1, 2);
ColorWrite('-10%', 'LightRed');
GotoXY(PosStatX + 1, 6);
ColorWrite('-20%', 'LightRed');
GotoXY(PosStatX + 1, 8);
ColorWrite('+10%', 'LightGreen');
end;
procedure TestLocation();
begin
GotoXY(62, 21);
ColorWrite('Улица', ColorLocation);
end;
procedure TestTransLocation();
begin
GotoXY(1, PosTransitionBeginY);
ColorWrite('--> ', ColorCommandText);
ColorWrite('Переход на локацию "', ColorTransLocation);
ColorWrite('Улица', ColorLocation);
ColorWrite('" ', ColorTransLocation);
ColorWrite('к событию "', ColorTransLocation);
ColorWrite('Встреча с гопниками', ColorEventName);
ColorWrite('" ', ColorTransLocation, 1);
end;
procedure TestEvent();
begin
GotoXY(0, 0);
ColorWrite('Слышишь в свой адрес:', ColorEventText, 1);
ColorWrite('Слышь пацанчик, а есть чёнить? А? А если найду?', ColorEventText, 1);
ColorWrite('Опа-на! Чики-брики и в дамки!', ColorEventText, 1);
ColorWrite('Чем меньше у человека зубов, тем лучше он', ColorEventText, 1);
ColorWrite('фильтрует базар!', ColorEventText);
end;
procedure TestCommand();
begin
GotoXY(0, PosCommandsBeginY);
ColorWrite('1', ColorNumber);
ColorWrite(': ', ColorDefault);
ColorWrite('Притвориться местным авторитетом', ColorCommandName, 1);
ColorWrite('2', ColorNumber);
ColorWrite(': ', ColorDefault);
ColorWrite('Притвориться гопником', ColorCommandName, 1);
ColorWrite('3', ColorNumber);
ColorWrite(': ', ColorDefault);
ColorWrite('Дать отпор гопникам', ColorCommandName, 1);
end;
procedure CanvasFlush();
var
I: Integer;
begin
for I := 0 to StatsHeight do
LineChar(0, I, 50, ' ');
for I := PosCommandsBeginY to ConsoleHeight - 1 do
LineChar(0, I, 50, ' ');
for I := PosStatBeginY to StatsHeight do
LineChar(PosStatX + 3, I, 5, ' ');
LineChar(17, ConsoleHeight, 4, ' ');
for I := 0 to 3 do
LineChar(0, PosTransitionBeginY + I, ConsoleWidth, ' ');
end;
procedure CanvasForseFlush(); // Erase full screen except event's text
var
I: Integer;
x: Integer;
y: Integer;
begin
GetXY(x, y);
LineChar(0, ConsoleHeight, 50, ' ');
for I := PosStatBeginY to StatsHeight do
LineChar(PosStatX + 3, I, 5, ' ');
LineChar(17, ConsoleHeight, 4, ' ');
for I := 0 to 3 do
LineChar(0, PosTransitionBeginY + I, ConsoleWidth, ' ');
GotoXY(PosStatsX, 0);
LineChar(PosStatsX, 0, 29, ' ');
for I := 0 to StatsHeight do
begin
GotoXY(PosStatsX - 1, I);
ColorWrite(' ',ColorDefault);
end;
for I := 0 to ConsoleWidth do
begin
GotoXY(I, 11);
ColorWrite(' ',ColorDefault);
GotoXY(I, 17);
ColorWrite(' ',ColorDefault);
end;
for I := PosCommandsBeginY to ConsoleHeight do
begin
GotoXY(PosStatsX - 1, I);
ColorWrite(' ',ColorDefault);
end;
LineChar(52, 19, 20, ' ');
LineChar(52, 21, 20, ' ');
for I := 1 to 10 do
LineChar(51, I, 28, ' ');
GotoXY(x, y);
end;
end.