推箱子c语言编程源代码,C语言编写推箱子游戏源代码.docx

本文介绍了一个使用C语言编写的推箱子游戏的源代码,包括游戏地图的二维数组表示、屏幕绘制函数、游戏元素如墙壁、箱子、目的地的绘制以及胜利条件的判断结构。此外,还提供了初始化函数、人物移动等关键功能的实现细节。
摘要由CSDN通过智能技术生成

/* 一个C语言编写的推箱子游戏源代码 */

#include

#include

#include

#include

#include

#include

/* 定义二维数组ghouse来记录屏幕上各点的状态,

其中:0表示什么都没有,'b'表示箱子,'w'表示墙壁,'m'表示目的地,'i'表示箱子在目的地。 */

char ghouse[20][20];

/* 以下函数为直接写屏函数,很酷的函数哦!是我朋友告诉我的。 */

char far *screen=(char far* )0xb8000000;

void putchxy(int y,int x,char ch,char fc,char bc)

{

screen[(x*160)+(y<<1)+0]=ch;

screen[(x*160)+(y<<1)+1]=(bc*16)+fc;

}

/* 定义判断是否胜利的数据结构 */

typedef struct winer {

int x,y;

struct winer *p;

}winer;

/* 箱子位置的数据结构 */

typedef struct boxs {

int x,y;

struct boxs *next;

}boxs;

/* 在特定的坐标上画墙壁并用数组记录状态的函数 */

void printwall(int x,int y)

{

putchxy(y-1,x-1,219,GREEN,BLACK);

ghouse[x][y]='w';

}

/* 在特定的坐标上画箱子并用数组记录状态的函数 */

void printbox(int x,int y)

{

putchxy(y-1,x-1,10,WHITE,BLACK);

ghouse[x][y]='b';

}

/* 在特定的坐标上画目的地并用数组记录状态的函数 */

void printwhither1(int x,int y,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=qw;(*pw)=qw;qw->p=NULL;

}

}

/* 在特定的坐标上画目的地并用数组记录状态的函数 */

void printwhither(int x,int y)

{

putchxy(y-1,x-1,'*',YELLOW,BLACK);

ghouse[x][y]='m';

}

/* 在特定的坐标上画人的函数 */

void printman(int x,int y)

{

gotoxy(y,x);

_AL=02;_CX=01;_AH=0xa;

geninterrupt(0x10);

}

/* 在特定的坐标上画箱子在目的地上并用数组记录状态的函数 */

void printboxin(int x,int y)

{

putchxy(y-1,x-1,10,YELLOW,BLACK);

ghouse[x][y]='i';

}

/* 初始化函数,初始化数组和屏幕 */

void init()

{

int i,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("Welcome to come box world!");

gotoxy(40,6);

printf("Press up,down,left,right to play.");

gotoxy(40,8);

printf("Press Esc to quit it.");

gotoxy(40,10);

printf("Press space to reset the game.");

gotoxy(40

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值