commit ce88d0c38748f3dcab570e62c7abc12fd942b363 Author: unknown <18408000536@stu.hut.edu.cn> Date: Fri Jan 4 12:09:21 2019 +0800 first commit diff --git a/迷宫随机地图.cpp b/迷宫随机地图.cpp new file mode 100644 index 0000000..f70040f --- /dev/null +++ b/迷宫随机地图.cpp @@ -0,0 +1,80 @@ + +#include +#include +#include +#include +#define Height 25 //Թĸ߶ȣΪ +#define Width 25 //ԹĿȣΪ +#define Wall 1 +#define Road 0 +#define Start 2 +#define End 3 +int map[Height+2][Width+2]; +void gotoxy(int x,int y) //ƶ +{ +COORD coord; +coord.X=x; +coord.Y=y; +SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord ); +} +void create(int x,int y) //Թ +{ +int c[4][2]={0,1,1,0,0,-1,-1,0}; //ĸ +int i,j,t;// +for(i=0;i<4;i++) +{ +j=rand()%4; +t=c[i][0];c[i][0]=c[j][0];c[j][0]=t; +t=c[i][1];c[i][1]=c[j][1];c[j][1]=t; +} +map[x][y]=Road; +for(i=0;i<4;i++) +if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall) +{ +map[x+c[i][0]][y+c[i][1]]=Road; +create(x+2*c[i][0],y+2*c[i][1]); +} +} +void paint(int x,int y) //Թ +{ +gotoxy(2*y-2,x-1); +switch(map[x][y]) +{ +case Start: +printf("");break; // +case End: +printf("");break; // +case Wall: +printf("~");break; //ǽ +case Road: +printf(" ");break; //· +} +} +int main() +{ +system("title ԹϷ"); +int i,j; +srand((unsigned)time(NULL)); //ʼ漴 +for(i=0;i<=Height+1;i++) +for(j=0;j<=Width+1;j++) +if(i==0||i==Height+1||j==0||j==Width+1) //ʼԹ +map[i][j]=Road; +else map[i][j]=Wall; +create(2*(rand()%(Height/2)+1),2*(rand()%(Width/2)+1)); //һ㿪ʼԹõжΪż +for(i=0;i<=Height+1;i++) //߽紦 +{ +map[i][0]=Wall; +map[i][Width+1]=Wall; +} +for(j=0;j<=Width+1;j++) //߽紦 +{ +map[0][j]=Wall; +map[Height+1][j]=Wall; +} +map[2][1]=Start; // +map[Height-1][Width]=End; // +for(i=1;i<=Height;i++) +for(j=1;j<=Width;j++) //Թ +paint(i,j); +return 0; +} diff --git a/迷宫随机地图.exe b/迷宫随机地图.exe new file mode 100644 index 0000000..186ad0c Binary files /dev/null and b/迷宫随机地图.exe differ