-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.h
656 lines (539 loc) · 6.23 KB
/
game.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
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
/*
This scope give out some usual fuctions about tiny games.
You can free use:
Locate(x,y);
Setcolor(COLOR);
SetConsoleTitle("title");
system("mode con cols=50 lines=50");
if(KEY_DOWN(MOUSE_MOVED))printf("是");
printf("鼠标右键是否按下:");
if(KEY_DOWN(MOUSE_EVENT))printf("是");
printf("鼠标滚轮键是否按下:");
if(KEY_DOWN(MOUSE_WHEELED))printf("是");
*/
#pragma once
//#include "afxribbonstatusbar.h"
//
//class MyCMFCRibbonStatusBar :public CMFCRibbonStatusBar
//{
//public:
//MyCMFCRibbonStatusBar(void);
//~MyCMFCRibbonStatusBar(void);
//void OnPaneContextMenu(CWnd* pParentFrame, CPoint point);
//};
#include<windows.h>
#include<conio.h>
#include<string>
#include<iostream>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
#define IsKeyPressed(nVirtKey) ((GetKeyState(nVirtKey) & (1<<(sizeof(SHORT)*8-1))) != 0)
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
HANDLE hCon;
enum Color {
DARKBLUE = 1,
DARKGREEN,
DARKTEAL,
DARKRED,
DARKPINK,
DARKYELLOW,
GRAY,
DARKGRAY,
BLUE,
GREEN,
TEAL,
RED,
PINK,
YELLOW,
WHITE
};
void Setcolor(Color c) {
if(hCon == NULL)
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon, c);
}
void Locate(int x,int y) {
y = y * 2 - 1;
coord.X=y - 1;
coord.Y=x - 1;
SetConsoleCursorPosition(hout,coord);
}
void W(int x,int y,std::string s) {
Locate(x,y);
std::cout<<s;
}
int winx,winy;
void Winset(int x,int y) {
winx = y;
winy = x;
RECT rect;
HWND hwnd=GetForegroundWindow();
GetWindowRect(hwnd,&rect);
int title_high = GetSystemMetrics(SM_CYCAPTION); //窗口标题栏高度
int line_wight = GetSystemMetrics(SM_CYSIZEFRAME)
+ GetSystemMetrics(SM_CYBORDER); //窗口边框宽度
MoveWindow(hwnd,y-line_wight,x-title_high-line_wight,rect.right-rect.left,rect.bottom-rect.top,TRUE);
}
struct Mos {
int xx,yy;
};
Mos Getmouse() {
POINT pt;
GetCursorPos(&pt);
HWND hwnd=GetForegroundWindow();
ScreenToClient(hwnd,&pt);
Mos res;
// 定义 CONSOLE_FONT_INFOEX 结构体,用于保存控制台字体信息
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
// 获取控制台当前字体信息
GetCurrentConsoleFontEx(hCon, false, &cfi);
res.yy = pt.x/(cfi.dwFontSize.X*2)+1;
res.xx = pt.y/(cfi.dwFontSize.Y)+1;
return res;
}
/*
POINT pt;
GetCursorPos(&pt);
cout << "当前的鼠标坐标为:" << pt.x << "," << pt.y << endl;
system("cls");
= 4
SM_CXBORDER = 5
SM_CYBORDER = 6
GetSystemMetrics(6) //窗口边框宽度
*/
/*
// 获取活动窗口
HWND h=GetForegroundWindow();
printf("0x%X\n",h);
// 获取窗口标题
char text[200];
GetWindowText(h,text,200);
printf("%s\n",text);
// 获取屏幕鼠标坐标
POINT pt;
GetCursorPos(&pt);
printf("%d %d\n",pt.x,pt.y);
// 获取窗口鼠标坐标
ScreenToClient(h,&pt);
printf("%d %d\n",pt.x,pt.y);
*/
/*
虚拟键码对应表
VK_LBUTTON
1
鼠标左键
VK_RBUTTON
2
鼠标右键
VK_CANCEL
3
Cancel
VK_MBUTTON
4
鼠标中键
VK_XBUTTON1
5
VK_XBUTTON2
6
VK_BACK
8
Backspace
VK_TAB
9
Tab
VK_CLEAR
12
Clear
VK_RETURN
13
Enter
VK_SHIFT
16
Shift
VK_CONTROL
17
Ctrl
VK_MENU
18
Alt
VK_PAUSE
19
Pause
VK_CAPITAL
20
Caps Lock
VK_KANA
21
VK_HANGUL
21
VK_JUNJA
23
VK_FINAL
24
VK_HANJA
25
VK_KANJI
25*
VK_ESCAPE
27
Esc
VK_CONVERT
28
VK_NONCONVERT
29
VK_ACCEPT
30
VK_MODECHANGE
31
VK_SPACE
32
Space
VK_PRIOR
33
Page Up
VK_NEXT
34
Page Down
VK_END
35
End
VK_HOME
36
Home
VK_LEFT
37
Left Arrow
VK_UP
38
Up Arrow
VK_RIGHT
39
Right Arrow
VK_DOWN
40
Down Arrow
VK_SELECT
41
Select
VK_PRINT
42
Print
VK_EXECUTE
43
Execute
VK_SNAPSHOT
44
Snapshot
VK_INSERT
45
Insert
VK_DELETE
46
Delete
VK_HELP
47
Help
48
0
49
1
50
2
51
3
52
4
53
5
54
6
55
7
56
8
57
9
65
A
66
B
67
C
68
D
69
E
70
F
71
G
72
H
73
I
74
J
75
K
76
L
77
M
78
N
79
O
80
P
81
Q
82
R
83
S
84
T
85
U
86
V
87
W
88
X
89
Y
90
Z
VK_LWIN
91
VK_RWIN
92
VK_APPS
93
VK_SLEEP
95
VK_NUMPAD0
96
小键盘 0
VK_NUMPAD1
97
小键盘 1
VK_NUMPAD2
98
小键盘 2
VK_NUMPAD3
99
小键盘 3
VK_NUMPAD4
100
小键盘 4
VK_NUMPAD5
101
小键盘 5
VK_NUMPAD6
102
小键盘 6
VK_NUMPAD7
103
小键盘 7
VK_NUMPAD8
104
小键盘 8
VK_NUMPAD9
105
小键盘 9
VK_MULTIPLY
106
小键盘 *
VK_ADD
107
小键盘 +
VK_SEPARATOR
108
小键盘 Enter
VK_SUBTRACT
109
小键盘 -
VK_DECIMAL
110
小键盘 .
VK_DIVIDE
111
小键盘 /
VK_F1
112
F1
VK_F2
113
F2
VK_F3
114
F3
VK_F4
115
F4
VK_F5
116
F5
VK_F6
117
F6
VK_F7
118
F7
VK_F8
119
F8
VK_F9
120
F9
VK_F10
121
F10
VK_F11
122
F11
VK_F12
123
F12
VK_F13
124
VK_F14
125
VK_F15
126
VK_F16
127
VK_F17
128
VK_F18
129
VK_F19
130
VK_F20
131
VK_F21
132
VK_F22
133
VK_F23
134
VK_F24
135
VK_NUMLOCK
144
Num Lock
VK_SCROLL
145
Scroll
VK_LSHIFT
160
VK_RSHIFT
161
VK_LCONTROL
162
VK_RCONTROL
163
VK_LMENU
164
VK_RMENU
165
VK_BROWSER_BACK
166
VK_BROWSER_FORWARD
167
VK_BROWSER_REFRESH
168
VK_BROWSER_STOP
169
VK_BROWSER_SEARCH
170
VK_BROWSER_FAVORITES
171
VK_BROWSER_HOME
172
VK_VOLUME_MUTE
173
VolumeMute
VK_VOLUME_DOWN
174
VolumeDown
VK_VOLUME_UP
175
VolumeUp
VK_MEDIA_NEXT_TRACK
176
VK_MEDIA_PREV_TRACK
177
VK_MEDIA_STOP
178
VK_MEDIA_PLAY_PAUSE
179
VK_LAUNCH_MAIL
180
VK_LAUNCH_MEDIA_SELECT
181
VK_LAUNCH_APP1
182
VK_LAUNCH_APP2
183
VK_OEM_1
186
; :
VK_OEM_PLUS
187
= +
VK_OEM_COMMA
188
VK_OEM_MINUS
189
- _
VK_OEM_PERIOD
190
VK_OEM_2
191
/ ?
VK_OEM_3
192
` ~
VK_OEM_4
219
[ {
VK_OEM_5
220
\ |
VK_OEM_6
221
] }
VK_OEM_7
222
' "
VK_OEM_8
223
VK_OEM_102
226
VK_PACKET
231
VK_PROCESSKEY
229
VK_ATTN
246
VK_CRSEL
247
VK_EXSEL
248
VK_EREOF
249
VK_PLAY
250
VK_ZOOM
251
VK_NONAME
252
VK_PA1
253
VK_OEM_CLEAR
254
*/