迷宫寻路可视化


学了数据结构,一直想做个东西出来玩。八皇后?五子棋?贪吃蛇?推箱子?二叉树?来个我最熟悉的迷宫求解吧。

函数说明:
设置背景颜色:setbkcolor(RED);
画线算法:line(x1,y1,x2,y2);
画矩阵算法:rectangle(left,top,right,bottom);
字体颜色:settextcolor(YELLOW);
输出字符串:RECT r = { left,top,right,bottom};
drawtext(_T(“退出”), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
编译环境:Visual Studio 2017
菜单
队列寻路

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
#include <iostream>
#include <graphics.h>
#include<malloc.h>
#include <time.h>
#include <conio.h>//在控制台输入输出文件
using namespace std;
#define MAXSIZE 1000+10
void MEUN2(struct Stack *&stack, struct Queue *&queue);
void MEUN1(struct Stack *&stack, struct Queue *&queue);
void init();
void PrintLine();
void FillColor();
void QueueRoad(struct Queue *&queue);
void StackRoad(struct Stack *&stack);
//栈寻找迷宫路径
struct Box
{
int x;
int y;
int di;//方位值
};
struct Stack
{
struct Box data[MAXSIZE];
int top;
};

//队列寻找迷宫路径
struct Box1
{
int x;
int y;
int pre;
};
struct Queue
{
struct Box1 data[MAXSIZE];
int rear;
int front;
};


int px1 = 0, px2 = 0, py1 = 0, py2 = 0;

int flag1 = 0;
//迷宫数组
int mg[14][22] = { 0 };

//设置迷宫的边界
void init() {
for (int i = 0; i < 14; i++)
for (int j = 0; j < 22; j++)
mg[i][j] = 0;
for (int i = 0; i < 14; i++) mg[i][21] = 1;
for (int i = 0; i < 14; i++) mg[i][0] = 1;
for (int i = 0; i < 22; i++) mg[13][i] = 1;
for (int i = 0; i < 22; i++) mg[0][i] = 1;
}

//栈寻找路径
bool StackFind(struct Stack *&stack, int x1, int y1, int x2, int y2)
{
int i = 0;
int j = 0;
struct Box box;
//di的用来记录方位值,如果要退回的话,就不用再一次的重新来找一遍了
box.x = x1; box.y = y1; box.di = -1;
stack->top++;
stack->data[stack->top] = box;
mg[x1][y1] = -1;
//solidrectangle((box.y-1) * 50, (box.x-1) * 50, (box.y-1) * 50 + 50, (box.x-1) * 50 + 50);

while (stack->top != -1) {

box = stack->data[stack->top];
int x = box.x; int y = box.y; int di = box.di;


if (x == x2 && y == y2)
return true;
else {
while (di < 4) {
di++;
switch (di) {

case 0: i = x - 1; j = y; break;
case 1: i = x; j = y + 1; break;
case 2: i = x + 1; j = y; break;
case 3: i = x; j = y - 1; break;

}
if (mg[i][j] == 0) break;
}
if (di < 4) {
stack->data[stack->top].di = di;
box.x = i; box.y = j; box.di = -1;
stack->top++;
stack->data[stack->top] = box;
mg[i][j] = -1;
}
else {
stack->top--;
mg[x][y] = 0;
}
}
}
return false;
}

//队列寻找路径
bool QueueFind(struct Queue *&queue, int x1, int y1, int x2, int y2)
{
int i = 0;
int j = 0;

//pre的用来记录上一个可走方块在
struct Box1 box1;
box1.x = x1; box1.y = y1; box1.pre = -1;

queue->rear++;
queue->data[queue->rear] = box1;
mg[x1][y1] = -1;


while (queue->rear != queue->front) {

queue->front++;
box1 = queue->data[queue->front];
int x = box1.x; int y = box1.y;

if (x == x2 && y == y2) {
return true;
}
else {
int di = -1;
while (di < 4) {
di++;
switch (di) {


case 0: i = x - 1; j = y; break;
case 1: i = x; j = y + 1; break;
case 2: i = x + 1; j = y; break;
case 3: i = x; j = y - 1; break;


}
if (mg[i][j] == 0) {
box1.x = i; box1.y = j; box1.pre = queue->front;
queue->rear++;
queue->data[queue->rear] = box1;
mg[i][j] = -1;

}
}
}
}
}

//画迷宫图形
void PrintLine()
{
setbkcolor(WHITE);
cleardevice();
//画迷宫图形
setlinecolor(BLACK);
for (int i = 0; i <= 1000; i += 50) line(i, 0, i, 1000);
for (int i = 0; i <= 600; i += 50) line(0, i, 1000, i);
}
//填充颜色
void FillColor()
{
setfillcolor(RED);
//填充颜色,以分别可走路径和不可走路径
int flag = 1;
for (int i = 0; i < 1000; i += 50) {

for (int j = 0; j < 600; j += 50) {

//随机设置位置为不可走状态
flag = rand();

if (flag % 2 != 0 && flag % 3 != 0) {

solidrectangle(i, j, i + 50, j + 50);
mg[(j + 50) / 50][(i + 50) / 50] = 1;

Sleep(10);

}
}
}
}
void QueueRoad(struct Queue *&queue)
{
if (QueueFind(queue, px1, py1, px2, py2) == true) {

int root = queue->front;
while (root != 0) {
int pre = queue->data[root].pre;
queue->data[root].pre = -1;
root = pre;
}
struct Box1 box1;
for (int i = 1; i < queue->front; i++){
if (queue->data[i].pre == -1) {
setfillcolor(GREEN);
box1 = queue->data[i];
solidrectangle((box1.y - 1) * 50, (box1.x - 1) * 50, (box1.y - 1) * 50 + 50, (box1.x - 1) * 50 + 50);
Sleep(1000);
}
}
}
}
void StackRoad(struct Stack *&stack)
{
struct Box box;
if (StackFind(stack, px1, py1, px2, py2) == true) {

for (int i = 1; i < stack->top; i++)
{
setfillcolor(GREEN);

box = stack->data[i];
solidrectangle((box.y - 1) * 50, (box.x - 1) * 50, (box.y - 1) * 50 + 50, (box.x - 1) * 50 + 50);


//暂停0.1s钟以便于观察路径过程
Sleep(1000);
}
}
}
void MEUN1(struct Stack *&stack,struct Queue *&queue)
{
initgraph(1300, 600);
setbkmode(TRANSPARENT);//透明字体
HWND hwnd = GetHWnd();//获取当前窗口句柄
setbkcolor(RED);
cleardevice();
setlinecolor(GREEN);
settextcolor(GREEN);//字体颜色
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度为 48
_tcscpy_s(f.lfFaceName, _T("微软雅黑")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
//f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
rectangle(550, 300, 750, 400);
rectangle(550, 400, 750, 500);
rectangle(550, 500, 750, 600);
RECT r1 = { 550, 300, 750, 400 };
drawtext(_T("栈寻路"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r2 = { 550, 400, 750, 500 };
drawtext(_T("队列寻路"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 550,500,750,600 };
drawtext(_T("退出"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
MOUSEMSG Mou;
BeginBatchDraw();
bool flag = true;
while (flag) {
Mou = GetMouseMsg();
switch (Mou.uMsg) {
case WM_MOUSEMOVE:
EndBatchDraw();
if ((Mou.y >= 300 && Mou.y <= 400) && (Mou.x <= 750 && Mou.x >= 550)) {
settextcolor(YELLOW);
rectangle(550, 300, 750, 400);
RECT r1 = { 550, 300, 750, 400 };
drawtext(_T("栈寻路"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
settextcolor(GREEN);
rectangle(550, 400, 750, 500);
RECT r2 = { 550,400,750,500 };
drawtext(_T("队列寻路"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 550, 750, 500, 600 };
drawtext(_T("退出"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else if (Mou.y >= 400 && Mou.y <= 500 && Mou.x <= 750 && Mou.x >= 550) {
settextcolor(YELLOW);
RECT r2 = { 550,400,750,500 };
drawtext(_T("队列寻路"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
settextcolor(GREEN);
rectangle(550, 300, 750, 400);
RECT r1 = { 550, 300, 750, 400 };
drawtext(_T("栈寻路"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 550, 750, 500, 600 };
drawtext(_T("退出"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else if (Mou.x >= 550 && Mou.x <= 750 && Mou.y >= 500 && Mou.y <= 600) {
settextcolor(YELLOW);
RECT r3 = { 550, 500, 750, 600 };
drawtext(_T("退出"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
settextcolor(GREEN);
rectangle(550, 300, 750, 400);
rectangle(550, 400, 750, 500);
RECT r1 = { 550, 300, 750, 400 };
drawtext(_T("栈寻路"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r2 = { 550, 400, 750, 500 };
drawtext(_T("队列寻路"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else {
settextcolor(GREEN);
rectangle(550, 300, 750, 400);
rectangle(550, 400, 750, 500);
rectangle(550, 500, 750, 600);
RECT r1 = { 550, 300, 750, 400 };
drawtext(_T("栈寻路"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r2 = { 550, 400, 750, 500 };
drawtext(_T("队列寻路"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 550,500,750,600 };
drawtext(_T("退出"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
break;
case WM_LBUTTONDOWN:
EndBatchDraw();
if (Mou.x >= 550 && Mou.x <= 750 && Mou.y <= 400 && Mou.y >= 300) {
flag1 = 1;
closegraph();
MEUN2(stack,queue);
}
else if (Mou.x >= 550 && Mou.x <= 750 && Mou.y >= 400 && Mou.y <= 500){
flag1 = 2;
closegraph();
MEUN2(stack,queue);
}
else if (Mou.x >= 550 && Mou.x <= 750 && Mou.y >= 500 && Mou.y <= 600) {
closegraph();
flag = false;
}
break;
}
}
}
void MEUN2(struct Stack *&stack, struct Queue *&queue)
{
initgraph(1300, 600);
setbkcolor(WHITE);
cleardevice();
PrintLine();
settextcolor(GREEN);//字体颜色
LOGFONT f;
gettextstyle(&f); // 获取当前字体设置
f.lfHeight = 48; // 设置字体高度为 48
_tcscpy_s(f.lfFaceName, _T("微软雅黑")); // 设置字体为“黑体”(高版本 VC 推荐使用 _tcscpy_s 函数)
f.lfQuality = ANTIALIASED_QUALITY; // 设置输出效果为抗锯齿
settextstyle(&f); // 设置字体样式
rectangle(1050, 100, 1250, 150);//设置起点
rectangle(1050, 150, 1250, 200);//设置终点
rectangle(1050, 200, 1250, 250);//随机障碍
rectangle(1050, 250, 1250, 300);//开始寻路
rectangle(1050, 300, 1250, 350);//退出迷宫
RECT r1 = { 1050, 100, 1250, 150 };
drawtext(_T("设置起点"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r2 = { 1050, 150, 1250, 200 };
drawtext(_T("设置终点"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 1050, 200, 1250, 250 };
drawtext(_T("随机障碍"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r4 = { 1050, 250, 1250, 300 };
drawtext(_T("开始寻路"), &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r5 = { 1050, 300, 1250, 350 };
drawtext(_T("退出迷宫"), &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
MOUSEMSG Mou;
while (true) {
Mou = GetMouseMsg();
BeginBatchDraw();
switch (Mou.uMsg) {
case WM_MOUSEMOVE:
EndBatchDraw();
if ((Mou.x >= 1050 && Mou.x <= 1250) && (Mou.y >= 100 && Mou.y <= 150)) {
settextcolor(YELLOW);
rectangle(1050, 100, 1250, 150);
RECT r1 = { 1050, 100, 1250, 150 };
drawtext(_T("设置起点"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
settextcolor(GREEN);
rectangle(1050, 150, 1250, 200);//设置终点
rectangle(1050, 200, 1250, 250);//随机障碍
rectangle(1050, 250, 1250, 300);//开始寻路
rectangle(1050, 300, 1250, 350);//退出迷宫
RECT r2 = { 1050, 150, 1250, 200 };
drawtext(_T("设置终点"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 1050, 200, 1250, 250 };
drawtext(_T("随机障碍"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r4 = { 1050, 250, 1250, 300 };
drawtext(_T("开始寻路"), &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r5 = { 1050, 300, 1250, 350 };
drawtext(_T("退出迷宫"), &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else if (Mou.x >= 1050 && Mou.x <= 1250 && Mou.y >= 150 && Mou.y <= 200) {
settextcolor(YELLOW);
rectangle(1050, 150, 1250, 200);
RECT r2 = { 1050, 150, 1250, 200 };
drawtext(_T("设置终点"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
settextcolor(GREEN);
rectangle(1050, 100, 1250, 150);//设置起点
rectangle(1050, 200, 1250, 250);//随机障碍
rectangle(1050, 250, 1250, 300);//开始寻路
rectangle(1050, 300, 1250, 350);//退出迷宫
RECT r1 = { 1050, 100, 1250, 150 };
drawtext(_T("设置起点"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 1050, 200, 1250, 250 };
drawtext(_T("随机障碍"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r4 = { 1050, 250, 1250, 300 };
drawtext(_T("开始寻路"), &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r5 = { 1050, 300, 1250, 350 };
drawtext(_T("退出迷宫"), &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else if (Mou.x >= 1050 && Mou.x <= 1250 && Mou.y >= 200 && Mou.y <= 250) {
stack->top = -1;
queue->front = queue->rear = -1;
settextcolor(YELLOW);
rectangle(1050, 200, 1250, 250);
RECT r3 = { 1050, 200, 1250, 250 };
drawtext(_T("随机障碍"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
settextcolor(GREEN);
rectangle(1050, 100, 1250, 150);//设置起点
rectangle(1050, 150, 1250, 200);//设置终点
rectangle(1050, 250, 1250, 300);//开始寻路
rectangle(1050, 300, 1250, 350);//退出迷宫
RECT r1 = { 1050, 100, 1250, 150 };
drawtext(_T("设置起点"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r2 = { 1050, 150, 1250, 200 };
drawtext(_T("设置终点"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r4 = { 1050, 250, 1250, 300 };
drawtext(_T("开始寻路"), &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r5 = { 1050, 300, 1250, 350 };
drawtext(_T("退出迷宫"), &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else if (Mou.x >= 1050 && Mou.x <= 1250 && Mou.y <= 300 && Mou.y >= 250) {
settextcolor(YELLOW);
rectangle(1050, 250, 1250, 300);
RECT r4 = { 1050, 250, 1250, 300 };
drawtext(_T("开始寻路"), &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
settextcolor(GREEN);
rectangle(1050, 100, 1250, 150);//设置起点
rectangle(1050, 150, 1250, 200);//设置终点
rectangle(1050, 200, 1250, 250);//随机障碍
rectangle(1050, 300, 1250, 350);//退出迷宫
RECT r1 = { 1050, 100, 1250, 150 };
drawtext(_T("设置起点"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r2 = { 1050, 150, 1250, 200 };
drawtext(_T("设置终点"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 1050, 200, 1250, 250 };
drawtext(_T("随机障碍"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r5 = { 1050, 300, 1250, 350 };
drawtext(_T("退出迷宫"), &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else if (Mou.x >= 1050 && Mou.x <= 1250 && Mou.y >= 300 && Mou.y <= 350) {
settextcolor(YELLOW);
rectangle(1050, 250, 1250, 300);
RECT r5 = { 1050, 300, 1250, 350 };
drawtext(_T("退出迷宫"), &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
settextcolor(GREEN);
rectangle(1050, 100, 1250, 150);//设置起点
rectangle(1050, 150, 1250, 200);//设置终点
rectangle(1050, 200, 1250, 250);//随机障碍
rectangle(1050, 250, 1250, 300);//开始寻路
RECT r1 = { 1050, 100, 1250, 150 };
drawtext(_T("设置起点"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r2 = { 1050, 150, 1250, 200 };
drawtext(_T("设置终点"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 1050, 200, 1250, 250 };
drawtext(_T("随机障碍"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r4 = { 1050, 250, 1250, 300 };
drawtext(_T("开始寻路"), &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else {
settextcolor(GREEN);
rectangle(1050, 100, 1250, 150);//设置起点
rectangle(1050, 150, 1250, 200);//设置终点
rectangle(1050, 200, 1250, 250);//随机障碍
rectangle(1050, 250, 1250, 300);//开始寻路
rectangle(1050, 300, 1250, 350);//退出迷宫
RECT r1 = { 1050, 100, 1250, 150 };
drawtext(_T("设置起点"), &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r2 = { 1050, 150, 1250, 200 };
drawtext(_T("设置终点"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r3 = { 1050, 200, 1250, 250 };
drawtext(_T("随机障碍"), &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r4 = { 1050, 250, 1250, 300 };
drawtext(_T("开始寻路"), &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
RECT r5 = { 1050, 300, 1250, 350 };
drawtext(_T("退出迷宫"), &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
break;
case WM_LBUTTONDOWN:
EndBatchDraw();
if (Mou.x >= 1050 && Mou.x <= 1250 && Mou.y >= 100 && Mou.y <= 150) {

bool flag = true;
while (flag) {
//FlushMouseMsgBuffer();
Mou = GetMouseMsg();
BeginBatchDraw();
switch (Mou.uMsg) {
case WM_LBUTTONDOWN:
EndBatchDraw();
py1 = Mou.x / 50;
px1 = Mou.y / 50;
if (mg[py1 + 1][px1 + 1] != 1) {
setfillcolor(BLUE);
fillrectangle(Mou.x / 50 * 50, Mou.y / 50 * 50, Mou.x / 50 * 50 + 50, Mou.y / 50 * 50 + 50);
flag = false;
}
py1 += 1;
px1 += 1;
break;
}
}
}
else if (Mou.x >= 1050 && Mou.x <= 1250 && Mou.y >= 150 && Mou.y <= 200) {
bool flag = true;
while (flag) {
//FlushMouseMsgBuffer();
Mou = GetMouseMsg();
BeginBatchDraw();
switch (Mou.uMsg) {
case WM_LBUTTONDOWN:
EndBatchDraw();
py2 = Mou.x / 50;
px2 = Mou.y / 50;
if (mg[py2 + 1][px2 + 1] != 1) {
setfillcolor(YELLOW);
fillrectangle(Mou.x / 50 * 50, Mou.y / 50 * 50, Mou.x / 50 * 50 + 50, Mou.y / 50 * 50 + 50);
flag = false;
}
py2 += 1;
px2 += 1;
break;
}
}
}
else if (Mou.x >= 1050 && Mou.x <= 1250 && Mou.y >= 200 && Mou.y <= 250) {
stack->top = -1;
queue->front = queue->rear = -1;
init();
cleardevice();
PrintLine();
FillColor();
}
else if (Mou.x >= 1050 && Mou.x <= 1250 && Mou.y <= 300 && Mou.y >= 250) {
if (flag1 == 1) {
cout << px1 << ' ' << py1 << endl;
cout << px2 << ' ' << py2 << endl;
StackRoad(stack);
}
else if (flag1 == 2) {
cout << px1 << ' ' << py1 << endl;
cout << px2 << ' ' << py2 << endl;
QueueRoad(queue);
}
}
else if (Mou.x >= 1050 && Mou.x <= 1250 && Mou.y >= 300 && Mou.y <= 350) {
closegraph();
stack->top = -1;
queue->front = queue->rear = -1;
flag1 = 0;
init();
MEUN1(stack,queue);
}
}
}
}
int main()
{
//栈
struct Stack *stack;
stack = (struct Stack *)malloc(sizeof(struct Stack));
stack->top = -1;
//队列
struct Queue *queue;
queue = (struct Queue *)malloc(sizeof(struct Queue));
queue->rear = queue->front = -1;
//设置迷宫边界值
init();
//Sleep(1000);
MEUN1(stack,queue);
return 0;
}

编译完整版本:
链接:https://pan.baidu.com/s/1RrWjaRj_w47mxJy3aWdBhw
提取码:0dy0

下个目标:五子棋?

-------------本文结束感谢您的阅读-------------
0%