当前位置:首页 » 编程语言 » 推箱子c语言代码

推箱子c语言代码

发布时间: 2023-03-23 03:00:35

⑴ 如何用c语言编写控制台小游戏

//C语言实例:推箱子小游戏
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
//行和列
#defineROW10
#defineCOL11
/*,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("点击回车键开始游戏^_^ ");
//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 ");
flag=0;
break;
}
showMap();
if(currentBoxRow==8&&currentBoxCol==9){
printf("你的智商真高^_^!!!");
flag=0;
}

}

}
/*
方法的实现
*/


//打印地图
voidshowMap(){
inti;
for(i=0;i<ROW;i++){
printf("%s ",map[i]);
}
printf(" ");
printf("W:上,S:下,A:左,D:右。Q:退出");
printf(" ");
}
//接收小人的方向
charenterDirection(){
//清除SCANF中的缓冲区
rewind(stdin);
chardir;
dir=getch();
//scanf("%c",&dir);
returndir;
}
//小人向上移动的方法
voidmoveToUp(){
//小人的下一个坐标
intnextPersonCol=currentPersonCol;
intnextPersonRow=currentPersonRow-1;
//箱子的下一个坐标
intnextBoxRow=currentBoxRow-1;
intnextBoxCol=currentBoxCol;

//如果小人的下一个坐标是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一个坐标是墙
if(map[nextPersonRow][nextPersonCol]=='#'){
//什么也不做
}
//如果小人的下一个坐标是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){

map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';

map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';


currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}
//小人向下移动的方法
voidmoveToDown(){
//小人的下一个坐标
intnextPersonCol=currentPersonCol;
intnextPersonRow=currentPersonRow+1;
//箱子的下一个坐标
intnextBoxRow=currentBoxRow+1;
intnextBoxCol=currentBoxCol;

//如果小人的下一个坐标是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一个坐标是墙
if(map[nextPersonRow][nextPersonCol]=='#'){
//什么也不做
}
//如果小人的下一个坐标是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){

map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';

map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';

currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}
//小人向右移动的方法
voidmoveToRight(){
//小人的下一个坐标
intnextPersonCol=currentPersonCol+1;
intnextPersonRow=currentPersonRow;
//箱子的下一个坐标
intnextBoxRow=currentBoxRow;
intnextBoxCol=currentBoxCol+1;

//如果小人的下一个坐标是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一个坐标是墙
if(map[nextPersonRow][nextPersonCol]=='#'){
//什么也不做
}
//如果小人的下一个坐标是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){

map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';

map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';

currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}
//小人向左移动的方法
voidmoveToLeft(){
//小人的下一个坐标
intnextPersonCol=currentPersonCol-1;
intnextPersonRow=currentPersonRow;
//箱子的下一个坐标
intnextBoxRow=currentBoxRow;
intnextBoxCol=currentBoxCol-1;

//如果小人的下一个坐标是路
if(map[nextPersonRow][nextPersonCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';
currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
}
//如果小人的下一个坐标是墙
if(map[nextPersonRow][nextPersonCol]=='#'){
//什么也不做
}
//如果小人的下一个坐标是箱子
if(map[nextPersonRow][nextPersonCol]=='X'){
if(map[nextBoxRow][nextBoxCol]==''){
map[nextPersonRow][nextPersonCol]='A';
map[currentPersonRow][currentPersonCol]='';

map[nextBoxRow][nextBoxCol]='X';
map[currentBoxRow][currentBoxCol]='A';

currentPersonRow=nextPersonRow;
currentPersonCol=nextPersonCol;
currentBoxRow=nextBoxRow;
currentBoxCol=nextBoxCol;
}
}
}

⑵ 谁有能在vc++6.0上运行的c语言小游戏代码

最基础的贪吃蛇的代码

#include<stdio.h>
#include<windows.h>//基本型态定义。支援型仔明态定义函数。使用者界面函数 图形装置界面函数。
#include<conio.h> //用户通过按键盘产生的对应操作 (控制台)
#include<stdlib.h>
#include<time.h> //日期和时间头文件
#define LEN 30
#define WID 25
int Snake[LEN][WID] = {0}; //数组的元素代表蛇的各个部位
char Sna_Hea_Dir = 'a';//记录蛇头的移动方向
int Sna_Hea_X, Sna_Hea_Y;//记录蛇头的位置
int Snake_Len = 3;//记录蛇的长度
clock_t Now_Time;//记录当前时间,以便自动移动
int Wait_Time ;//记录自动移动的时间间隔
int Eat_Apple = 1;//吃到苹果表示为1
int Level ;
int All_Score = -1;
int Apple_Num = -1;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //获取标准输出的句柄 <windows.h>
//句柄 :标志应用程序中的不同对象和同类对象中的不同的实例 方便操控,
void gotoxy(int x, int y)//设置光标位置
{
COORD pos = {x,y}; //定义一个字符在控制台屏幕上的坐标POS

SetConsoleCursorPosition(hConsole, pos); //定位光标位置的函数<windows.h>

}

void Hide_Cursor()//隐藏光标 固定函数
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(hConsole, &cursor_info);
}

void SetColor(int color)//设置颜色
{
SetConsoleTextAttribute(hConsole, color);
//是API设置字体颜色和背景色的函数 格式:SetConsoleTextAttribute(句柄,颜色);
}

void Print_Snake()//打印蛇头和蛇的脖子和蛇尾
{
int iy, ix, color;
for(iy = 0; iy < WID; ++iy)
for(ix = 0; ix < LEN; ++ix)
{

if(Snake[ix][iy] == 1)//蛇头
{
SetColor(0xf); //oxf代庆搏表分配的内存地址 setcolor:34行自定义设置颜色的函数
gotoxy(ix*2, iy);
printf("※");
}
if(Snake[ix][iy] == 2)//蛇的脖子
{
color = rand()%15 + 1; //rand()函数是产生随机念差告数的一个随机函数。C语言里还有 srand()函数等。
//头文件:stdlib.h
if(color == 14)
color -= rand() % 13 + 1; //变色
SetColor(color);
gotoxy(ix*2, iy);
printf("■");
}
if(Snake[ix][iy] == Snake_Len)
{
gotoxy(ix*2, iy);
SetColor(0xe);
printf("≈");
}
}
}

void Clear_Snake()//擦除贪吃蛇
{
int iy, ix;
for(iy = 0; iy < WID; ++iy)
for(ix = 0; ix < LEN; ++ix)
{
gotoxy(ix*2, iy);
if(Snake[ix][iy] == Snake_Len)
printf(" ");
}
}

void Rand_Apple()//随机产生苹果
{
int ix, iy;

do
{
ix = rand() % LEN;
iy = rand() % WID;
}while(Snake[ix][iy]);

Snake[ix][iy] = -1;
gotoxy(ix*2, iy);
printf("⊙");
Eat_Apple = 0;
}

void Game_Over()//蛇死掉了
{
gotoxy(30, 10);
printf("Game Over");
Sleep(3000);
system("pause > nul");
exit(0);
}

void Move_Snake()//让蛇动起来
{
int ix, iy;

for(ix = 0; ix < LEN; ++ix)//先标记蛇头
for(iy = 0; iy < WID; ++iy)
if(Snake[ix][iy] == 1)
{
switch(Sna_Hea_Dir)//根据新的蛇头方向标志蛇头
{
case 'w':
if(iy == 0)
Game_Over();
else
Sna_Hea_Y = iy - 1;
Sna_Hea_X = ix;

break;
case 's':
if(iy == (WID -1))
Game_Over();
else
Sna_Hea_Y = iy + 1;
Sna_Hea_X = ix;

break;
case 'a':
if(ix == 0)
Game_Over();
else
Sna_Hea_X = ix - 1;
Sna_Hea_Y = iy;

break;
case 'd':
if(ix == (LEN - 1))
Game_Over();
else
Sna_Hea_X = ix + 1;
Sna_Hea_Y = iy;

break;
default:
break;
}
}

if(Snake[Sna_Hea_X][Sna_Hea_Y]!=1&&Snake[Sna_Hea_X][Sna_Hea_Y]!=0&&Snake[Sna_Hea_X][Sna_Hea_Y]!=-1)
Game_Over();

if(Snake[Sna_Hea_X][Sna_Hea_Y] < 0)//吃到苹果
{
++Snake_Len;
Eat_Apple = 1;
}
for(ix = 0; ix < LEN; ++ix)//处理蛇尾
for(iy = 0; iy < WID; ++iy)
{
if(Snake[ix][iy] > 0)
{
if(Snake[ix][iy] != Snake_Len)
Snake[ix][iy] += 1;
else
Snake[ix][iy] = 0;
}
}

Snake[Sna_Hea_X][Sna_Hea_Y] = 1;//处理蛇头
}

void Get_Input()//控制蛇的移动方向
{
if(kbhit())
{
switch(getch())
{
case 87:

Sna_Hea_Dir = 'w';
break;
case 83:

Sna_Hea_Dir = 's';
break;
case 65:

Sna_Hea_Dir = 'a';
break;
case 68:

Sna_Hea_Dir = 'd';
break;
default:
break;
}
}

if(clock() - Now_Time >= Wait_Time)//蛇到时间自动行走
{
Clear_Snake();
Move_Snake();
Print_Snake();
Now_Time = clock();
}
}

void Init()//初始化
{
system("title 贪吃毛毛蛇");
system("mode con: cols=80 lines=25");
Hide_Cursor();

gotoxy(61, 4);
printf("You Score:");
gotoxy(61, 6);
printf("You Level:");
gotoxy(61, 8);
printf("The Lenght:");
gotoxy(61, 10);
printf("The Speed:");
gotoxy(61, 12);
printf("Apple Num:");

int i;
for(i = 0; i < Snake_Len; ++i)//生成蛇
Snake[10+i][15] = i+1;

int iy, ix;//打印蛇
for(iy = 0; iy < WID; ++iy)
for(ix = 0; ix < LEN; ++ix)
{
if(Snake[ix][iy])
{
SetColor(Snake[ix][iy]);
gotoxy(ix*2, iy);
printf("■");
}
}
}

void Pri_News()//打印信息
{
SetColor(0xe);
gotoxy(73,4);
All_Score += Level;
printf("%3d", All_Score);
gotoxy(73, 6);
printf("%3d", Level);
gotoxy(73, 8);
printf("%3d",Snake_Len);
gotoxy(73, 10);
printf("0.%3ds", Wait_Time/10);
gotoxy(73, 12);
printf("%d", Apple_Num);
}

void Lev_Sys()//等级系统
{
if(((Apple_Num-1) / 10) == Level)
{
++Level;
if(Wait_Time > 50)
Wait_Time -= 50;
else
if(Wait_Time > 10)
Wait_Time -= 10;
else
Wait_Time -= 1;
}
}

int main(void)
{
Init();
srand((unsigned)time(NULL));//设置随机数的种子
Now_Time = clock();
int speed1=1000,speed2,a;
printf("\n");
printf("请输入你想要的速度\n");
scanf("%d",&speed2);
Level=1;
Wait_Time=speed1-speed2;
printf("请输入你想要的苹果数\n");
scanf("%d",&a);

while(a--)
Rand_Apple();
while(1)
{
if(Eat_Apple)
{
++Apple_Num;
Rand_Apple();
Lev_Sys();
Pri_News();
}
Get_Input();
Sleep(10);
}
return 0;
}

⑶ 求C语言小游戏源程序

新手要方便写代码,可以收藏下面几个自编函数:

  1. gtxy (6, 3) //光标定位于窗口的第6列,第3行处(准备输出,行与列都是从0算起)

  2. Color (4, 0) //设置为红字配黑底 如 Color (10, 0)则是淡绿字配黑底

  3. yinc (1,0) //隐藏光标(第二个参数设为0就隐藏,没有光标闪烁,yinc代表隐藏)

  4. kou(80,25) //设定窗口缓冲区大小为80列,25行

    下面几个是库函数,不需自己编写,只要用#include包含就可以使用。

  5. SetConsoleTitle("俄罗斯方块"); //设置窗口左上角标题栏处出现"俄罗斯方块"5个字

  6. srand( (unsigned) time(NULL) ); //初始化随机数发生器

  7. n= rand( ) % 20; //产生随机数0-19中的一个. 如 rand( )%5 就产生0-4中的一个数

    SetConsoleTitle( )函数在<windows.h>里,srand( )函数与rand( )函数要配合用,

    就是同时要用,在<stdlib.h>里。如果 rand( )%10+1 就产生1-10之中的一个数。

  8. Sleep(300); //延时300毫秒(就是程序暂停300毫秒后继续运行)

  9. system("cls"); //清屏(把窗口里的内容全部清除,光标定于(0,0)位置处)

    这两个函数都在<windows.h>里。开头4个自编函数 编写如下:

void gtxy (int x, int y) //控制光标位置的函数

{ COORD pos;

pos.X = x;

pos.Y = y;

SetConsoleCursorPosition ( GetStdHandle (STD_OUTPUT_HANDLE), pos );

}

void Color (short ForeColor= 7, short BackGroundColor= 0) //设定颜色的函数

{ HANDLE hl = GetStdHandle ( STD_OUTPUT_HANDLE );

SetConsoleTextAttribute ( hl, ForeColor + BackGroundColor * 0x10 );

}

声明时原型可写 void Color (short x, short y);

void yinc (int x,int y) //隐藏光标的函数

{ CONSOLE_CURSOR_INFO gb={ x , y }; //gb代表光标

SetConsoleCursorInfo ( GetStdHandle(STD_OUTPUT_HANDLE), &gb );

}

void kou(int w,int h) //设置窗口大小的函数

{HANDLE hl=GetStdHandle ( STD_OUTPUT_HANDLE ) ;

COORD size={ w , h };

SetConsoleScreenBufferSize( hl , size );

SMALL_RECT rc={ 0, 0, w, h };

SetConsoleWindowInfo( hl, 1, &rc );

}

最后这个函数,参数w是宽h是高。里边5行中第一行定义了句柄型变量hl,并给它赋值。

第二行定义了坐标型结构体变量size,它的取值决定了缓冲区的大小。第三行就是使用

size的值设置好缓冲区大小。第四行定义了变量rc,它的值决定当前窗口显示的位置与

大小(不得超过缓冲区的大小)。前两个0,0是从缓冲区左上角0列0行位置处开始,后两

个参数可以小于w和h.比如rc={0,0,w-10,h-5}; 最后一行使用rc的值设置好窗口,中间

那个参数要为" 1 "或写“ true ”才有效。

⑷ 简单的搬运工C语言代码

程序在tc3.0下编译通过. 回车键选关,我只做了两关, r键重新开始 p键悔步,只能悔五步啊.不过你可以改#define STEPMAX的值 #define MAX 2 /*游戏中总关数*/#define STARTX 180#define STARTY 80#define ...
程序在tc3.0下编译通过. 回车键

选关,我只做了两关, r键重新开始

p键悔步,只能悔五步啊.不过你可以

改#define STEPMAX的值

#define MAX 2 /*游戏中总关数*/
#define STARTX 180
#define STARTY 80
#define BKCOLOR BLACK
#define MANCOLOR RED
#define OBJECTCOLOR YELLOW
#define TIMEINT 2
#define STARNUM 300
#define STEPMAX 5
#include<sing.h>
#include<bios.h>档芹
#include<sio.h>
#include<dos.h>
#include<graphics.h>
#include<conio.h>
#include<time.h>
#include<slib.h>
#include<sio.h>
#define Key_R 0x1372
#define Key_Up 0x4800
#define Key_Enter 0x1c0d
#define Key_Down 0x5000
#define Key_P 0x1970
#define Key_Esc 0x11b
#define Key_Right 0x4d00
#define Key_Left 0x4b00

typedef suct star
{
int x;
int y;
int c;
}Star;
Star s;

typedef suct record
{
char name;
int second;
suct time t;
suct date d;
}Record;
Record r;

typedef suct c
{
int x;
int y;
}Add;

typedef suct a
{
int x;
int y;
}Player;
Player p;

char name; /*进入游戏时记录玩家的姓名*/
time_t t1,t2; /*游戏结束时的时间*/
int Ide; /*开始进入游戏时,选择菜单时返的功能号(1,2,3)*/
int MissionNum; /*玩家正在玩的关数*/橘蠢带
int BoxNum; /*目的地的个数*/
int Key; /*玩家按键*/
int map; /*地图.(空=0),(人=1),(箱子=2),(墙=3),(目的地圆芦=4),(人 目的地=5),(箱子 目的地=6)*/
int StepNum;
int DirectionKey; /*用来表示方向键最后一次按键*/
int BoxMove;
int Step;

/*函数定义*/
void InputName();
void Init();
void MainMenu();
void JudgeRecord();
void WriteRecord();
void JudgeIde();
void DrawMenu(int );
void Game();
void InitMission(int );
void NextMission();
void InitPic(int ,int ,int );
int Move(Add );
void DrawWall(int ,int );
void DrawBack(int ,int );
void DrawBox(int ,int );
void DrawObject(int ,int );
void DrawMan(int ,int );
void DrawStar();
int JudgeWin();
void InitMission1();
void InitMission2();
int TimeCome();
void ChangeStar();
void InputName();
void ViewRecords();
void DeleteRecords();
void RegisterStep();
void ReverselyMove();
void MoveBack(Add );

void main()
{
InputName();
Init(); /*驱动显卡*/
srand(time(&t1));
MainMenu(); /*画开始菜单(1.start game 2.view records 3.delete records 4.exit game)*/
}

void InputName()
{
char c;
clrscr();
do
{
printf("\n\nPlease input your name:");
scanf("%s",name);
printf("Are you sure the name right(Y/N):");
do
{
c=getch();
}while(c!='Y'&&c!='y'&&c!='N'&&c!='n');
}while(c!='Y'&&c!='y');
}
void Init()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
}

void MainMenu()
{
setbkcolor(BKCOLOR);
cleardevice();
/*DrawStar(); /*画开始菜单的背景画面*/
DrawStar();
Ide=0,Key=0;
DrawMenu(Ide);
do
{
if(bioskey(1)) /*有键按下则处理按键*/
{
Key=bioskey(0);
switch(Key)
{
case Key_Down: {Ide ;Ide=Ide%4;DrawMenu(Ide);break;}
case Key_Up: {Ide--;Ide=(Ide 4)%4;DrawMenu(Ide);break;}
}
}
else {if(TimeCome()) ChangeStar();} /*改变背景*/
}while(Key!=Key_Enter);
JudgeIde(); /*根据Ide运行不同的程序*/
}

void JudgeIde()
{
switch(Ide)
{
case 0:Game();break;
case 1:{ViewRecords();bioskey(0);MainMenu();break;}
case 2:{DeleteRecords();ViewRecords();bioskey(0);MainMenu();break;}
case 3:exit(0);
}
}

void Game()
{
int i,j,flag;
Add ad;
MissionNum=0;
NextMission();
do
{
flag=0;
Key=bioskey(0);
switch(Key)
{
case Key_Enter:{NextMission();time(&t1);break;}
case Key_Up:{ad.x=-1;ad.y=0;flag=1;DirectionKey=Key;break;}
case Key_Down:{ad.x=1;ad.y=0;flag=1;DirectionKey=Key;break;}
case Key_Left:{ad.x=0;ad.y=-1;flag=1;DirectionKey=Key;break;}
case Key_Right:{ad.x=0;ad.y=1;flag=1;DirectionKey=Key;break;}
case Key_R:{MissionNum--;NextMission();break;}
case Key_Esc:{MainMenu();break;}
case Key_P:{ReverselyMove();break;}
}
if(flag==1)
{if(Move(ad)) {RegisterStep(); if(JudgeWin()) {JudgeRecord();NextMission();}}}
}while(1);
}

void InitMission(int n)
{
int i,j;
for(i=0;i<10;i )
for(j=0;j<10;j )
map=0;
switch(n)
{
case 1:InitMission1();break; /*第一关*/
case 2:InitMission2();break; /*第二关*/
}
}

void InitPic(int n,int i,int j)
{
switch(n)
{
case 0:DrawBack(i,j);break;
case 1:DrawMan(i,j);break;
case 2:DrawBo

x(i,j);break;
case 3:DrawWall(i,j);break;
case 4:DrawObject(i,j);break;
case 5:DrawMan(i,j);break;
case 6:DrawBox(i,j);break;
}
}

void NextMission()
{
int i,j;
if(MissionNum 1>MAX) MissionNum=1;
else MissionNum ;
InitMission(MissionNum);
setbkcolor(BKCOLOR);
cleardevice();
for(i=0;i<10;i )
for(j=0;j<10;j )
InitPic(map,i,j);
switch(MissionNum)
{
case 1:outtextxy(200,230,"Mission 1");break;
case 2:outtextxy(200,230,"Mission 2");break;
}
time(&t1);
for(i=0;i<STEPMAX;i )
{Step=BoxMove=0;}
StepNum=0;
}

int Move(Add a)
{
int flag;
int i=StepNum%STEPMAX;
switch(map) /*看下一位置为什么*/
{
case 0:{map-=1;InitPic(map,p.x,p.y);
p.x=p.x a.x;p.y=p.y a.y;
map =1;InitPic(map,p.x,p.y);flag=1;break;}
case 2:{if(map==0||map==4)
{map-=1;map=1;map =2;
InitPic(map,p.x,p.y);
InitPic(map,p.x a.x,p.y a.y);
InitPic(map,p.x 2*a.x,p.y 2*a.y);
p.x=p.x a.x;p.y=p.y a.y;flag=1;BoxMove=1;}
else flag=0;
break;}
case 3:flag=0;break;
case 4:{map-=1;InitPic(map,p.x,p.y);
p.x=p.x a.x;p.y=p.y a.y;
map =1;InitPic(map,p.x,p.y);flag=1;break;}
case 6:{if(map==0||map==4)
{map-=1;map=5;map =2;
InitPic(map,p.x,p.y);
InitPic(map,p.x a.x,p.y a.y);
InitPic(map,p.x 2*a.x,p.y 2*a.y);
p.x=p.x a.x;p.y=p.y a.y;flag=1;BoxMove=1;}
else flag=0;
break;}
}
return flag;
}

void DrawWall(int i,int j)
{
DrawBack(i,j);
setfillstyle(9,1);
bar(STARTX 20*j-9,STARTY 20*i-9,STARTX 20*j 9,STARTY 20*i 9);
}

void DrawMan(int i,int j)
{
DrawBack(i,j);
setcolor(MANCOLOR);
circle(STARTX 20*j,STARTY 20*i,9);
arc(STARTX 20*j-3,STARTY 20*i-2,20,160,3);
arc(STARTX 20*j 4,STARTY 20*i-2,20,160,3);
arc(STARTX 20*j,STARTY 20*i-2,220,320,7);
}

void DrawBack(int i,int j)
{
setfillstyle(1,BKCOLOR);
bar(STARTX 20*j-9,STARTY 20*i-9,STARTX 20*j 9,STARTY 20*i 9);
}

void DrawObject(int i,int j)
{
DrawBack(i,j);
setcolor(OBJECTCOLOR);
line(STARTX 20*j-9,STARTY 20*i,STARTX 20*j 9,STARTY 20*i);
line(STARTX 20*j-9,STARTY 20*i-9,STARTX 20*j 9,STARTY 20*i 9);
line(STARTX 20*j-9,STARTY 20*i 9,STARTX 20*j 9,STARTY 20*i-9);
}

void DrawBox(int i,int j)
{
DrawBack(i,j);
setfillstyle(9,3);
bar(STARTX 20*j-9,STARTY 20*i-9,STARTX 20*j 9,STARTY 20*i 9);
}

void DrawMenu(int j)
{
int n;
char *s={"1.Start Game","2.View Records","3.Delete Records","4.Exit Game"};
settextstyle(0,0,1);
setcolor(GREEN);
for(n=0;n<4;n )
outtextxy(250,170 n*20,s);
setcolor(RED);
outtextxy(250,170 j*20,s);
}

void DrawStar()
{
int w,h,i,dotx,doty,color,maxcolor;
w=getmaxx();
h=getmaxy();
maxcolor=getmaxcolor();
for(i=0;i<STARNUM;i )
{
s.x=1 random(w-1);
s.y=1 random(h-1);
s.c=random(maxcolor);
putpixel(s.x,s.y,s.c);
}
}
void ChangeStar()
{
int i,maxcolor;
maxcolor=getmaxcolor();
for(i=0;i<STARNUM;i )
{
s.c=random(maxcolor);
putpixel(s.x,s.y,s.c);
}
}

int TimeCome()
{

static long tm, old;
tm=biostime(0,tm);
if(tm-old<TIMEINT) return 0;
else
{
old=tm; return 1;
}
}

int JudgeWin()
{
int n=0,i,j;
for(i=0;i<10;i )
for(j=0;j<10;j )
if(map==6) n ;
if(n==BoxNum) return 1;
else return 0;
}

void InitMission1() /*第九关*/
{
int i,j;
for(i=0;i<10;i )
for(j=0;j<10;j )
map=0;
for(i=0;i<=5;i )
map=3;
for(i=5;i<=7;i )
{map=map=3;}
for(i=1;i<=4;i )
{map=map=map=3;}
map=map=map=3;
for(i=2;i<=4;i )
map=2;
map=map=2;
for(i=2;i<=3;i )
{map=map=4;}
map=4;
p.x=3;p.y=5;
map=1;
BoxNum=5;
}

void InitMission2()
{
int i,j;
for(i=0;i<10;i )
for(j=0;j<10;j )
map=0;
for(i=1;i<=5;i )
{map=map=3;}
for(i=2;i<=4;i )
{map=map=map=map=3;}
map=map=map=map=map=map=3;
map=map=map=map=2;
map=map=map=map=4;
p.x=1;p.y=3;
map=1;
BoxNum=4;
}

void ViewRecords()
{
FILE *fp;
int i;
setbkcolor(BKCOLOR);
cleardevice();
if((fp=fopen("record","r"))==NULL)
{
printf("\nerror on open file!");
getch();
exit(1);
}
gotoxy(1,1);
printf("\n\t\t\tRecord Information\n");
printf("Record-holder Achievement(s)\t Time(h:m:s)\t\tDate(y/m/d)");
for(i=0;i<MAX;i )
{fseek(fp,i*sizeof(Record),0);
fread(&r,sizeof(Record),1,fp);
printf("\n%-10s\t%d\t\t d:d:d\t\td/d/d",r.name,r.second,r.t.ti_hour,r.t.ti_min,r.t.ti_sec,r.d.da_year,r.d.da_mon,r.d.da_day);}
fclose(fp);
gotoxy(10,25);
printf("Press any key to return mainmenu...");
}

void DeleteRecords()
{
int i;
FILE *fp;
fp=fopen("record","w");
for(i=0;i<MAX;i )
{
scpy(r.name,"nameless");
r.second=0;
gettime(&r.t);
geate(&r.d);
}
for(i=0;i<MAX;i )
fwrite(&r,sizeof(Record),1,fp);
fclose(fp);
}

void JudgeRecord()
{
int i=MissionNum-1;
time(&t2);
if(r.second==0||difftime(t2,t1)<r.second)
{
gotoxy(10,3);printf("\t\tYou have broken the record");
r.second=difftime(t2,t1);
scpy(r.name,name);
gettime(&r.t);
geate(&r.d);
WriteRecord();
}
else
{gotoxy(10,3);printf("\t\tYou have pass this mission");}
gotoxy(10,4);
printf("\t\tpress any key continue...");
getch();
getch();
}

void WriteRecord()
{
FILE *fp;
int i=MissionNum-1;
fp=fopen("record","rt ");
fseek(fp,i*sizeof(Record),0);
fwrite(&r,sizeof(Record),1,fp);
fclose(fp);
}

void RegisterStep()
{
int i;
StepNum ;
i=(StepNum-1)%STEPMAX;
Step=DirectionKey;
}

void ReverselyMove()
{
int i;
Add ad;
i=(StepNum-1)%STEPMAX;
if(Step==0) return;
else
{
switch(Step)
{
case Key_Up:{ad.x=1;ad.y=0;MoveBack(ad);break;}
case Key_Down:{ad.x=-1;ad.y=0;MoveBack(ad);break;}
case Key_Left:{ad.x=0;ad.y=1;MoveBack(ad);break;}
case Key_Right:{ad.x=0;ad.y=-1;MoveBack(ad);break;}
}
StepNum--;Step=0;BoxMove=0;
}
}

void MoveBack(Add a) /*一定可以移动*/
{
int i=(StepNum-1)%STEPMAX;
if(BoxMove==0)
{
map-=1;InitPic(map,p.x,p.y);
p.x=p.x a.x;p.y=p.y a.y;
map =1;InitPic(map,p.x,p.y);
}
else if(BoxMove==1)
{
map-=2;InitPic(map,p.x-a.x,p.y-a.y);
map =1;InitPic(map,p.x,p.y);
p.x=p.x a.x;p.y=p.y a.y;
map =1;InitPic(map,p.x,p.y);
}
}

点这里下载

p=map=map=4;
p.x=1;p.y=3;
map=1;
BoxNum=4;
}

void ViewRecords()
{
FILE *fp;
int i;
setbkcolor(BKCOLOR);
cleardevice();
if((fp=fopen("record","r"))==NULL)
{
printf("\nerror on open file!");
getch();
exit(1);
}
gotoxy(1,1);
printf("\n\t\t\tRecord Information\n");
printf("Record-holder Achievement(s)\t Time(h:m:s)\t\tDate(y/m/d)");
for(i=0;i<MAX;i )
{fseek(fp,i*sizeof(Record),0);
fread(&r,sizeof(Record),1,fp);
printf("\n%-10s\t%d\t\t d:d:d\t\td/d/d",r.name,r.second,r.t.ti_hour,r.t.ti_min,r.t.ti_sec,r.d.da_year,r.d.da_mon,r.d.da_day);}
fclose(fp);
gotoxy(10,25);
printf("Press any key to return mainmenu...");
}

void DeleteRecords()
{
int i;
FILE *fp;
fp=fopen("record","w");
for(i=0;i<MAX;i )
{
scpy(r.name,"nameless");
r.second=0;
gettime(&r.t);
geate(&r.d);
}
for(i=0;i<MAX;i )
fwrite(&r,sizeof(Record),1,fp);
fclose(fp);
}

void JudgeRecord()
{
int i=MissionNum-1;
time(&t2);
if(r.second==0||difftime(t2,t1)<r.second)
{
gotoxy(10,3);printf("\t\tYou have broken the record");
r.second=difftime(t2,t1);
scpy(r.name,name);
gettime(&r.t);
geate(&r.d);
WriteRecord();
}
else
{gotoxy(10,3);printf("\t\tYou have pass this mission");}
gotoxy(10,4);
printf("\t\tpress any key continue...");
getch();
getch();
}

void WriteRecord()
{
FILE *fp;
int i=MissionNum-1;
fp=fopen("record","rt ");
fseek(fp,i*sizeof(Record),0);
fwrite(&r,sizeof(Record),1,fp);
fclose(fp);
}

void RegisterStep()
{
int i;
StepNum ;
i=(StepNum-1)%STEPMAX;
Step=DirectionKey;
}

void ReverselyMove()
{
int i;
Add ad;
i=(StepNum-1)%STEPMAX;
if(Step==0) return;
else
{
switch(Step)
{
case Key_Up:{ad.x=1;ad.y=0;MoveBack(ad);break;}
case Key_Down:{ad.x=-1;ad.y=0;MoveBack(ad);break;}
case Key_Left:{ad.x=0;ad.y=1;MoveBack(ad);break;}
case Key_Right:{ad.x=0;ad.y=-1;MoveBack(ad);break;}
}
StepNum--;Step=0;BoxMove=0;
}
}

void MoveBack(Add a) /*一定可以移动*/
{
int i=(StepNum-1)%STEPMAX;
if(BoxMove==0)
{
map-=1;InitPic(map,p.x,p.y);
p.x=p.x a.x;p.y=p.y a.y;
map =1;InitPic(map,p.x,p.y);
}
else if(BoxMove==1)
{
map-=2;InitPic(map,p.x-a.x,p.y-a.y);
map =1;InitPic(map,p.x,p.y);
p.x=p.x a.x;p.y=p.y a.y;
map =1;InitPic(map,p.x,p.y);
}
}

⑸ c语言推箱子

//空:0墙:1箱子:3巢:4箱子与巢重合:5
[MAPCOUNT]
map_count=8
[MAP1]
w=8
h=8
nest_count=4
l1=00011100
l2=00013100
l3=11110100
l4=13202111
l5=11142031
l6=00121111
l7=00131000
l8=00111000
[MAP2]
w=9
h=9
nest_count=3
l1=111110000
l2=1或歼岩40010000
l3=102210111
l4=102010131
l5=111011131
l6=011000031
l7=010001001
l8=010001111
l9=011111000
[MAP3]
w=10
h=7
nest_count=4
l1=011111110改誉0
l2=0100000111
l3=1121110001
l4=1040200201
l5=1033102011
l6=1133100010
l7=0111111110
[MAP4]
w=6
h=8
nest_count=5
l1=011110
l2=110010
l3=142010
l4=112011
l5=110201
l6=132001
l7=133531
l8=111111
//以上为地图数据文件,保存为boxdata.dat文件
//空:0墙:1箱子:3巢:4箱子与巢重合:5
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<windows.h>
#include<string.h>

typedefstruct
{
intx;
inty;
}PT;

int**s;
PT衫御man;
PT*nest=NULL;
PTprev;

intnest_count=0;
intmap_count=0;
intgate=1;
intw,h;
charwork_dir[100]={''};
chardata_file[100]={''};

voidGetDataFromFile();
voidGetIntFromLineString(char*ch,intlen,inti);
voidDraw();
boolis_Success();

intmain()
{
printf("Loading...");
CONSOLE_CURSOR_INFOcci;
cci.bVisible=FALSE;
cci.dwSize=sizeof(cci);
HANDLEhandle=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle,&cci);

_getcwd(work_dir,100);
strcpy(data_file,work_dir);
strcat(data_file,"\boxdata.dat");
if(access(data_file,0))
{
printf("Don'tfindmapdatafile!");
getch();
exit(0);
}

while(1)
{
GetDataFromFile();
intsel=0;
Draw();
while(1)
{
fflush(stdin);
sel=getch();
if(sel==224)
{
sel=getch();
prev=man;
if(sel==77)//right
{
if(s[man.y][man.x+1]==2)
{
if(s[man.y][man.x+2]==0||s[man.y][man.x+2]==3)
{
s[man.y][man.x+2]=2;
s[man.y][man.x+1]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
elseif(s[man.y][man.x+1]==0||s[man.y][man.x+1]==3)
{
s[man.y][man.x+1]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
elseif(sel==80)//down
{
if(s[man.y+1][man.x]==2)
{
if(s[man.y+2][man.x]==0||s[man.y+2][man.x]==3)
{
s[man.y+2][man.x]=2;
s[man.y+1][man.x]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
elseif(s[man.y+1][man.x]==0||s[man.y+1][man.x]==3)
{
s[man.y+1][man.x]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
elseif(sel==72)//up
{
if(s[man.y-1][man.x]==2)
{
if(s[man.y-2][man.x]==0||s[man.y-2][man.x]==3)
{
s[man.y-2][man.x]=2;
s[man.y-1][man.x]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
elseif(s[man.y-1][man.x]==0||s[man.y-1][man.x]==3)
{
s[man.y-1][man.x]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
elseif(sel==75)//left
{
if(s[man.y][man.x-1]==2)
{
if(s[man.y][man.x-2]==0||s[man.y][man.x-2]==3)
{
s[man.y][man.x-2]=2;
s[man.y][man.x-1]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
elseif(s[man.y][man.x-1]==0||s[man.y][man.x-1]==3)
{
s[man.y][man.x-1]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
inti;
for(i=0;i<nest_count;i++)
{
if(nest[i].x==prev.x&&nest[i].y==prev.y)
{
s[prev.y][prev.x]=3;
break;
}
}
Draw();
if(is_Success()==true)
{
gate++;
if(gate>map_count)
{
printf(" mapisend!");
fflush(stdin);
getch();
exit(0);
}
break;
}
}
elseif(sel=='q'||sel=='Q')
{
exit(0);
}
elseif(sel=='r'||sel=='R')
{
break;
}
}
}
return0;
}

voidGetDataFromFile()
{
inti;
if(s!=NULL)
{
if(h!=0)
{
for(i=0;i<h;i++)
{
free(s+i);
}
free(s);
}
else
{
printf("fail");
getch();
exit(0);
}
}

if(nest!=NULL)
{
free(nest);
}
map_count=GetPrivateProfileInt("MAPCOUNT","map_count",0,data_file);

if(map_count<gate)
{
printf("gatefinish!");
getch();
exit(0);
}
charsection[20]={''};
sprintf(section,"MAP%d",gate);
nest_count=GetPrivateProfileInt(section,"nest_count",0,data_file);
nest=(PT*)malloc(sizeof(PT)*nest_count);

w=GetPrivateProfileInt(section,"w",0,data_file);
h=GetPrivateProfileInt(section,"h",0,data_file);
if(w<5||h<5||nest_count<1)
{
printf("worhorbox_nestdataerror!");
getch();
exit(0);
}
s=(int**)malloc(sizeof(int*)*h);
for(i=0;i<h;i++)
{
*(s+i)=(int*)malloc(sizeof(int)*w);
}

charkey[20]={''};
charline[50]={''};
intlen;
intj;
for(i=0;i<h;i++)
{
memset(line,'',50);
sprintf(key,"l%d",i+1);
GetPrivateProfileString(section,key,"",line,50,data_file);
len=strlen(line);
if(len>0)
{
line[len++]='';
line[len]='';
}
GetIntFromLineString(line,strlen(line),i);
}
len=0;
for(i=0;i<h;i++)
{
for(j=0;j<w;j++)
{
if(s[i][j]==3)
{
nest[len].y=i;
nest[len].x=j;
len++;
}
elseif(s[i][j]==5)
{
nest[len].y=i;
nest[len].x=j;
len++;
s[i][j]=2;
}
}
}
}

voidstrmyncpy(char*source,char*target,intbegin,intend)
{
inti=0;
while(1)
{
if(source[begin]!='')
{
target[i]=source[begin];
}
i++;
begin++;
if(begin>end)
{
target[i]='';
break;
}
}
}

voidGetIntFromLineString(char*ch,intlen,inti)
{
intj=0;
charc[5]={''};
intb=0,e=0;
while(e<len)
{
if(ch[e]=='')
{
memset(c,'',5);
strmyncpy(ch,c,b,e);
b=e+1;
e++;
s[i][j++]=atoi(c);
}
e++;
}
}

voidDraw()
{
inti,j,k;
boolflag=false;
system("cls");
printf(" ");
for(i=0;i<h;i++)
{
printf(" ");
for(j=0;j<w;j++)
{
if(s[i][j]==0)
{
printf("");
}
elseif(s[i][j]==1)
{
printf("■");
}
elseif(s[i][j]==2)
{
printf("★");
}
elseif(s[i][j]==3)
{
printf("☆");
}
elseif(s[i][j]==4)
{
printf("◎");
man.x=j;
man.y=i;
}
}
}
}

boolis_Success()
{
inti,j;
for(i=0;i<h;i++)
{
for(j=0;j<w;j++)
{
if(s[i][j]==3)
{
returnfalse;
}
}
}
for(i=0;i<nest_count;i++)
{
if(man.x==nest[i].x&&man.y==nest[i].y)
{
returnfalse;
}
}
returntrue;
}

⑹ c语言推箱子论文

/* 一个C语言编写的推箱子游戏源代码 */
/* 本游戏是字符模式的,请不要在中文dos下运行。本游戏在TURBO C下调试通过 */
#include <dos.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <bios.h>
#include <alloc.h>

/* 定义二维数组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,12);
printf("Procer : wangdehao.");
gotoxy(40,14);
printf("Mar. 30th 2003.");
}

/* 第一关的图象初始化 */
winer *inithouse1()
{
int x,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(x+4,y+10);
for(y=9,x=2;x<=5;x++)
printwall(x+4,y+10);
for(y=1,x=3;x<=8;x++)
printwall(x+4,y+10);
for(x=3,y=3;x<=5;x++)
printwall(x+4,y+10);
for(x=5,y=8;x<=9;x++)
printwall(x+4,y+10);
for(x=7,y=4;x<=9;x++)
printwall(x+4,y+10);
for(x=9,y=5;y<=7;y++)
printwall(x+4,y+10);
for(x=8,y=2;y<=3;y++)
printwall(x+4,y+10);
printwall(5+4,4+10);
printwall(5+4,7+10);
printwall(3+4,2+10);
printbox(3+4,6+10);
printbox(3+4,7+10);
printbox(4+4,7+10);
printwhither1(4+4,2+10,&win,&pw);
printwhither1(5+4,2+10,&win,&pw);
printwhither1(6+4,2+10,&win,&pw);
printman(2+4,8+10);
return win;
}

/* 第三关的图象初始化 */
winer *inithouse3()
{int x,y;
winer *win=NULL,*pw;
for(x=1,y=2;y<=8;y++)
printwall(x+4,y+10);
for(x=2,y=2;x<=4;x++)
printwall(x+4,y+10);
for(x=4,y=1;y<=3;y++)
printwall(x+4,y+10);
for(x=5,y=1;x<=8;x++)
printwall(x+4,y+10);
for(x=8,y=2;y<=5;y++)
printwall(x+4,y+10);
for(x=5,y=5;x<=7;x++)
printwall(x+4,y+10);
for(x=7,y=6;y<=9;y++)
printwall(x+4,y+10);
for(x=3,y=9;x<=6;x++)
printwall(x+4,y+10);
for(x=3,y=6;y<=8;y++)
printwall(x+4,y+10);
printwall(2+4,8+10);
printwall(5+4,7+10);
printbox(6+4,3+10);
printbox(4+4,4+10);
printbox(5+4,6+10);
printwhither1(2+4,5+10,&win,&pw);
printwhither1(2+4,6+10,&win,&pw);
printwhither1(2+4,7+10,&win,&pw);
printman(2+4,4+10);
return win;
}

/* 第二关的图象初始化 */
winer *inithouse2()
{int x,y;
winer *win=NULL,*pw;
for(x=1,y=4;y<=7;y++)
printwall(x+4,y+10);
for(x=2,y=2;y<=4;y++)
printwall(x+4,y+10);
for(x=2,y=7;x<=4;x++)
printwall(x+4,y+10);
for(x=4,y=1;x<=8;x++)
printwall(x+4,y+10);
for(x=8,y=2;y<=8;y++)
printwall(x+4,y+10);
for(x=4,y=8;x<=8;x++)
printwall(x+4,y+10);
for(x=4,y=6;x<=5;x++)
printwall(x+4,y+10);
for(x=3,y=2;x<=4;x++)
printwall(x+4,y+10);
for(x=4,y=4;x<=5;x++)
printwall(x+4,y+10);
printwall(6+4,3+10);
printbox(3+4,5+10);
printbox(6+4,6+10);
printbox(7+4,3+10);
printwhither1(5+4,7+10,&win,&pw);
printwhither1(6+4,7+10,&win,&pw);
printwhither1(7+4,7+10,&win,&pw);
printman(2+4,6+10);
return win;
}

/* 第四关的图象初始化 */
winer *inithouse4()
{
int x,y;
winer *win=NULL,*pw;
for(x=1,y=1;y<=6;y++)
printwall(x+4,y+10);
for(x=2,y=7;y<=8;y++)
printwall(x+4,y+10);
for(x=2,y=1;x<=7;x++)
printwall(x+4,y+10);
for(x=7,y=2;y<=4;y++)
printwall(x+4,y+10);
for(x=6,y=4;y<=9;y++)
printwall(x+4,y+10);
for(x=3,y=9;x<=5;x++)
printwall(x+4,y+10);
for(x=3,y=3;y<=4;y++)
printwall(x+4,y+10);
printwall(3+4,8+10);
printbox(3+4,5+10);
printbox(4+4,4+10);
printbox(4+4,6+10);
printbox(5+4,5+10);
printbox(5+4,3+10);
printwhither1(3+4,7+10,&win,&pw);
printwhither1(4+4,7+10,&win,&pw);
printwhither1(5+4,7+10,&win,&pw);
printwhither1(4+4,8+10,&win,&pw);
printwhither1(5+4,8+10,&win,&pw);
printman(2+4,2+10);
return win;
}

/* 移动在空地上的箱子到空地上 */
movebox(int x,int y,char a)
{
switch(a)
{
case 'u':ghouse[x-1][y]=0;printf(" ");
printbox(x-2,y);printman(x-1,y);
ghouse[x-2][y]='b';break;
case 'd':ghouse[x+1][y]=0;printf(" ");
printbox(x+2,y);printman(x+1,y);
ghouse[x+2][y]='b';break;
case 'l':ghouse[x][y-1]=0;printf(" ");
printbox(x,y-2);printman(x,y-1);
ghouse[x][y-2]='b';break;
case 'r':ghouse[x][y+1]=0;printf(" ");
printbox(x,y+2);printman(x,y+1);
ghouse[x][y+2]='b';break;
default: break;
}
}

/* 移动在目的地上的箱子到空地上 */
moveinbox(int x,int y,char a)
{
switch(a)
{
case 'u':ghouse[x-1][y]='m';printf(" ");
printbox(x-2,y);printman(x-1,y);
ghouse[x-2][y]='b';break;
case 'd':ghouse[x+1][y]='m';printf(" ");
printbox(x+2,y);printman(x+1,y);
ghouse[x+2][y]='b';break;
case 'l':ghouse[x][y-1]='m';printf(" ");
printbox(x,y-2);printman(x,y-1);
ghouse[x][y-2]='b';break;
case 'r':ghouse[x][y+1]='m';printf(" ");
printbox(x,y+2);printman(x,y+1);
ghouse[x][y+2]='b';break;
default: break;
}
}

/* 移动在空地上的箱子到目的地上 */
moveboxin(int x,int y,char a)
{
switch(a)
{
case 'u':ghouse[x-1][y]=0;printf(" ");
printboxin(x-2,y);printman(x-1,y);
ghouse[x-2][y]='i';break;
case 'd':ghouse[x+1][y]=0;printf(" ");
printboxin(x+2,y);printman(x+1,y);
ghouse[x+2][y]='i';break;
case 'l':ghouse[x][y-1]=0;printf(" ");
printboxin(x,y-2);printman(x,y-1);
ghouse[x][y-2]='i';break;
case 'r':ghouse[x][y+1]=0;printf(" ");
printboxin(x,y+2);printman(x,y+1);
ghouse[x][y+2]='i';break;
default: break;
}
}

/* 移动在目的地上的箱子到目的地 */
moveinboxin(int x,int y,char a)
{
switch(a)
{
case 'u':ghouse[x-1][y]='m';printf(" ");
printboxin(x-2,y);printman(x-1,y);
ghouse[x-2][y]='i';break;
case 'd':ghouse[x+1][y]='m';printf(" ");
printboxin(x+2,y);printman(x+1,y);
ghouse[x+2][y]='i';break;
case 'l':ghouse[x][y-1]='m';printf(" ");
printboxin(x,y-2);printman(x,y-1);
ghouse[x][y-2]='i';break;
case 'r':ghouse[x][y+1]='m';printf(" ");
printboxin(x,y+2);printman(x,y+1);
ghouse[x][y+2]='i';break;
default: break;
}
}

/* 判断特定的坐标上的状态 */
int judge(int x,int y)
{
int i;
switch(ghouse[x][y])
{
case 0: i=1;break;
case 'w': i=0;break;
case 'b': i=2;break;
case 'i': i=4;break;
case 'm': i=3;break;
default: break;
}
return i;
}

/* 处理按下键盘后,人物移动的主函数 */
move(int x,int y,char a)
{

switch(a)
{
case 'u':if(!judge(x-1,y)) {gotoxy(y,x);break;}
else if(judge(x-1,y)==1||judge(x-1,y)==3)
{if(judge(x,y)==3)
{ printwhither(x,y);printman(x-1,y);break;}
else
{printf(" ");printman(x-1,y);break;}
}
else if(judge(x-1,y)==2)
{ if(judge(x-2,y)==1)
{movebox(x,y,'u');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y,x-1);
}
else if(judge(x-2,y)==3)
{ moveboxin(x,y,'u');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y,x-1);
}
else gotoxy(y,x);
break;
}
else if(judge(x-1,y)==4)
{ if(judge(x-2,y)==1)
{moveinbox(x,y,'u');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x-1);
}
else if(judge(x-2,y)==3)
{ moveinboxin(x,y,'u');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x-1);
}
else gotoxy(y,x);
break;
}
case 'd':if(!judge(x+1,y)) {gotoxy(y,x);break;}
else if(judge(x+1,y)==1||judge(x+1,y)==3)
{if(judge(x,y)==3)
{ printwhither(x,y);printman(x+1,y);break;}
else
{printf(" ");printman(x+1,y);break;}
}
else if(judge(x+1,y)==2)
{ if(judge(x+2,y)==1)
{movebox(x,y,'d');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x+1);
}
else if(judge(x+2,y)==3)
{moveboxin(x,y,'d');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x+1);
}
else gotoxy(y,x);
break;
}
else if(judge(x+1,y)==4)
{ if(judge(x+2,y)==1)
{moveinbox(x,y,'d');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x+1);
}
else if(judge(x+2,y)==3)
{moveinboxin(x,y,'d');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x+1);
}
else gotoxy(y,x);
break;
}

case 'l':if(!judge(x,y-1)) {gotoxy(y,x);break;}
else if(judge(x,y-1)==1||judge(x,y-1)==3)
{if(judge(x,y)==3)
{ printwhither(x,y);printman(x,y-1);break;}
else
{printf(" ");printman(x,y-1);break;}
}
else if(judge(x,y-1)==2)
{ if(judge(x,y-2)==1)
{movebox(x,y,'l');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y-1,x);
}
else if(judge(x,y-2)==3)
{moveboxin(x,y,'l');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y-1,x);
}
else gotoxy(y,x);
break;
}
else if(judge(x,y-1)==4)
{ if(judge(x,y-2)==1)
{moveinbox(x,y,'l');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y-1,x);
}
else if(judge(x,y-2)==3)
{moveinboxin(x,y,'l');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y-1,x);
}
else gotoxy(y,x);
break;
}
case 'r':if(!judge(x,y+1)) {gotoxy(y,x);break;}
else if(judge(x,y+1)==1||judge(x,y+1)==3)
{if(judge(x,y)==3)
{printwhither(x,y);printman(x,y+1);break;}
else
{printf(" ");printman(x,y+1);break;}
}
else if(judge(x,y+1)==2)
{ if(judge(x,y+2)==1)
{movebox(x,y,'r');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y+1,x);
}
else if(judge(x,y+2)==3)
{moveboxin(x,y,'r');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y+1,x);
}
else gotoxy(y,x);
break;
}
else if(judge(x,y+1)==4)
{ if(judge(x,y+2)==1)
{moveinbox(x,y,'r');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y+1,x);
}
else if(judge(x,y+2)==3)
{moveinboxin(x,y,'r');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y+1,x);
}
else gotoxy(y,x);
break;
}
default: break;
}
}

/* 按下空格键后,回到本关开头的函数 */
void reset(int i)
{
switch(i)
{
case 0: init();
inithouse1();break;
case 1: init();
inithouse2();break;
case 2: init();
inithouse3();break;
case 3: init();
inithouse4();break;
default:break;
}
}

/* 主函数main */
void main()
{
int key,x,y,s,i=0;
winer *win,*pw;
_AL=3;_AH=0;
geninterrupt(0x10);
init();
win=inithouse1();

do{
_AH=3;
geninterrupt(0x10);
x=_DH+1;y=_DL+1;
while(bioskey(1)==0);
key=bioskey(0);
switch(key)
{
case 0x4800:move(x,y,'u');break; /* 按下向上键后 */
case 0x5000:move(x,y,'d');break; /* 按下向下键后 */
case 0x4b00:move(x,y,'l');break; /* 按下向左键后 */
case 0x4d00:move(x,y,'r');break; /* 按下向右键后 */
case 0x3920:reset(i);break; /* 按下空格键后 */
default:break;
}
s=0;
pw=win;
while(pw)
{
if(ghouse[pw->x][pw->y]=='m') s++;
pw=pw->p;
}
if(s==0)
{
free(win);
gotoxy(25,2);
printf("congratulate! you did a good job!");
getch();
i++;
switch(i)
{
case 1: init();
win=inithouse2();break;
case 2: init();
win=inithouse3();break;
case 3: init();
win=inithouse4();break;
case 4: gotoxy(15,21);
printf("My dear Friend, How smart you are! Welcome to play again!");
key=0x011b;getch();break;
default: break;
}
}

}while(key!=0x011b);

_AL=3;
_AH=0;
geninterrupt(0x10);
}

⑺ c语言推箱子代码

Here you are!
编译通过。
/* 推箱子游戏 */
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <conio.h>
#include <bios.h>
#include <alloc.h>
/* 定义二维数组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,MAGENTA,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;
system("cls");
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 push 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,12);
printf("April 30th 2004.");
}

/* 第一关的图象初始化 */
winer *inithouse1()
{
int x,y;
winer *win=NULL,*pw;
gotoxy(8,2);
printf("Level No.1");
for(x=1,y=5;y<=9;y++)
printwall(x+4,y+10);
for(y=5,x=2;x<=5;x++)
printwall(x+4,y+10);
for(y=9,x=2;x<=5;x++)
printwall(x+4,y+10);
for(y=1,x=3;x<=8;x++)
printwall(x+4,y+10);
for(x=3,y=3;x<=5;x++)
printwall(x+4,y+10);
for(x=5,y=8;x<=9;x++)
printwall(x+4,y+10);
for(x=7,y=4;x<=9;x++)
printwall(x+4,y+10);
for(x=9,y=5;y<=7;y++)
printwall(x+4,y+10);
for(x=8,y=2;y<=3;y++)
printwall(x+4,y+10);
printwall(5+4,4+10);
printwall(5+4,7+10);
printwall(3+4,2+10);
printbox(3+4,6+10);
printbox(3+4,7+10);
printbox(4+4,7+10);
printwhither1(4+4,2+10,&win,&pw);
printwhither1(5+4,2+10,&win,&pw);
printwhither1(6+4,2+10,&win,&pw);
printman(2+4,8+10);
return win;
}

/* 第三关的图象初始化 */
winer *inithouse3()
{int x,y;
winer *win=NULL,*pw;
gotoxy(8,3);
printf("Level No.3");
for(x=1,y=2;y<=8;y++)
printwall(x+4,y+10);
for(x=2,y=2;x<=4;x++)
printwall(x+4,y+10);
for(x=4,y=1;y<=3;y++)
printwall(x+4,y+10);
for(x=5,y=1;x<=8;x++)
printwall(x+4,y+10);
for(x=8,y=2;y<=5;y++)
printwall(x+4,y+10);
for(x=5,y=5;x<=7;x++)
printwall(x+4,y+10);
for(x=7,y=6;y<=9;y++)
printwall(x+4,y+10);
for(x=3,y=9;x<=6;x++)
printwall(x+4,y+10);
for(x=3,y=6;y<=8;y++)
printwall(x+4,y+10);
printwall(2+4,8+10);
printwall(5+4,7+10);
printbox(6+4,3+10);
printbox(4+4,4+10);
printbox(5+4,6+10);
printwhither1(2+4,5+10,&win,&pw);
printwhither1(2+4,6+10,&win,&pw);
printwhither1(2+4,7+10,&win,&pw);
printman(2+4,4+10);
return win;
}

/* 第二关的图象初始化 */
winer *inithouse2()
{int x,y;
winer *win=NULL,*pw;
gotoxy(8,2);
printf("Level No.2");
for(x=1,y=4;y<=7;y++)
printwall(x+4,y+10);
for(x=2,y=2;y<=4;y++)
printwall(x+4,y+10);
for(x=2,y=7;x<=4;x++)
printwall(x+4,y+10);
for(x=4,y=1;x<=8;x++)
printwall(x+4,y+10);
for(x=8,y=2;y<=8;y++)
printwall(x+4,y+10);
for(x=4,y=8;x<=8;x++)
printwall(x+4,y+10);
for(x=4,y=6;x<=5;x++)
printwall(x+4,y+10);
for(x=3,y=2;x<=4;x++)
printwall(x+4,y+10);
for(x=4,y=4;x<=5;x++)
printwall(x+4,y+10);
printwall(6+4,3+10);
printbox(3+4,5+10);
printbox(6+4,6+10);
printbox(7+4,3+10);
printwhither1(5+4,7+10,&win,&pw);
printwhither1(6+4,7+10,&win,&pw);
printwhither1(7+4,7+10,&win,&pw);
printman(2+4,6+10);
return win;
}

/* 第四关的图象初始化 */
winer *inithouse4()
{int x,y;
winer *win=NULL,*pw;
gotoxy(8,2);
printf("Level No.4");
for(x=1,y=1;y<=6;y++)
printwall(x+4,y+10);
for(x=2,y=7;y<=8;y++)
printwall(x+4,y+10);
for(x=2,y=1;x<=7;x++)
printwall(x+4,y+10);
for(x=7,y=2;y<=4;y++)
printwall(x+4,y+10);
for(x=6,y=4;y<=9;y++)
printwall(x+4,y+10);
for(x=3,y=9;x<=5;x++)
printwall(x+4,y+10);
for(x=3,y=3;y<=4;y++)
printwall(x+4,y+10);
printwall(3+4,8+10);
printbox(3+4,5+10);
printbox(4+4,4+10);
printbox(4+4,6+10);
printbox(5+4,5+10);
printbox(5+4,3+10);
printwhither1(3+4,7+10,&win,&pw);
printwhither1(4+4,7+10,&win,&pw);
printwhither1(5+4,7+10,&win,&pw);
printwhither1(4+4,8+10,&win,&pw);
printwhither1(5+4,8+10,&win,&pw);
printman(2+4,2+10);
return win;
}

/* 移动在空地上的箱子到空地上 */
movebox(int x,int y,char a)
{switch(a)
{
case 'u':ghouse[x-1][y]=0;printf(" ");
printbox(x-2,y);printman(x-1,y);
ghouse[x-2][y]='b';break;
case 'd':ghouse[x+1][y]=0;printf(" ");
printbox(x+2,y);printman(x+1,y);
ghouse[x+2][y]='b';break;
case 'l':ghouse[x][y-1]=0;printf(" ");
printbox(x,y-2);printman(x,y-1);
ghouse[x][y-2]='b';break;
case 'r':ghouse[x][y+1]=0;printf(" ");
printbox(x,y+2);printman(x,y+1);
ghouse[x][y+2]='b';break;
default: break;
}
}

/* 移动在目的地上的箱子到空地上 */
moveinbox(int x,int y,char a)
{switch(a)
{
case 'u':ghouse[x-1][y]='m';printf(" ");
printbox(x-2,y);printman(x-1,y);
ghouse[x-2][y]='b';break;
case 'd':ghouse[x+1][y]='m';printf(" ");
printbox(x+2,y);printman(x+1,y);
ghouse[x+2][y]='b';break;
case 'l':ghouse[x][y-1]='m';printf(" ");
printbox(x,y-2);printman(x,y-1);
ghouse[x][y-2]='b';break;
case 'r':ghouse[x][y+1]='m';printf(" ");
printbox(x,y+2);printman(x,y+1);
ghouse[x][y+2]='b';break;
default: break;
}
}

/* 移动在空地上的箱子到目的地上 */
moveboxin(int x,int y,char a)
{switch(a)
{
case 'u':ghouse[x-1][y]=0;printf(" ");
printboxin(x-2,y);printman(x-1,y);
ghouse[x-2][y]='i';break;
case 'd':ghouse[x+1][y]=0;printf(" ");
printboxin(x+2,y);printman(x+1,y);
ghouse[x+2][y]='i';break;
case 'l':ghouse[x][y-1]=0;printf(" ");
printboxin(x,y-2);printman(x,y-1);
ghouse[x][y-2]='i';break;
case 'r':ghouse[x][y+1]=0;printf(" ");
printboxin(x,y+2);printman(x,y+1);
ghouse[x][y+2]='i';break;
default: break;
}
}

/* 移动在目的地上的箱子到目的地 */
moveinboxin(int x,int y,char a)
{switch(a)
{
case 'u':ghouse[x-1][y]='m';printf(" ");
printboxin(x-2,y);printman(x-1,y);
ghouse[x-2][y]='i';break;
case 'd':ghouse[x+1][y]='m';printf(" ");
printboxin(x+2,y);printman(x+1,y);
ghouse[x+2][y]='i';break;
case 'l':ghouse[x][y-1]='m';printf(" ");
printboxin(x,y-2);printman(x,y-1);
ghouse[x][y-2]='i';break;
case 'r':ghouse[x][y+1]='m';printf(" ");
printboxin(x,y+2);printman(x,y+1);
ghouse[x][y+2]='i';break;
default: break;
}
}

/* 判断特定的坐标上的状态 */
int judge(int x,int y)
{int i;
switch(ghouse[x][y])
{
case 0: i=1;break;
case 'w': i=0;break;
case 'b': i=2;break;
case 'i': i=4;break;
case 'm': i=3;break;
default: break;
}
return i;
}

/* 处理按下键盘后,人物移动的主函数 */
move(int x,int y,char a)
{switch(a)
{
case 'u':if(!judge(x-1,y)) {gotoxy(y,x);break;}
else if(judge(x-1,y)==1||judge(x-1,y)==3)
{if(judge(x,y)==3)
{ printwhither(x,y);printman(x-1,y);break;}
else
{printf(" ");printman(x-1,y);break;}
}
else if(judge(x-1,y)==2)
{ if(judge(x-2,y)==1)
{movebox(x,y,'u');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y,x-1);
}
else if(judge(x-2,y)==3)
{ moveboxin(x,y,'u');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y,x-1);
}
else gotoxy(y,x);
break;
}
else if(judge(x-1,y)==4)
{ if(judge(x-2,y)==1)
{moveinbox(x,y,'u');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x-1);
}
else if(judge(x-2,y)==3)
{ moveinboxin(x,y,'u');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x-1);
}
else gotoxy(y,x);
break;
}
case 'd':if(!judge(x+1,y)) {gotoxy(y,x);break;}
else if(judge(x+1,y)==1||judge(x+1,y)==3)
{if(judge(x,y)==3)
{ printwhither(x,y);printman(x+1,y);break;}
else
{printf(" ");printman(x+1,y);break;}
}
else if(judge(x+1,y)==2)
{ if(judge(x+2,y)==1)
{movebox(x,y,'d');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x+1);
}
else if(judge(x+2,y)==3)
{moveboxin(x,y,'d');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x+1);
}
else gotoxy(y,x);
break;
}
else if(judge(x+1,y)==4)
{ if(judge(x+2,y)==1)
{moveinbox(x,y,'d');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x+1);
}
else if(judge(x+2,y)==3)
{moveinboxin(x,y,'d');
if(judge(x,y)==3) printwhither(x,y);gotoxy(y,x+1);
}
else gotoxy(y,x);
break;
}

case 'l':if(!judge(x,y-1)) {gotoxy(y,x);break;}
else if(judge(x,y-1)==1||judge(x,y-1)==3)
{if(judge(x,y)==3)
{ printwhither(x,y);printman(x,y-1);break;}
else
{printf(" ");printman(x,y-1);break;}
}
else if(judge(x,y-1)==2)
{ if(judge(x,y-2)==1)
{movebox(x,y,'l');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y-1,x);
}
else if(judge(x,y-2)==3)
{moveboxin(x,y,'l');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y-1,x);
}
else gotoxy(y,x);
break;
}
else if(judge(x,y-1)==4)
{ if(judge(x,y-2)==1)
{moveinbox(x,y,'l');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y-1,x);
}
else if(judge(x,y-2)==3)
{moveinboxin(x,y,'l');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y-1,x);
}
else gotoxy(y,x);
break;
}
case 'r':if(!judge(x,y+1)) {gotoxy(y,x);break;}
else if(judge(x,y+1)==1||judge(x,y+1)==3)
{if(judge(x,y)==3)
{printwhither(x,y);printman(x,y+1);break;}
else
{printf(" ");printman(x,y+1);break;}
}
else if(judge(x,y+1)==2)
{ if(judge(x,y+2)==1)
{movebox(x,y,'r');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y+1,x);
}
else if(judge(x,y+2)==3)
{moveboxin(x,y,'r');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y+1,x);
}
else gotoxy(y,x);
break;
}
else if(judge(x,y+1)==4)
{ if(judge(x,y+2)==1)
{moveinbox(x,y,'r');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y+1,x);
}
else if(judge(x,y+2)==3)
{moveinboxin(x,y,'r');
if(judge(x,y)==3) printwhither(x,y); gotoxy(y+1,x);
}
else gotoxy(y,x);
break;
}
default: break;
}
}

/* 按下空格键后,回到本关开头的函数 */
void reset(int i)
{switch(i)
{
case 0: init();
inithouse1();break;
case 1: init();
inithouse2();break;
case 2: init();
inithouse3();break;
case 3: init();
inithouse4();break;
default:break;
}
}

/* 主函数main */
main()
{int key,x,y,s,i=0;
winer *win,*pw;
_AL=3;_AH=0;
geninterrupt(0x10);
init();
win=inithouse1();
do{
_AH=3;
geninterrupt(0x10);
x=_DH+1;y=_DL+1;
while(bioskey(1)==0);
key=bioskey(0);
switch(key)
{
case 0x4800:move(x,y,'u');break; /* 按下向上键后 */
case 0x5000:move(x,y,'d');break; /* 按下向下键后 */
case 0x4b00:move(x,y,'l');break; /* 按下向左键后 */
case 0x4d00:move(x,y,'r');break; /* 按下向右键后 */
case 0x3920:reset(i);break; /* 按下空格键后 */
default:break;
}
s=0;
pw=win;
while(pw)
{
if(ghouse[pw->x][pw->y]=='m') s++;
pw=pw->p;
}
if(s==0)
{
free(win);
gotoxy(25,2);
printf("Congratulate! You have passed Level %d!",i+1);
getch();
i++;
switch(i)
{
case 1: init();
win=inithouse2();break;
case 2: init();
win=inithouse3();break;
case 3: init();
win=inithouse4();break;
case 4: gotoxy(8,14);
printf("Great! You have passed all the levels! Press any key to quit!");
key=0x011b;getch();break;
default: break;
}
}
}while(key!=0x011b);
_AL=3;
_AH=0;
geninterrupt(0x10);
}

⑻ 我用c语言分别写了推箱子的第一关和第二关的地图 请问怎样将第一关和第二关联系在一起

关卡信息只是数据,所以程序只大丛要支持推箱子的规则就行了,不能换一举升关地图,而重正仿老新编写程序,程序是通用的才行。

热点内容
cups脚本重启不生效 发布:2024-11-05 11:34:19 浏览:997
解压gta5 发布:2024-11-05 11:33:29 浏览:200
手游安卓cf怎么退款 发布:2024-11-05 11:23:28 浏览:135
登录qq时什么是昵称和密码 发布:2024-11-05 11:21:38 浏览:955
ftp怎么设置可以直接打开 发布:2024-11-05 11:20:49 浏览:823
问道全敏竞技怎么配置队伍 发布:2024-11-05 11:20:04 浏览:832
app应用下载源码下载 发布:2024-11-05 11:15:36 浏览:841
给公司服务器配置公网ip 发布:2024-11-05 11:05:33 浏览:159
Sql两表差集 发布:2024-11-05 11:04:10 浏览:590
GA算法来源 发布:2024-11-05 11:00:32 浏览:746