用C语言编写推箱子游戏
本文实例为大家分享了C语言推箱子游戏的具体实现代码,供大家参考,具体内容如下
#include#include #include #include //行和列 #defineROW10 #defineCOL11 /*runthisprogramusingtheconsolepauseroraddyourowngetch,system("pause")orinputloop*/ /** * * */ //地图 charmap[ROW][COL]={ "##########",//0 "#####",//1 "#####",//2 "##AX###",//3 "#####",//4 "######",//5 "###",//6 "#####",//7 "###",//8 "##########"//9 //A:人,X:箱子 }; //打印地图 voidshowMap(); //接收小人的方向 charenterDirection(); //小人向上移动的方法 voidmoveToUp(); //小人向下移动的方法 voidmoveToDown(); //小人向右移动的方法 voidmoveToRight(); //小人向左移动的方法 voidmoveToLeft(); //当前小人的坐标 intcurrentPersonRow=3; intcurrentPersonCol=2; //当前箱子的坐标 intcurrentBoxRow=3; intcurrentBoxCol=3; intmain(intargc,char*argv[]){ //system("clear"); printf("点击回车键开始游戏^_^\n\n"); //1代表运行0停止 intflag=1; while(flag==1){ //显示地图 showMap(); //接收小人的方向 chardir=enterDirection(); switch(dir){ //小人向上移动 case'w': case'W': moveToUp(); break; //小人向下移动 case's': case'S': moveToDown(); break; //小人向右移动 case'd': case'D': moveToRight(); break; //小人向左移动 case'a': case'A': moveToLeft(); break; //停止运行 case'q': case'Q': printf("你的智商真低!T_T\n"); flag=0; break; } showMap(); if(currentBoxRow==8&¤tBoxCol==9){ printf("你的智商真高^_^!!!"); flag=0; } } } /* 方法的实现 */ //打印地图 voidshowMap(){ inti; for(i=0;i |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。