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,0,0,0,0,0,1,0,0,0,0,0,0,0,1, 1,0,1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1, 1,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1, 1,0,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1, 1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,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,1,1,1,1,1 } ; temp=a[x][y]; a[x][y]=2; for (i=0;i<24;i++) { for (j=0;j<25;j++) printf("%c",a[i][j]); printf("\n"); } a[x][y]=temp; loop: s=getch(); while (s!='0') { switch (s) { case 'a': if (a[x][y-1]==0) y=y-1;else goto loop ;break; case 'd': if (a[x][y+1]==0) y=y+1;else goto loop ;break; case 'w': if (a[x-1][y]==0 ) x=x-1;else goto loop ;break; case 's': if (a[x+1][y]==0 ) x=x+1;else goto loop ;break; default :goto loop; } //system("cls"); temp=a[x][y]; a[x][y]=2; if (a[0][1]==2) {printf("great job!\n"); getch(); break;} for (i=0;i<24;i++) { for (j=0;j<25;j++) printf("%c",a[i][j]); printf("\n"); } a[x][y]=temp; s=getch(); } } |
用c语言写迷宫算法 谢谢
贴错了