迷宫小游戏c语言代码,C语言编写的迷宫小游戏-源代码

#include #define N 20/*迷宫的大小,可改变*/

int oldmap[N][N];/*递归用的数组,用全局变量节约时间*/

int yes=0;/*yes是判断是否找到路的标志,1找到,0没找到*/

int way[100][2],wayn=0;/*way数组是显示路线用的,wayn是统计走了几个格子*/

void Init(void);/*图形初始化*/

void Close(void);/*图形关闭*/

void DrawPeople(int *x,int *y,int n);/*画人工探索物图*/

void PeopleFind(int (*x)[N]);/*人工探索*/

void WayCopy(int (*x)[N],int (*y)[N]);/*为了8个方向的递归,把旧迷宫图拷贝给新数组*/

int FindWay(int (*x)[N],int i,int j);/*自动探索函数*/

void MapRand(int (*x)[N]);/*随机生成迷宫函数*/

void PrMap(int (*x)[N]);/*输出迷宫图函数*/

void Result(void);/*输出结果处理*/

void Find(void);/*成功处理*/

void NotFind(void);/*失败处理*/

void main(void)/*主函数*/

{

int map[N][N]; /*迷宫数组*/

char ch;

clrscr();

printf("\n Please select hand(1) else auto\n");/*选择探索方式*/

scanf("%c",&ch);

Init(); /*初始化*/

MapRand(map);/*生成迷宫*/

PrMap(map);/*显示迷宫图*/

if(ch==1)

PeopleFind(map);/*人工探索*/

else

FindWay(map,1,1);/*系统自动从下标1,1的地方开始探索*/

Result();/*输出结果*/

Close();

}

void Init(void)/*图形初始化*/

{

int gd=DETECT,gm;

initgraph(&gd,&gm,"c:\\tc");

}

void DrawPeople(int *x,int *y,int n)/*画人工控制图*/

{/*如果将以下两句注释掉,则显示人工走过的路径,*/

setfillstyle(SOLID_FILL,WHITE); /*设置白色实体填充样式*/

bar(100+(*y)*15-6,50+(*x)*15-6,100+(*y)*15+6,50+(*x)*15+6);

/*恢复原通路*/

switch(n)/*判断x,y的变化,8个方向的变化*/

{

case 1: (*x)--;break; /*上*/

case 2: (*x)--;(*y)++;break ;/*右上*/

case 3: (*y)++;break; /*右*/

case 4: (*x)++;(*y)++;break; /*右下*/

case 5: (*x)++;break; /*下*/

case 6: (*x)++;(*y)--;break; /*左下*/

case 7: (*y)--;break; /*左*/

case 8: (*x)--;(*y)--;break; /*左上*/

}

setfillstyle(SOLID_FILL,RED);/*新位置显示探索物*/

bar(100+(*y)*15-6,50+(*x)*15-6,100+(*y)*15+6,50+(*x)*15+6);

}

void PeopleFind(int (*map)[N])/*人工手动查找*/

{

int x,y;

char c=0;/*接收按键的变量*/

x=y=1;/*人工查找的初始位置*/

setcolor(11);

line(500,200,550,200);

outtextxy(570,197,"d");

line(500,200,450,200);

outtextxy(430,197,"a");

line(500,200,500,150);

outtextxy(497,130,"w");

line(500,200,500,250);

outtextxy(497,270,"x");

line(500,200,450,150);

outtextxy(445,130,"q");

line(500,200,550,150);

outtextxy(550,130,"e");

line(500,200,450,250);

outtextxy(445,270,"z");

line(500,200,550,250);

outtextxy(550,270,"c");/*以上是画8个方向的控制介绍*/

setcolor(YELLOW);

outtextxy(420,290,"Press Enter to end");/*压回车键结束*/

setfillstyle(SOLID_FILL,RED);

bar(100+y*15-6,50+x*15-6,100+y*15+6,50+x*15+6);/*入口位置显示*/

while(c!=13)/*如果按下的不是回车键*/

{

c=getch();/*接收字符后开始各个方向的探索*/

if(c==w&&map[x-1][y]!=1)

DrawPeople(&x,&y,1);/*上*/

else

if(c==e&&map[x-1][y+1]!=1)

DrawPeople(&x,&y,2);/*右上*/

else

if(c==d&&map[x][y+1]!=1)

DrawPeople(&x,&y,3);/*右*/

else

if(c==c&&map[x+1][y+1]!=1)

DrawPeople(&x,&y,4);/*右下*/

else

if(c==x&&map[x+1][y]!=1)

DrawPeople(&x,&y,5);/*下*/

else

if(c==z&&map[x+1][y-1]!=1)

DrawPeople(&x,&y,6); /*左下*/

else

if(c==a&&map[x][y-1]!=1)

DrawPeople(&x,&y,7); /*左*/

else if(c==q&&map[x-1][y-1]!=1)

DrawPeople(&x,&y,8); /*左上*/

}

setfillstyle(SOLID_FILL,WHITE); /*消去红色探索物,恢复原迷宫图*/

bar(100+y*15-6,50+x*15-6,100+y*15+6,50+x*15+6);

if(x==N-2&&y==N-2)/*人工控制找成功的话*/

yes=1; /*如果成功标志为1*/

}

void WayCopy(int (*oldmap)[N],int (*map)[N])/*拷贝迷宫数组 */

{

int i,j;

for(i=0;i=0;i--)

{

bar(100+way[i][1]*15-6,50+way[i][0]*15-6,100+

way[i][1]*15+6,50+way[i][0]*15+6);

sleep(1);/*控制显示时间*/

}

bar(100+(N-2)*15-6,50+(N-2)*15-6,100+

(N-2)*15+6,50+(N-2)*15+6); /*在目标点标红色*/

setcolor(GREEN);

settextstyle(0,0,2);/*设置字体大小*/

outtextxy(130,400,"Find a way!");

}

void NotFind(void)/*没找到通路*/

{

setcolor(GREEN);

settextstyle(0,0,2);/*设置字体大小*/

outtextxy(130,400,"Not find a way!");

}

void Result(void)/*结果处理*/

{

if(yes)/*如果找到*/

Find();

else/*没找到路*/

NotFind();

getch();

}

void Close(void)/*图形关闭*/

{

closegraph();

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440405.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【ZOJ - 4032】Magic Points (思维,几何,构造)

题干: 解题报告: 想到了,这样绕圈构造。但是这样有个问题,最后一个点如何构造。 刚开始想的是n奇数 , 就8 10 这样的连一条,n偶数 就8 11 这样的连一条,随便构造一下就行,但是发…

s7-200 plc 梯形图转换成c语言的方法,S7-200PLC模拟量4-20mA转换成整数程序算法示例.pdf...

S7200PLC 模拟量4 -20 mA 转换成整数程序算法示例S7200PLC 模拟量4 -20 mA 转换成整数程序算法示例,以及模拟量数据滤波平缓处理,消除曲线的尖峰毛刺程序示例。连续采集10 个数,找出最大值,最小值&#xff…

【ZOJ - 4033】CONTINUE...? (思维,整体思想,分组思想)

题干: DreamGrid has classmates numbered from to . Some of them are boys and the others are girls. Each classmate has some gems, and more specifically, the -th classmate has gems. DreamGrid would like to divide the classmates into four group…

android 仿真翻页动画,Android 两Activity之间动画效果(1)---------翻页效果

用Android rotate动画实现翻页效果,效果如图:要实现上面动画,首先搞明白rotate动画原理;(1)Degrees坐标:0度(360度)270度90度 顺时针旋转 180(2)rotate 关键属性fromDegrees 开始旋转时角度 toDegrees 结束时的角…

android 存储不被垃圾清理,手机内存足够大,就不需要清理垃圾了?你错了!

原标题:手机内存足够大,就不需要清理垃圾了?你错了!中新网4月20日电今天,人们使用智能手机的时间已超过电脑,希望在任何时候、任何地方,一部手机搞定所有。对手机的流畅度、性能和安全的要求越来越高。新手机刚到手时非常流畅,用一段时间就出现各种卡顿,网民对猎豹…

【蓝桥杯 - 真题】六角幻方(dfs+剪枝)

标题:六角幻方 把 1 2 3 ... 19 共19个整数排列成六角形状,如下: * * * * * * * * * * * * * * * * * * * 要求每个直线上的数字之和必须相等。共有15条直线哦! 再给点线索吧!我们预先填好了2个数字&…

【2019浙江省赛 - J】Welcome Party(并查集,bfs,优先队列,建图)

题干: The 44th World Finals of the International Collegiate Programming Contest (ICPC 2020) will be held in Moscow, Russia. To celebrate this annual event for the best competitive programmers around the world, it is decided to host a welcome pa…

app android de,Android Deobfuscation

Android Deobfuscation11/11/2019本文内容ProGuard、DexGuard 和 R8 是用于对 Android 应用程序的代码进行优化和模糊处理的工具。 它会删除未使用的代码、重命名具有语义模糊名称的类、字段和方法,使基本代码更小,更难反向工程。 若要在 Android 应用中…

【2019浙江省赛 - B】Element Swapping(思维,数学)

题干: DreamGrid has an integer sequence and he likes it very much. Unfortunately, his naughty roommate BaoBao swapped two elements and () in the sequence when DreamGrid wasnt at home. When DreamGrid comes back, he finds with dismay that his …

android 没有指令,android – 运行时没有命令输出:’am start -n

最近,当我试图在我的设备上运行我的Android应用程序时,我必须在实际启动之前从Eclipse运行它几次.我试图重新安装JRE,JDK和IDE,我试图切换工作区.我还让Eclipse为Java VM使用更多的RAM.我的IDE,JRE,JDK,ADT和ADT插件都是最新的.对此有任何建议非常感谢.No command output when …

【2019浙江省赛 - E】Sequence in the Pocket(思维)

题干: DreamGrid has just found an integer sequence in his right pocket. As DreamGrid is bored, he decides to play with the sequence. He can perform the following operation any number of times (including zero time): select an element and move i…

android和ios系统的内存,WP和Saipan系统的流畅程度相当于ios,占用的内存很少,但是为什么要用Android取代它...

当涉及到WP和Symbian系统时,许可能没有听说过它,但是对于大多数关注智能手机市场增长的消费者来说,它已经为人们所熟悉,并且许已经使用了它. 当时在功能性机器上使用了Saipan系统,但是您会发现该系统的流畅性与当时的i…

【CodeForces - 1042C】Array Product(思维,有坑细节)

题干: You are given an array aa consisting of nn integers. You can perform the following operations with it: Choose some positions ii and jj (1≤i,j≤n,i≠j1≤i,j≤n,i≠j), write the value of ai⋅ajai⋅aj into the jj-th cell and remove the num…

红米pro android o刷机,红米Pro如何刷机?你可以通过这两种方法获取root权限!

小米官网最近发布了关于红米pro的消息,相信很多米粉们已经上手了,那么新到手的机子怎么刷机呢?下面小编为大家带来一个完整的红米Pro官方卡刷机教程,希望可以帮助到大家。红米Pro卡刷升级教程:准备工作1.进入红米Pro刷…

【2019浙江省赛 - K 】Strings in the Pocket(马拉车,思维)

题干: BaoBao has just found two strings and in his left pocket, where indicates the -th character in string , and indicates the -th character in string . As BaoBao is bored, he decides to select a substring of and reverse it. Formally spe…

android+微信一键关注,一键关注微信公众平台JS代码有哪些?

一键关注微信公众平台JS代码有哪些?在网页设置一个按钮或者链接可以让用户一键关注微信公众平台,那么这种一键关注微信公众平台的功能如何实现呢?下面小编分享给大家一键关注微信公众平台的JS代码。在微信上,通过微信公众平台推送…

【2019浙江省赛 - A】Vertices in the Pocket(权值线段树下二分,图,思维)

题干: DreamGrid has just found an undirected simple graph with vertices and no edges (thats to say, its a graph with isolated vertices) in his right pocket, where the vertices are numbered from 1 to . Now he would like to perform operations …

html写原生曲线图,HTML5 平滑的正弦波曲线图

JavaScript语言:JaveScriptBabelCoffeeScript确定var waves new SineWaves({el: document.getElementById(waves),speed: 4,width: function() {return $(window).width();},height: function() {return $(window).height();},ease: SineInOut,wavesWidth: 80%,wav…

【CodeForces - 1150C】Prefix Sum Primes(思维)

题干: Were giving away nice huge bags containing number tiles! A bag we want to present to you contains nn tiles. Each of them has a single number written on it — either 11or 22. However, there is one condition you must fulfill in order to re…

asp.net 写入html代码,asp.net读取模版并写入文本文件

本文要介绍的是ASP.NET怎样读写文本文件,但更重要的是实现的过程。使用的工具是Visual Studio 2015 ,.NET版本是4.6.1 。一共建立的2个项目,HoverTreePanel和HoverTreeWeb,都是ASP.NET项目。文章末尾附源码下载。项目结果如下图&a…