推箱子游戏
/* 这是彭搏同学的推箱子游戏,大家试试玩,谁有更好的Idea? */
#include"stdio.h"
#include"bios.h"
#define LEFT 75
#define RIGHT 77
#define UPPER 72
#define DOWN 80
#define ESC 27
struct Boxss /*定义箱子结构体,其中包含坐标属性*/
{
int x,y;
};
union keyboard /*定义读取键盘码的共用体类型*/
{
unsigned int iKeyInfo;
char chKeyBit[2];
};
int fnGetKey(void) /*定义读取键盘码的函数*/
{
union keyboard uniKey1; /*定义读取键盘码的共用体变量*/
while(bioskey(1)==0); /*检测用户是否按键*/
uniKey1.iKeyInfo=bioskey(0); /*读取按键信息*/
return(uniKey1.chKeyBit[0]==0?uniKey1.chKeyBit[1]:uniKey1.chKeyBit[0]); /*返回ASCII码或扩充码*/
}
void main()
{
int iKey,x=11,y=6,tx=11,ty=6; /*x,y为人物移动后坐标,tx,ty为人物移动前坐标*/
struct Boxss Box[4]; /*定义箱子数量*/
int chMap[10][10]={ /*用二维数组定义地图*/
{0,0,0,0,0,0,0,0,0,0}, /*0表示墙1表示路2表示目标*/
{0,1,0,0,0,0,1,1,1,0},
{0,1,0,2,0,0,1,0,1,0},
{0,1,0,1,0,0,1,0,1,0},
{0,1,1,1,0,0,1,0,1,0},
{0,1,0,0,0,0,1,0,1,0},
{0,1,1,1,1,1,1,0,1,0},
{0,1,0,1,0,0,0,0,2,0},
{0,2,0,1,1,1,1,2,0,0},
{0,0,0,0,0,0,0,0,0,0},
};
int i,j;
Box[0].x=13; /*定义箱子的坐标属性*/
Box[1].x=11;
Box[2].x=14;
Box[3].x=18;
Box[0].y=8;
Box[1].y=7;
Box[2].y=13;
Box[3].y=7;
while(1) /*反复进行求移动的坐标运算*/
{
for(i=0;i<10;i++) /*输出新地图(刷新地图)*/
{
gotoxy(10,5+i);
for(j=0;j<10;j++)
{
if(chMap[i][j]==0)
printf("#");
if(chMap[i][j]==1)
printf(" ");
if(chMap[i][j]==2)
printf("X");
}
}
j=0; /*判断是否所有箱子都在目标坐
相关新闻>>
- 发表评论
-
- 最新评论 更多>>