Click here to Skip to main content
15,889,116 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Can someone give a detail of this sample coder why the result is 9,and not 4?? Pin
CPallini20-Jun-10 4:51
mveCPallini20-Jun-10 4:51 
AnswerRe: Can someone give a detail of this sample coder why the result is 9,and not 4?? Pin
hasani200720-Jun-10 4:51
hasani200720-Jun-10 4:51 
AnswerRe: Can someone give a detail of this sample coder why the result is 9,and not 4?? PinPopular
Richard MacCutchan20-Jun-10 5:49
mveRichard MacCutchan20-Jun-10 5:49 
JokeRe: Can someone give a detail of this sample coder why the result is 9,and not 4?? Pin
Rajesh R Subramanian20-Jun-10 6:42
professionalRajesh R Subramanian20-Jun-10 6:42 
AnswerRe: Can someone give a detail of this sample coder why the result is 9,and not 4?? Pin
Hristo-Bojilov20-Jun-10 6:23
Hristo-Bojilov20-Jun-10 6:23 
GeneralRe: Can someone give a detail of this sample coder why the result is 9,and not 4?? Pin
Luc Pattyn20-Jun-10 11:04
sitebuilderLuc Pattyn20-Jun-10 11:04 
AnswerRe: Can someone give a detail of this sample coder why the result is 9,and not 4?? - sorta repost Pin
Iain Clarke, Warrior Programmer21-Jun-10 0:26
Iain Clarke, Warrior Programmer21-Jun-10 0:26 
QuestionHow to find the correct coordinate? Pin
hasani200720-Jun-10 4:28
hasani200720-Jun-10 4:28 
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},
};

/* 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;
      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");}
}




/* function to create the walls */
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("**");
}
/* 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;

      }
}


Where is the problem.
AnswerRe: How to find the correct coordinate? Pin
Niklas L21-Jun-10 0:44
Niklas L21-Jun-10 0:44 
Questiona problem in maze (the worm pass the walls) Pin
hasani200720-Jun-10 0:25
hasani200720-Jun-10 0:25 
AnswerRe: a problem in maze (the worm pass the walls) Pin
Hristo-Bojilov20-Jun-10 0:45
Hristo-Bojilov20-Jun-10 0:45 
AnswerRe: a problem in maze (the worm pass the walls) Pin
Aescleal20-Jun-10 0:54
Aescleal20-Jun-10 0:54 
GeneralRe: a problem in maze (the worm pass the walls) Pin
hasani200720-Jun-10 1:10
hasani200720-Jun-10 1:10 
QuestionHow to get flash handle(ocx) in bho Pin
ZEROFIELD19-Jun-10 16:24
ZEROFIELD19-Jun-10 16:24 
AnswerCrosspost Pin
Richard MacCutchan19-Jun-10 21:28
mveRichard MacCutchan19-Jun-10 21:28 
QuestionWMI getting IP-Address [modified] Pin
Marcel Vogt19-Jun-10 4:23
Marcel Vogt19-Jun-10 4:23 
AnswerSuggestion Pin
Baltoro19-Jun-10 8:52
Baltoro19-Jun-10 8:52 
GeneralRe: Suggestion Pin
Marcel Vogt19-Jun-10 8:59
Marcel Vogt19-Jun-10 8:59 
GeneralRe: Suggestion Pin
Baltoro19-Jun-10 9:16
Baltoro19-Jun-10 9:16 
AnswerRe: WMI getting IP-Address Pin
Luc Pattyn19-Jun-10 9:26
sitebuilderLuc Pattyn19-Jun-10 9:26 
AnswerRe: WMI getting IP-Address Pin
Hristo-Bojilov20-Jun-10 3:44
Hristo-Bojilov20-Jun-10 3:44 
QuestionWhich is faster? Pin
Code-o-mat19-Jun-10 0:48
Code-o-mat19-Jun-10 0:48 
AnswerRe: Which is faster? Pin
Aescleal19-Jun-10 0:55
Aescleal19-Jun-10 0:55 
GeneralRe: Which is faster? Pin
Code-o-mat19-Jun-10 1:00
Code-o-mat19-Jun-10 1:00 
GeneralRe: Which is faster? [modified] Pin
Code-o-mat19-Jun-10 5:16
Code-o-mat19-Jun-10 5:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.