迷宫源代码: #include
#define STACK_INIT_SIZE 200 #define STACKINCREMENT 10 typedef int Boolean; typedef int Status; typedef suct { int x; int y; } PosType; typedef suct { int ord; PosType seat; int di; } SElemType; typedef suct { int ; int foot; int mark; } MazeType; typedef suct {
SElemType *base; SElemType *top; int stacksize; } Stack; int Maze[20][30]; MazeType maze[20][30]; PosType StartPlace; PosType EndPlace; int count; int m,n;
Boolean b_start=FALSE,b_end=FALSE; void CreatMaze(void);
Status SaveMaze(char *filename); Status LoadMaze(char *filename); void Error(char *message); Status InitStack(Stack *s); Status DesoyStack(Stack *s); Status ClearStack(Stack *s); Boolean StackEmpty(Stack *s); int StackLength(Stack *s);
Status Push(Stack *s,SElemType e); SElemType Pop(Stack *s,SElemType e); Status GetTop(Stack *s,SElemType *e);
Status StackTraverse(Stack *s,Status (* visit)(SElemType *se)); Boolean Pass(PosType curpos); void MarkPrint(PosType seat); void FootPrint(PosType curpos); PosType NextPos(PosType seat,int di); Status MazePath(PosType start,PosType end); void CreatMaze(void) /* Form the maze. */ {
void Error(char *message); Status SaveMaze(char *filename); Status LoadMaze(char *filename); int i,j; int x,y; char c;
char savename[12],loadname[12]; Boolean flag=FALSE,load=FALSE; clrscr();
printf(\
printf(\printf(\printf(\do {
c=getch(); switch(c) {
case ''''''''''''''''''''''''''''''''1'''''''''''''''''''''''''''''''': putch(''''''''''''''''''''''''''''''''1''''''''''''''''''''''''''''''''); break; case ''''''''''''''''''''''''''''''''2'''''''''''''''''''''''''''''''': putch(''''''''''''''''''''''''''''''''2''''''''''''''''''''''''''''''''); break; case Esc: sleep(1); exit(1); default: break; } }
while(c!=''''''''''''''''''''''''''''''''1''''''''''''''''''''''''''''''''&&c!=''''''''''''''''''''''''''''''''2'''''''''''''''''''''''''''''''') ; if(c==''''''''''''''''''''''''''''''''1'''''''''''''''''''''''''''''''') {
printf(\scanf(\if(LoadMaze(loadname)) {
sleep(1); load=TRUE; }
else { gotoxy(1,9); printf(\} if(!load) {
printf(\printf(\scanf(\printf(\scanf(\
if(m<4||n<4) Error(\
if(m>30||n>20) Error(\for(i=0;i<30;i ) for(j=0;j<20;j ) Maze[j][i]=2; StartPlace.x=0; StartPlace.y=0; EndPlace.x=0; EndPlace.y=0;
clrscr();BR> for(i=1;i<=n;i )