已知用二维数组表示的迷宫通道,用c语言libgraphics图形库绘制迷宫地图
时间: 2024-03-03 12:52:59 浏览: 101
好的,我可以为你提供一些绘制迷宫地图的代码,但是需要你提供更多的细节,例如迷宫的起点和终点位置、迷宫的大小、迷宫通道的颜色等等。
以下是一个简单的示例代码,绘制一个迷宫大小为20x20的地图,迷宫通道为白色,墙壁为黑色:
```c
#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int maze[20][20] = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1},
{1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1},
{1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
{1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1},
{1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1},
{1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
int x, y;
int cell_width = 30;
int cell_height = 30;
for (x = 0; x < 20; x++) {
for (y = 0; y < 20; y++) {
if (maze[x][y] == 0) {
setfillstyle(SOLID_FILL, WHITE);
bar(x * cell_width, y * cell_height, (x + 1) * cell_width, (y + 1) * cell_height);
} else {
setfillstyle(SOLID_FILL, BLACK);
bar(x * cell_width, y * cell_height, (x + 1) * cell_width, (y + 1) * cell_height);
}
}
}
getch();
closegraph();
return 0;
}
```
你可以根据自己的需求修改代码中的迷宫数组和单元格的大小,以及使用不同的颜色来绘制迷宫地图。
阅读全文
相关推荐


















