Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all
I am working on maze in turbo c(command prompt not windows). I write 90% of it.
but there are 2 problems I do any work can't solve it.
1- When worm(** is my worm) reach a wall it don't stop. it can pass the wall?
2- the worm make longer but it should be ** in any time?


#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,1,1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,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,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},
};

/* prototypes */
create_wall();
arrow_keys();
/* end of prototypes */

void main()
{
   int a=3,b=2;
   create_wall();
   lbl : arrow_keys();
   if (dir==72){b-=1; wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
   if (dir==75){a-=1; wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
   if (dir==77){a+=1; wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
   if (dir==80){b+=1; wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
   if (dir==0) {printf("exit");}
}




/* function to create the walls */
create_wall(){
   clrscr();
   int i,j;
   for(i=0;i&lt;15;i++){
      for(j=0;j&lt;26;j++){
      if (wall[i][j]==1) printf("²");
      else printf(" ");
      }
   printf("\n");
   }
   gotoxy(2,2);
   printf("**");
}
/* end of create_wall function */
////////////////////////////////////
/* function to define arrow keys */
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;

      }
}


Please help me to solve the problems.
Thanks in advance
Posted
Updated 20-Jun-10 0:39am
v3

1 solution

This question has already been answered in the C/C++/MFC Forum[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900