c语言推箱子

供稿:hz-xin.com     日期:2025-01-16
c语言推箱子代码

Here you are!
编译通过。
/* 推箱子游戏 */
#include
#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,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);
}

#include "stdio.h"#include #include "Windows.h"void gotoxy(int x, int y) {system("cls");COORD cr;cr.X = x;cr.Y = y;HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(handle, cr);printf("*");}int main() {static int x = 10, y = 10;gotoxy(x, y);char c;while(1) {c = getch();switch(c) {case 'w':case 'W':y--;gotoxy(x, y);break;case 'a':case 'A':x--;gotoxy(x, y);break;case 's':case 'S':y++;gotoxy(x, y);break;case 'd':case 'D':x++;gotoxy(x, y);break;default:break;}}}我只是给你举个简单的例子,你应该能明白这个程序了

//空:0  墙:1  箱子:3   巢:4   箱子与巢重合:5
[MAPCOUNT]
map_count=8
[MAP1]
w=8
h=8
nest_count=4
l1=0 0 0 1 1 1 0 0
l2=0 0 0 1 3 1 0 0
l3=1 1 1 1 0 1 0 0
l4=1 3 2 0 2 1 1 1
l5=1 1 1 4 2 0 3 1
l6=0 0 1 2 1 1 1 1
l7=0 0 1 3 1 0 0 0
l8=0 0 1 1 1 0 0 0
[MAP2]
w=9
h=9
nest_count=3
l1=1 1 1 1 1 0 0 0 0
l2=1 4 0 0 1 0 0 0 0
l3=1 0 2 2 1 0 1 1 1
l4=1 0 2 0 1 0 1 3 1
l5=1 1 1 0 1 1 1 3 1
l6=0 1 1 0 0 0 0 3 1
l7=0 1 0 0 0 1 0 0 1
l8=0 1 0 0 0 1 1 1 1
l9=0 1 1 1 1 1 0 0 0
[MAP3]
w=10
h=7
nest_count=4
l1=0 1 1 1 1 1 1 1 0 0
l2=0 1 0 0 0 0 0 1 1 1
l3=1 1 2 1 1 1 0 0 0 1
l4=1 0 4 0 2 0 0 2 0 1
l5=1 0 3 3 1 0 2 0 1 1
l6=1 1 3 3 1 0 0 0 1 0
l7=0 1 1 1 1 1 1 1 1 0
[MAP4]
w=6
h=8
nest_count=5
l1=0 1 1 1 1 0
l2=1 1 0 0 1 0
l3=1 4 2 0 1 0
l4=1 1 2 0 1 1
l5=1 1 0 2 0 1
l6=1 3 2 0 0 1
l7=1 3 3 5 3 1
l8=1 1 1 1 1 1
//以上为地图数据文件,保存为boxdata.dat文件
//空:0  墙:1  箱子:3   巢:4   箱子与巢重合:5
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <windows.h>
#include <string.h>

typedef struct
{
int x;
int y;
} PT;

int** s;
PT man;
PT* nest=NULL;
PT prev;

int nest_count=0;
int map_count=0;
int gate=1;
int w,h;
char work_dir[100]={'\0'};
char data_file[100]={'\0'};

void GetDataFromFile();
void GetIntFromLineString(char* ch, int len, int i);
void Draw();
bool is_Success();

int main()
{
printf("Loading...");
CONSOLE_CURSOR_INFO cci;
cci.bVisible = FALSE;
cci.dwSize = sizeof(cci);
HANDLE handle = 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't find map data file !");
getch();
exit(0);
}

while(1)
{
GetDataFromFile();
int sel=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;
}
}
else if(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;
}
}
else if(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;
}
}
else if(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;
}
}
else if(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;
}
}
else if(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;
}
}
else if(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;
}
}
else if(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;
}
}
int i;
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("

map is end!");
fflush(stdin);
getch();
exit(0);
}
break;
}
}
else if(sel=='q' || sel=='Q')
{
exit(0);
}
else if(sel=='r' || sel=='R')
{
break;
}
}
}
return 0;
}

void GetDataFromFile()
{
int i;
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("gate finish!");
getch();
exit(0);
}
char section[20]={'\0'};
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("w or h or box_nest data error!");
getch();
exit(0);
}
s=(int**)malloc(sizeof(int*)*h);
for(i=0;i<h;i++)
{
*(s+i)=(int*)malloc(sizeof(int)*w);
}

char key[20]={'\0'};
char line[50]={'\0'};
int len;
int j;
for(i=0;i<h;i++)
{
memset(line,'\0',50);
sprintf(key,"l%d",i+1);
GetPrivateProfileString(section,key,"\0",line,50,data_file);
len=strlen(line);
if(len>0)
{
line[len++]=' ';
line[len]='\0';
}
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++;
}
else if(s[i][j]==5)
{
nest[len].y=i;
nest[len].x=j;
len++;
s[i][j]=2;
}
}
}
}

void strmyncpy(char* source, char* target, int begin, int end)
{
int i=0;
while(1)
{
if(source[begin]!=' ')
{
target[i]=source[begin];
}
i++;
begin++;
if(begin>end)
{
target[i]='\0';
break;
}
}
}

void GetIntFromLineString(char* ch, int len, int i)
{
int j=0;
char c[5]={'\0'};
int b=0,e=0;
while(e<len)
{
if(ch[e]==' ')
{
memset(c,'\0',5);
strmyncpy(ch,c,b,e);
b=e+1;
e++;
s[i][j++]=atoi(c);
}
e++;
}
}

void Draw()
{
int i,j,k;
bool flag=false;
system("cls");
printf("

");
for(i=0;i<h;i++)
{
printf("

");
for(j=0;j<w;j++)
{
if(s[i][j]==0)
{
printf("    ");
}
else if(s[i][j]==1)
{
printf(" ■ ");
}
else if(s[i][j]==2)
{
printf(" ★ ");
}
else if(s[i][j]==3)
{
printf(" ☆ ");
}
else if(s[i][j]==4)
{
printf(" ◎ ");
man.x=j;
man.y=i;
}
}
}
}

bool is_Success()
{
int i,j;
for(i=0;i<h;i++)
{
for(j=0;j<w;j++)
{
if(s[i][j]==3)
{
return false;
}
}
}
for(i=0;i<nest_count;i++)
{
if(man.x==nest[i].x && man.y==nest[i].y)
{
return false;
}
}
return true;
}


C语言推箱子代码 不要解释的
编译通过。 \/* 推箱子游戏 *\/ #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'表示...

c语言推箱子
\/\/空:0 墙:1 箱子:3 巢:4 箱子与巢重合:5[MAPCOUNT]map_count=8[MAP1]w=8h=8nest_count=4l1=0 0 0 1 1 1 0 0l2=0 0 0 1 3 1 0 0l3=1 1 1 1 0 1 0 0l4=1 3 2 0 2 1 1 1l5=1 1 1 4 2 0 3 1l6=0 0 1 2 1 1 1 1l7=0 0 1 3 1 0...

求一个用C语言编写的推箱子小游戏代码
若用VC环境下的C语言进行图像编程,理论上是不行的。不过好在已有高人解决了 压缩包内有文件源代码,与相应的插件,按说明安装即可 亲自测试

用汇编语言编写一个推箱子游戏
出来了,代码如下:data segment car db 2,2,2,2,2,2,2,2,2,2 db 2,2,2,2,2,2,0,0,0,2 db 2,2,2,2,2,2,0,0,0,2 db 2,2,2,2,2,2,0,0,0,2 db 2,2,2,2,2,2,2,2,2,2 db 2,2,2,2,2,2,2,2,2,2 db 0,0,2,0,0,0,0,2,0,0 db 0,2,0,2...

网络工程学c语言吗
并且具备很强的数据处理能力,可以用来编写系统软件、制作动画、绘制二维图形和三维图形等。3、开发嵌入式设备:手机等消费类电子产品内部的应用软件、游戏等很多都是采用C语言进行嵌入式开发的。4、开发游戏软件:利用C语言可以开发很多游戏,比如推箱子、贪吃蛇等。今天的分享就是这些,希望能帮助到大家!

想问一下C语言的应用领域有哪些
(6)游戏软件开发。游戏大家更不陌生,很多人就是由玩游戏而熟悉了计算机。利用C语言可以开发很多游戏,比如推箱子、贪吃蛇等。1. 上层开发 其实用 C 语言做上层应用程序开发和写界面不是明智的选择,比如 Windows 上面,画个窗口,写个消息处理函数,但是较为麻烦。2. 底层开发 C 语言主要的用途...

用什么软件编写c语言
并且具备很强的数据处理能力,可以用来编写系统软件、制作动画、绘制二维图形和三维图形等。3、开发嵌入式设备:手机等消费类电子产品内部的应用软件、游戏等很多都是采用C语言进行嵌入式开发的。4、开发游戏软件:利用C语言可以开发很多游戏,比如推箱子、贪吃蛇等。今天的分享就是这些,希望能帮助到大家!

儿童相机推箱子游戏第10关
下载地址:http:\/\/www.xyx09.com\/307491\/ 类型:安卓游戏-益智休闲 版本:v1.0.13 大小:16.09M 语言:中文 平台:安卓APK 推荐星级(评分):★★★ 游戏标签: 益智手游 推箱子迷宫 推箱子迷宫是一款休闲益智小游戏,相信大家对这款游戏并不陌生,这都是我们小时候的回忆,让我...

如何学好c语言
并且具备很强的数据处理能力,可以用来编写系统软件、制作动画、绘制二维图形和三维图形等。3、开发嵌入式设备:手机等消费类电子产品内部的应用软件、游戏等很多都是采用C语言进行嵌入式开发的。4、开发游戏软件:利用C语言可以开发很多游戏,比如推箱子、贪吃蛇等。今天的分享就是这些,希望能帮助到大家!

c语言在电子信息方面的应用有哪些?
C语言是数字计算能力超强的高级语言。(5)嵌入式设备开发。手机、PDA等时尚消费类电子产品相信大家都不陌生,其内部的应用软件、游戏等很多都是采用C语言进行嵌入式开发的。(6)游戏软件开发。游戏大家更不陌生,很多人就是由玩游戏而熟悉了计算机。利用C语言可以开发很多游戏,比如推箱子、贪吃蛇等。