版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include #include /用到system()#include /因为需要用到getch()函数/推箱子_C语言版/写了一下午,第一个C语言游戏终于写好了,想想有点小激动./蔚蓝之链编写/分享给大家参考下(在看得懂的情况下.),代码写得很凌乱.,勿喷#define X 20#define Y 20#define REN 2#define XIANGZI 3#define WEIZHI 4#define KONG 0#define QIANG 1#define RW 6#define XW 5#define bool short#define false 0#define true
2、1/数组内部数值表示内容:0表示空位,1表示墙体,2表示人,3表示箱子,4表示箱子要推到的位置,5表示既有箱子又有又位置,6表示既有位置又有人/01,2,3,4符号表示:/0 : 1:2:3:回4:void create_map_arr(int _x,int _y,int (*map_arr)Y);/创建地图数组void creata_map(int _x,int _y, int (*map)Y);/创建地图,重绘游戏画面void amend_map(int _x,int _y,char key , int (* arr_map)Y);/接收输入,修改游戏画面bool is_finish(in
3、t _x, int _y,int _total ,int (*arr_map)Y);/判断是否完成推箱子(地图x,地图y,总箱子数,地图数组)int main(void)int map_arrXY;/存储地图的二维数组create_map_arr(X,Y,map_arr);/创建数组printf(C语言_推箱子v1.0 蔚蓝之链编写nn);printf(控制键:W,A,S,Dn);printf(提示:玩本游戏前请先关闭输入法n);system(pause);system(cls);while(1)creata_map(X,Y,map_arr);/创建地图,重绘游戏画面if(is_finish(
4、X,Y,2,map_arr) = true)printf(恭喜哦,推箱子完成!n);system(pause);return 0;amend_map(X,Y,getch(),map_arr);/接收输入,修改画面system(cls);/清空画面getchar();return 0;void create_map_arr (int _x,int _y,int (*map_arr)Y)/创建地图数组int x,y;for(x=0;x_x;x+)for (y=0;y_y;y+)if(y=0 | x=0 | x=_x-1 | y=_y-1)*(*(map_arr+x)+y) = QIANG;/pri
5、ntf ();else*(*(map_arr+x)+y) = KONG;/printf ( );/printf(n);/这里可以修改箱子创建的位置,人创建的位置及箱子要达到的位置,默认两个箱子*(*(map_arr+3)+7)=REN;/人*(*(map_arr+5)+6)=XIANGZI;/箱子*(*(map_arr+5)+7)=XIANGZI;/箱子*(*(map_arr+1)+8)=WEIZHI;/箱子要推到的位置*(*(map_arr+2)+8)=WEIZHI;/箱子要推到的位置void creata_map(int _x,int _y, int (*map)Y)/创建地图(地图数组)
6、int x,y;for(x = 0; x _x; x+)for (y = 0; y _y; y+)if (*(*(map + x) + y) = QIANG)printf ();else if(*(*(map + x) + y) = KONG) printf ( );else if(*(*(map + x) + y)=REN | *(*(map + x) + y)=RW)printf ();else if (* (*(map + x) + y)=XIANGZI)printf();else if (*(*(map + x) + y)=WEIZHI)printf();else if(*(*(map
7、 + x) + y) = XW)printf(回);printf (n);/这个函数写的太乱了,自己看着也头大,不过还好,总算完成了_void amend_map(int _x,int _y,char key , int (* arr_map)Y)/移动(地图x,地图y,按键值,地图数组)int x,y;for(x = 0; x _x; x+)for (y = 0; y 0)if(*(*(arr_map + x) +(y) = RW)/人在最终位置if(*( * (arr_map + x ) + (y-1) = WEIZHI)/人左边还是最终位置*( * (arr_map + x ) + (y
8、-1) = RW;*( * (arr_map + x ) + y) = WEIZHI;else if(*( * (arr_map + x ) + (y-1) = XIANGZI | *( * (arr_map + x ) + (y-1) = XW)if(*( * (arr_map + x ) + (y-1) = XW)if (*( * (arr_map + x ) + (y-2) = KONG)*( * (arr_map + x ) + (y-2) = XIANGZI;*( * (arr_map + x ) + (y-1) = RW;*( * (arr_map + x ) + (y) = WE
9、IZHI;else if(*( * (arr_map + x ) + (y-2) = WEIZHI)*( * (arr_map + x ) + (y-2) = XW;*( * (arr_map + x ) + (y-1) = RW;*( * (arr_map + x ) + (y) = WEIZHI;else if(*(*(arr_map + x) + (y - 1) = XIANGZI )if (*( * (arr_map + x ) + (y-2) = KONG)*( * (arr_map + x ) + (y-2) = XIANGZI;*( * (arr_map + x ) + (y-1
10、) = REN;*( * (arr_map + x ) + (y) = WEIZHI;else if(*( * (arr_map + x ) + (y-2) = WEIZHI)*( * (arr_map + x ) + (y-2) = XW;*( * (arr_map + x ) + (y-1) = REN;*( * (arr_map + x ) + (y) = WEIZHI;else if(*(*(arr_map + x) + (y - 1) = KONG)*( * (arr_map + x ) + (y-1) = REN;*( * (arr_map + x ) + (y) = WEIZHI
11、;else if (*(*(arr_map + x) +(y) = REN)/人在空位if(*( * (arr_map + x ) + (y-1) = WEIZHI)/人左边是最终位置*( * (arr_map + x ) + (y-1) = RW;*( * (arr_map + x ) + y) = KONG;else if(*( * (arr_map + x ) + (y-1) = XIANGZI | *( * (arr_map + x ) + (y-1) = XW)if(*( * (arr_map + x ) + (y-1) = XW)if (*( * (arr_map + x ) +
12、(y-2) = KONG)*( * (arr_map + x ) + (y-2) = XIANGZI;*( * (arr_map + x ) + (y-1) = RW;*( * (arr_map + x ) + (y) = KONG;else if(*( * (arr_map + x ) + (y-2) = WEIZHI)*( * (arr_map + x ) + (y-2) = XW;*( * (arr_map + x ) + (y-1) = RW;*( * (arr_map + x ) + (y) = KONG;else if(*(*(arr_map + x) + (y - 1) = XI
13、ANGZI )if (*( * (arr_map + x ) + (y-2) = KONG)*( * (arr_map + x ) + (y-2) = XIANGZI;*( * (arr_map + x ) + (y-1) = REN;*( * (arr_map + x ) + (y) = KONG;else if(*( * (arr_map + x ) + (y-2) = WEIZHI)*( * (arr_map + x ) + (y-2) = XW;*( * (arr_map + x ) + (y-1) = REN;*( * (arr_map + x ) + (y) = KONG;else
14、 if(*(*(arr_map + x) + (y - 1) = KONG)*( * (arr_map + x ) + (y-1) = REN;*( * (arr_map + x ) + (y) = KONG;/人在空位ENDelse if (*( * (arr_map + x ) + (y-1) = XW | *( * (arr_map + x ) + (y-1) = XIANGZI)/人左边有箱子或箱子在最终位置if(*( * (arr_map + x ) + (y-1) = XIANGZI | *( * (arr_map + x ) + (y-1) = XW)if(*( * (arr_m
15、ap + x ) + (y-1) = XW)if (*( * (arr_map + x ) + (y-2) = KONG)*( * (arr_map + x ) + (y-2) = XIANGZI;*( * (arr_map + x ) + (y-1) = RW;*( * (arr_map + x ) + (y) = KONG;else if(*( * (arr_map + x ) + (y-2) = WEIZHI)*( * (arr_map + x ) + (y-2) = XW;*( * (arr_map + x ) + (y-1) = RW;*( * (arr_map + x ) + (y
16、) = KONG;else if(*(*(arr_map + x) + (y - 1) = XIANGZI )if (*( * (arr_map + x ) + (y-2) = KONG)*( * (arr_map + x ) + (y-2) = XIANGZI;*( * (arr_map + x ) + (y-1) = REN;*( * (arr_map + x ) + (y) = KONG;else if(*( * (arr_map + x ) + (y-2) = WEIZHI)*( * (arr_map + x ) + (y-2) = XW;*( * (arr_map + x ) + (
17、y-1) = REN;*( * (arr_map + x ) + (y) = KONG;else if(*(*(arr_map + x) + (y-1) = WEIZHI)*(*(arr_map + x) + (y-1) = RW;*(*(arr_map + x) + (y) = KONG;else if(*(*(arr_map + x) + (y-1) = KONG)*(*(arr_map + x) + (y-1) = REN;*(*(arr_map + x) + (y) = KONG;/IF(Y0)END/else if(key = d | key = D)/if (y 0)END/els
18、e if(key = w | key = W)/if (x-1 0)if(*(*(arr_map + (x) +(y) = RW)/人在最终位置if(*( * (arr_map + (x-1) ) + (y) = WEIZHI)/人上边还是最终位置*( * (arr_map + (x-1) ) + (y) = RW;*( * (arr_map + (x) ) + y) = WEIZHI;else if(*( * (arr_map + (x-1) ) + (y) = XIANGZI | *( * (arr_map + (x-1) ) + (y) = XW)if(*( * (arr_map + (
19、x-1) ) + (y) = XW)if (*( * (arr_map + (x-2) ) + (y) = KONG)*( * (arr_map + (x-2) ) + (y) = XIANGZI;*( * (arr_map + (x-1) ) + (y) = RW;*( * (arr_map + (x) ) + (y) = WEIZHI;else if(*( * (arr_map + (x-2) ) + (y) = WEIZHI)*( * (arr_map + (x-2) ) + (y) = XW;*( * (arr_map + (x-1) ) + (y) = RW;*( * (arr_ma
20、p + x ) + (y) = WEIZHI;else if(*(*(arr_map + (x-1) + (y) = XIANGZI )if (*( * (arr_map + (x-2) ) + (y) = KONG)*( * (arr_map + (x-2) ) + (y) = XIANGZI;*( * (arr_map + (x-1) ) + (y) = REN;*( * (arr_map + x ) + (y) = WEIZHI;else if(*( * (arr_map + (x-2) ) + (y) = WEIZHI)*( * (arr_map + (x-2) ) + (y) = X
21、W;*( * (arr_map + (x-1) ) + (y) = REN;*( * (arr_map + x ) + (y) = WEIZHI;else if(*(*(arr_map + (x-1) + (y) = KONG)*( * (arr_map + (x-1) ) + (y) = REN;*( * (arr_map + x ) + (y) = WEIZHI;else if (*(*(arr_map + x) +(y) = REN)/人在空位if(*( * (arr_map + (x-1) ) + (y) = WEIZHI)/人上边是最终位置*( * (arr_map + (x-1)
22、) + (y) = RW;*( * (arr_map + x ) + y) = KONG;else if(*( * (arr_map + (x-1) ) + (y) = XIANGZI | *( * (arr_map + (x-1) ) + (y) = XW)/人上边是箱子或在最终位置的箱子if(*( * (arr_map + (x-1) ) + (y) = XW)if (*( * (arr_map + (x-2) ) + (y) = KONG)*( * (arr_map + (x-2) ) + (y) = XIANGZI;*( * (arr_map + (x-1) ) + (y) = RW;
23、*( * (arr_map + x ) + (y) = KONG;else if(*( * (arr_map + (x-2) ) + (y) = WEIZHI)*( * (arr_map + (x-2) ) + (y) = XW;*( * (arr_map + (x-1) ) + (y) = RW;*( * (arr_map + x ) + (y) = KONG;else if(*(*(arr_map + (x-1) + (y) = XIANGZI )if (*( * (arr_map + (x-2) ) + (y) = KONG)*( * (arr_map + (x-2) ) + (y) =
24、 XIANGZI;*( * (arr_map + (x-1) ) + (y) = REN;*( * (arr_map + x ) + (y) = KONG;else if(*( * (arr_map + (x-2) ) + (y) = WEIZHI)*( * (arr_map + (x-2) ) + (y) = XW;*( * (arr_map + (x-1) ) + (y) = REN;*( * (arr_map + x ) + (y) = KONG;else if(*(*(arr_map + (x-1) + (y) = KONG)*( * (arr_map + (x-1) ) + (y)
25、= REN;*( * (arr_map + x ) + (y) = KONG;/人在空位ENDelse if (*( * (arr_map + (x-1) ) + (y) = XW | *( * (arr_map + (x-1) ) + (y) = XIANGZI)/人上边有箱子或箱子在最终位置if(*( * (arr_map + (x-1) ) + (y) = XIANGZI | *( * (arr_map + (x-1) ) + (y) = XW)if(*( * (arr_map + (x-1) ) + (y) = XW)if (*( * (arr_map + (x-2) ) + (y)
26、= KONG)*( * (arr_map + (x-2) ) + (y) = XIANGZI;*( * (arr_map + (x-1) ) + (y) = RW;*( * (arr_map + x ) + (y) = KONG;else if(*( * (arr_map + (x-2) ) + (y) = WEIZHI)*( * (arr_map + (x-2) ) + (y) = XW;*( * (arr_map + (x-1) ) + (y) = RW;*( * (arr_map + x ) + (y) = KONG;else if(*(*(arr_map + (x-1) + (y) =
27、 XIANGZI )if (*( * (arr_map + (x-2) ) + (y) = KONG)*( * (arr_map + (x-2) ) + (y) = XIANGZI;*( * (arr_map + (x-1) ) + (y) = REN;*( * (arr_map + x ) + (y) = KONG;else if(*( * (arr_map + (x-2) ) + (y) = WEIZHI)*( * (arr_map + (x-2) ) + (y) = XW;*( * (arr_map + (x-1) ) + (y) = REN;*( * (arr_map + x ) +
28、(y) = KONG;else if(*(*(arr_map + (x-1) + (y) = WEIZHI)*(*(arr_map + (x-1) + (y) = RW;*(*(arr_map + x) + (y) = KONG;else if(*(*(arr_map + (x-1) + (y) = KONG)*(*(arr_map + (x-1) + (y) = REN;*(*(arr_map + x) + (y) = KONG;/IF(Y0)END/else if(key = s | key = S)/if (x 0)if(*(*(arr_map + (x) +(y) = RW)/人在最终
29、位置if(*( * (arr_map + (x+1) ) + (y) = WEIZHI)/人下边还是最终位置*( * (arr_map + (x+1) ) + (y) = RW;*( * (arr_map + (x) ) + y) = WEIZHI;else if(*( * (arr_map + (x+1) ) + (y) = XIANGZI | *( * (arr_map + (x+1) ) + (y) = XW)if(*( * (arr_map + (x+1) ) + (y) = XW)if (*( * (arr_map + (x+2) ) + (y) = KONG)*( * (arr_map + (x+2) ) + (y) = XIANGZI;*( * (arr_map + (x+1) ) + (y) = RW;*( * (arr_map + (x) ) + (y) = WEIZHI;else if(*( * (arr_map + (x+2) ) + (y) = WEIZHI)*( * (arr_map + (x+2) ) + (y) = XW;*( * (arr_map + (x+1) ) + (y) = RW;*( * (arr_map + x ) + (y) =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 动物的营养需要
- 生物物种安全保护体系建设
- 皮肤科湿疹药物治疗须知
- 职场沟通的技巧与方法
- 幼师教育家精神演讲稿
- 实习员工实习报告
- 2025版前列腺癌常见症状及护理方法指南
- 手环心率测试原理
- 脑卒中宣教护理品管圈
- 脑出血患者入院宣教
- 电厂入场安全培训要求课件
- 2025年广西水利工程行业研究报告及未来行业发展趋势预测
- 2025年社区工作者招聘考试(公共基础知识)试题及答案
- 护理领域新质生产力发展
- 新质生产力核心要素-1
- 专升本时态题目及答案
- 技术方案书模板产品设计与技术实施全面描述版
- 家电清洗课件培训
- 天然药物文献汇报
- 按不同的标准分类(课件)2025-2026学年人教版二年级数学上册
- 幼儿园评估整改措施汇编
评论
0/150
提交评论