资源描述:
《C语言编写的推箱子游戏源代码》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、/*一个C语言编写的推箱子游戏源代码*/#include#include#include#include#include#include/*定义二维数组ghouse来记录屏幕上各点的状态,其中:0表示什么都没有,'b'表示箱子,'w'表示墙壁,'m'表示目的地,'i'表示箱子在目的地。*/charghouse[20][20];/*以下函数为直接写屏函数,很酷的函数哦!是我朋友告诉我的。*/charf
2、ar*screen=(charfar*)0xb8000000;voidputchxy(inty,intx,charch,charfc,charbc){screen[(x*160)+(y<<1)+0]=ch;screen[(x*160)+(y<<1)+1]=(bc*16)+fc;}/*定义判断是否胜利的数据结构*/typedefstructwiner{intx,y;structwiner*p;}winer;/*箱子位置的数据结构*/typedefstructboxs{intx,y;structboxs
3、*next;}boxs;/*在特定的坐标上画墙壁并用数组记录状态的函数*/voidprintwall(intx,inty){putchxy(y-1,x-1,219,GREEN,BLACK);ghouse[x][y]='w';}/*在特定的坐标上画箱子并用数组记录状态的函数*/voidprintbox(intx,inty){putchxy(y-1,x-1,10,WHITE,BLACK);ghouse[x][y]='b';}/*在特定的坐标上画目的地并用数组记录状态的函数*/voidprintwhith
4、er1(intx,inty,winer**win,winer**pw){winer*qw;putchxy(y-1,x-1,'*',YELLOW,BLACK);ghouse[x][y]='m';if(*win==NULL){*win=*pw=qw=(winer*)malloc(sizeof(winer));(*pw)->x=x;(*pw)->y=y;(*pw)->p=NULL;}else{qw=(winer*)malloc(sizeof(winer));qw->x=x;qw->y=y;(*pw)->p
5、=qw;(*pw)=qw;qw->p=NULL;}}/*在特定的坐标上画目的地并用数组记录状态的函数*/voidprintwhither(intx,inty){putchxy(y-1,x-1,'*',YELLOW,BLACK);ghouse[x][y]='m';}/*在特定的坐标上画人的函数*/voidprintman(intx,inty){gotoxy(y,x);_AL=02;_CX=01;_AH=0xa;geninterrupt(0x10);}/*在特定的坐标上画箱子在目的地上并用数组记录状态的
6、函数*/voidprintboxin(intx,inty){putchxy(y-1,x-1,10,YELLOW,BLACK);ghouse[x][y]='i';}/*初始化函数,初始化数组和屏幕*/voidinit(){inti,j;for(i=0;i<20;i++)for(j=0;j<20;j++)ghouse[i][j]=0;_AL=3;_AH=0;geninterrupt(0x10);gotoxy(40,4);printf("Welcometocomeboxworld!");gotoxy(40
7、,6);printf("Pressup,down,left,righttoplay.");gotoxy(40,8);printf("PressEsctoquitit.");gotoxy(40,10);printf("Pressspacetoresetthegame.");gotoxy(40,12);printf("Producer1:yangxianxiu.");gotoxy(40,14);printf("Producer2:zhouxunan.");gotoxy(40,16);printf("Pr
8、oducer3:fancuihua.");gotoxy(40,18);printf("Producer4:dingxiaolin.");gotoxy(40,20);printf("Mar.23th2011.");}/*第一关的图象初始化*/winer*inithouse1(){intx,y;winer*win=NULL,*pw;for(x=1,y=5;y<=9;y++)printwall(x+4,y+10);for(y=5,x=2;x<=5;x++)printwall