Hello all
this is my maze. when the worm reach to wall it passes the wall and sometime it stops.
#include <stdio.h>
#include <conio.h>
int dir=0;
char wall[40][50]={
{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},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1},
{1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,1},
{1,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,1},
{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
{1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,0,1},
{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
{1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,0,1},
{1,0,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1},
{1,1,1,1,1,1,1,1,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1},
{1,1,0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,1},
{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
{1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,0,1},
{1,0,1,0,0,1,1,1,1,1,1,1,1,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,1},
};
create_wall();
arrow_keys();
void main()
{
int a=3,b=2;
create_wall();
lbl : arrow_keys();
if (dir==72){
b-=1;
if (wall[a][b]==0){wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
else b+=1;goto lbl;
}
if (dir==75){
a-=1;
if (wall[a][b]==0){wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
else a+=1;goto lbl;
}
if (dir==77){
a+=1;
if (wall[a][b]==0){wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
else a-=1;goto lbl;
}
if (dir==80){
b+=1;
if (wall[a][b]==0){wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
else b-=1;goto lbl;
}
if (dir==0) {printf("exit");}
}
create_wall(){
clrscr();
int i,j;
for(i=0;i<15;i++){
for(j=0;j<26;j++){
if (wall[i][j]==1) printf("²");
else printf(" ");
}
printf("\n");
}
gotoxy(2,2);
printf("**");
}
int arrow_keys()
{
int ch;
while(1)
{
ch=getch();
if(ch==0)
{
ch=getch();
if(ch==72) {dir=72; break;}
if(ch==75) {dir=75; break;}
if(ch==77) {dir=77; break;}
if(ch==80) {dir=80; break;}
}
else dir=0;
break;
}
}
Where is the problem.
|