迷宫中的问题 [英] a problem in maze
本文介绍了迷宫中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我正在使用Turbo C迷宫(命令提示符不是Windows).我写了90%.
但有2个问题,我做任何工作都无法解决.
1-当蠕虫(**是我的蠕虫)到达墙壁时,它不会停止.它可以穿过墙壁吗?
2-蠕虫会变长,但随时都应该**吗?
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<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;
}
}
请帮助我解决问题.
在此先感谢
Please help me to solve the problems.
Thanks in advance
推荐答案
此问题已在 ^ ].
这篇关于迷宫中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文