迷宫中的问题

编程入门 行业动态 更新时间:2024-10-22 23:23:28
本文介绍了迷宫中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好 我正在使用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&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

推荐答案

此问题已在 C/C ++/MFC论坛 [ ^ ].

更多推荐

迷宫中的问题

本文发布于:2023-11-30 11:42:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649844.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:迷宫

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!