已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
贪吃蛇源代码完美运行,结尾附图#include #include #include #include int printMap(int map16);void moveBox(int map16,int x,int y,int select,int map216);int insert(int map16,int map216,int sum);void UI();void img1();void img2();void img3();void img4();void img5();void img6();void color(int b) /颜色函数 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE) ; SetConsoleTextAttribute(hConsole,b) ; void img1() int map21416; int i,j,sum=0; int map1416= 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0, 0,0,0,0,0,0,1,3,1,0,0,0,0,0,0,0, 0,0,0,1,1,1,1,4,1,0,0,0,0,0,0,0, 0,0,0,1,3,2,4,6,1,1,1,0,0,0,0,0, 0,0,0,1,1,1,4,2,4,3,1,0,0,0,0,0, 0,0,0,0,0,1,2,1,1,1,1,0,0,0,0,0, 0,0,0,0,0,1,3,1,0,0,0,0,0,0,0,0, 0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, ; for(i=0;i14;i+) for(j=0;j16;j+) map2ij=mapij; if(mapij = 3 | mapij = 5) sum+; insert(map,map2,sum); img2();void img2() int map21416; int i,j,sum=0; int map1416= 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 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,0,0,1,2,6,3,3,3,1,0,0,0,0,0, 0,0,0,0,1,2,2,2,2,2,1,1,0,0,0,0, 0,0,0,1,1,1,4,2,2,2,2,1,0,0,0,0, 0,0,0,1,2,2,2,2,2,2,2,1,0,0,0,0, 0,0,0,1,2,4,2,1,4,1,2,1,0,0,0,0, 0,0,0,1,2,2,2,1,2,2,2,1,0,0,0,0, 0,0,0,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, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, ; for(i=0;i14;i+) for(j=0;j16;j+) map2ij=mapij; if(mapij = 3 | mapij = 5) sum+; insert(map,map2,sum); img3();void img3() int map21416; int i,j,sum=0; int map1416= 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,0,0,0,0,0,0,0, 0,0,0,0,1,2,2,6,1,0,0,0,0,0,0,0, 0,0,0,0,1,2,4,4,1,0,1,1,1,0,0,0, 0,0,0,0,1,2,4,2,1,0,1,3,1,0,0,0, 0,0,0,0,1,1,1,2,1,1,1,3,1,0,0,0, 0,0,0,0,0,1,1,2,2,2,2,3,1,0,0,0, 0,0,0,0,0,1,2,2,2,1,2,2,1,0,0,0, 0,0,0,0,0,1,2,2,2,1,1,1,1,0,0,0, 0,0,0,0,0,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,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, ; for(i=0;i14;i+) for(j=0;j16;j+) map2ij=mapij; if(mapij = 3 | mapij = 5) sum+; insert(map,map2,sum); img4();void img4() int map21416; int i,j,sum=0; int map1416= 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0, 0,0,0,0,0,0,1,2,2,1,0,0,0,0,0,0, 0,0,0,0,0,1,1,2,2,1,0,0,0,0,0,0, 0,0,0,0,0,1,6,4,2,1,0,0,0,0,0,0, 0,0,0,0,0,1,1,4,2,1,1,0,0,0,0,0, 0,0,0,0,0,1,1,2,4,2,1,0,0,0,0,0, 0,0,0,0,0,1,3,4,2,2,1,0,0,0,0,0, 0,0,0,0,0,1,3,3,5,3,1,0,0,0,0,0, 0,0,0,0,0,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,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, ; for(i=0;i14;i+) for(j=0;j16;j+) map2ij=mapij; if(mapij = 3 | mapij = 5) sum+; insert(map,map2,sum); img5();void img5() int map21416; int i,j,sum=0; int map1416= 0,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,1,1,1,1,2,2,2,2,2,1,0,0,0,0, 0,0,1,2,2,2,3,1,1,1,2,1,0,0,0,0, 0,0,1,2,1,2,1,2,2,2,2,1,1,0,0,0, 0,0,1,2,1,2,4,2,4,1,3,2,1,0,0,0, 0,0,1,2,1,2,2,5,2,2,1,2,1,0,0,0, 0,0,1,2,3,1,4,2,4,2,1,2,1,0,0,0, 0,0,1,1,2,2,2,2,1,2,1,2,1,1,1,0, 0,0,0,1,2,1,1,1,3,2,2,2,2,6,1,0, 0,0,0,1,2,2,2,2,2,1,1,2,2,2,1,0, 0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0, ; for(i=0;i14;i+) for(j=0;j16;j+) map2ij=mapij; if(mapij = 3 | mapij = 5) sum+; insert(map,map2,sum); img5();void img6() int map21416; int i,j,sum=0; int map1416= 0,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,0,0,1,3,2,3,2,3,1,0,0,0,0, 0,0,0,0,0,1,2,4,4,4,2,1,0,0,0,0, 0,0,0,0,0,1,3,4,6,4,3,1,0,0,0,0, 0,0,0,0,0,1,2,4,4,4,2,1,0,0,0,0, 0,0,0,0,0,1,3,2,3,2,3,1,0,0,0,0, 0,0,0,0,0,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, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, ; for(i=0;i14;i+) for(j=0;j16;j+) map2ij=mapij; if(mapij = 3 | mapij = 5) sum+; insert(map,map2,sum);int insert(int map16,int map216,int sum) int i,j; int x,y; /人的位置 char op; /所按下的方向键 int num = 0; /还剩下几个箱子没有推向目的地 while(1) for(i=0;i14;i+) for(j=0;j16;j+) if(mapij = 6) goto found; found: x = i; y = j; system(cls); num = printMap(map); if(num = sum) printf( 你通关了.n); return 0; else op = getch(); if(op = Q) | (op =q) printf(退出.n); return 2; op = getch(); switch(op) case 72: /上箭头 moveBox(map,x,y,1,map2); break; case 75: /左箭头 moveBox(map,x,y,2,map2); break; case 77: /右箭头 moveBox(map,x,y,3,map2); break; case 80: /下箭头 moveBox(map,x,y,4,map2); break; default: break; int printMap(int map16) int i,j; int count = 0; for(i=0;i14;i+) for(j=0;j16;j+) switch(mapij) case 0: /空地 printf( ); break; case 1: /墙 color(13); printf(); break; case 2: /内部空地 printf( ); break; case 3: /目的地 color(11); printf(); break; case 4: /箱子 color(8); printf(); break; case 5: /箱子推到目的地后显示 count+; color(9); printf(); break; case 6: /小人 color(10); printf(); break; printf(n); printf(nn); printf(按方向键操作游戏,按Q退出!n); return count;void moveBox(int map16,int x,int y,int select,int map216) int x1,y1; /下个位置的坐标 int x2,y2; /下下个位置的坐标 switch(select) case 1: /向上移动 x1 = x - 1; y1 = y; x2 = x - 2; y2 = y; break; case 2: /向左移动 x1 = x; y1 = y - 1; x2 = x; y2 = y - 2; break; case 3: /向右移动 x1 = x; y1 = y + 1; x2 = x; y2 = y + 2; break; case 4: /向下移动 x1 = x + 1; y1 = y; x2 = x + 2; y2 = y; break; default: break; /operate map switch(mapx1y1) case 1: /墙,不动 break; case 2: if(map2xy = 3)/空格,分情况变换 mapx1y1 = 6; mapxy = 3; else mapx1y1 = 6; mapxy = 2; break; case 3: if(map2xy = 3)/目的地,分情况变换 mapx1y1 = 6; mapxy = 3; else mapx1y1 = 6; mapxy = 2; break; case 4: if(mapx2y2 = 3) mapx2y2 = 5; mapx1y1 = 6; if(map2xy = 2 | map2xy = 6) mapxy = 2; else if(map2xy = 3) mapxy = 3; else mapxy = 2; else if(mapx2y2 = 2 | map2xy = 6) mapx2y2 = 4; mapx1y1 = 6; if(map2xy = 2 | map2xy = 6) mapxy = 2; else if(map2xy = 3) mapxy = 3; else mapxy = 2; break; case 5: if(map2xy = 2 | map2xy = 6) & map2x2y2 = 3) mapx2y2 = 5; mapx1y1 = 6; mapxy = 2; else if(map2xy = 3 & mapx2y2 = 3) mapx2y2 =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 岗位安全教育培训全套课件及考试题集
- 2026安徽阜阳市妇女儿童医院校园招聘16人考试笔试备考题库及答案解析
- 2025国务院发展研究中心有关直属事业单位招聘19人笔试考试参考试题及答案解析
- 2026安徽合肥市建投集团校园招聘20人笔试考试参考试题及答案解析
- 项目投资效益评估全面报告
- 高考政治一轮复习 第01课 在生活中学民法用民法(练习)(原卷版)
- 中央空调系统采购招标文件范本
- 2025西安市经开第六中学教师招聘(4人)考试笔试备考试题及答案解析
- 2025年黑河北安通北镇社区公开招聘公益性岗位6人考试笔试备考试题及答案解析
- 燃气锅炉安全运行管理手册
- GB/T 27689-2011无动力类游乐设施儿童滑梯
- GB/T 21010-2007土地利用现状分类
- GB/T 10125-2021人造气氛腐蚀试验盐雾试验
- 冬期混凝土施工测温记录表完整
- 泥浆护壁成孔灌注桩方案
- 中级无机化学答案版
- 道德与法治教研活动记录
- 完全平方公式(课件)
- 对全球变暖认识的七个问题的确定与不确定性
- 烟台中集来福士海洋工程有限公司授信方案(国内证、福费廷)
- 混凝土防渗墙施工作业指导书
评论
0/150
提交评论