资源描述:
《推箱子(C语言小游戏代码).doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#include#include//打印地图voidDrawMap();//设置颜色voidSetColor(intnColor);//获取玩家坐标POINTGetGamerPosition();//上voidUp();//下voidDown();//左voidLeft();//右voidRight();//获取空箱子个数intGetSpareBox();//地图//0:空地;3箱子的目的地4箱子//6人7箱子与目的
2、地的集合//1:墙壁;9人在箱子的目的地intg_map[2][10][12]={{{0,0,0,0,1,1,1,0,0,0,0,0},{0,0,0,0,1,3,1,0,0,0,0,0},{0,0,0,0,1,0,1,1,1,1,1,1},{1,1,1,1,1,4,0,4,0,0,3,1},{1,3,0,0,0,4,6,1,1,1,1,1},{1,1,1,1,1,1,4,1,0,0,0,0},{0,0,0,0,0,1,0,1,0,0,0,0},{0,0,0,0,0,1,0,1,0,0,0,0},{0,0,0,0,0,1,3,
3、1,0,0,0,0},{0,0,0,0,0,1,1,1,0,0,0,0},},{{1,1,1,1,1,0,0,0,0,0,0,0},{1,0,0,0,1,0,1,1,1,0,0,0},{1,0,4,0,1,0,1,1,1,1,1,1},{1,0,4,6,1,0,1,0,0,0,3,1},{1,1,1,4,1,1,1,0,0,0,3,1},{1,1,1,0,0,0,0,0,0,0,3,1},{0,1,0,0,0,1,0,0,0,0,0,1},{0,1,0,0,0,1,0,0,0,0,0,1},{0,1,0,0,0,1,1,1,
4、1,1,1,1},{1,1,1,1,1,1,0,0,0,0,0,0},}};intg_nCurrentLevel=0;//当前管卡intmain(){//设置窗口大小system("modeconcols=26lines=11");//设置标题//SetConsoLeTitle("推箱子");charnInput=0;//输入字符while(1){//如果箱子推完了过关if(0==GetSpareBox())g_nCurrentLevel++;//清屏system("cls");//如果没有关卡,那就恭喜你成功通关。if(g
5、_nCurrentLevel>=sizeof(g_map)/sizeof(g_map[0])){printf("恭喜你已经通关!");break;}//打印地图DrawMap();nInput=_getch();switch(nInput){//往上case'w':case72:Up();break;case's':case80:Down();break;case'a':case75:Left();break;case'd':case77:Right();break;}}system("pause");return0;}//
6、打印地图voidDrawMap(){for(inti=0;i<10;i++){for(intj=0;j<12;j++){switch(g_map[g_nCurrentLevel][i][j]){case0://道路,空地printf("");break;case1:SetColor(FOREGROUND_RED
7、FOREGROUND_INTENSITY);printf("■");break;case3:SetColor(FOREGROUND_GREEN
8、FOREGROUND_INTENSITY);printf("☆");br
9、eak;case4:SetColor(FOREGROUND_RED
10、FOREGROUND_BLUE
11、FOREGROUND_INTENSITY);printf("□");break;case6:SetColor(FOREGROUND_GREEN
12、FOREGROUND_INTENSITY);printf("♂");break;case7:SetColor(FOREGROUND_RED
13、FOREGROUND_BLUE
14、FOREGROUND_INTENSITY);printf("★");break;case9:SetColor(FO
15、REGROUND_GREEN
16、FOREGROUND_INTENSITY);printf("♂");break;}}printf("");}}//设置颜色voidSetColor(intnColor){HANDLEhConsole=GetStdHandle(STD_OUTPUT_HAND