導航:首頁 > 源碼編譯 > 怎麼用推箱子編譯

怎麼用推箱子編譯

發布時間:2022-04-12 06:10:37

Ⅰ 求一個用C語言編寫的推箱子小游戲代碼

若用VC環境下的C語言進行圖像編程,理論上是不行的。不過好在已有高人解決了
壓縮包內有文件源代碼,與相應的插件,按說明安裝即可
親自測試
很抱歉,回答者上傳的附件已失效

Ⅱ 怎麼用C語言編寫推箱子的簡單小游戲

http://blog.csdn.net/pastthewind/article/details/52456178,這裡面有代碼

Ⅲ 用vc++編寫推箱子程序的具體步驟

你可以到魔方吧推箱子論壇問問,那裡有很多編程高手
http://bbs.mf8-china.com/forum.php?mod=forumdisplay&fid=57

Ⅳ 緊急求救:用C語言編寫推箱子游戲的程序!!

給:
#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; /*判斷是否所有箱子都在目標坐標上*/
for(i=0;i<4;i++)
if(chMap[Box[i].y-5][Box[i].x-10]==2)
j++;
if(j==4) /*如果所有箱子都就位輸出"YOU WIN!"退出*/
{
clrscr();
printf("You Win!");
break;
}
for(i=0;i<4;i++) /*在起始(或移動後)的坐標輸出箱子*/
{
gotoxy(Box[i].x,Box[i].y);
printf("0");
}
gotoxy(x,y); /*在起始(或移動後)的坐標輸出人*/
printf("*\b");
tx=x; /*記錄本次移動前的坐標*/
ty=y;
iKey=fnGetKey();
if(iKey==LEFT&&chMap[y-5][x-1-10]!=0) /*按讀取的按鍵信息改變坐標如果改變的坐標和牆(0)重合則不改變*/
x--;
if(iKey==RIGHT&&chMap[y-5][x+1-10]!=0)
x++;
if(iKey==UPPER&&chMap[y-1-5][x-10]!=0)
y--;
if(iKey==DOWN&&chMap[y+1-5][x-10]!=0)
y++; /*輸入ESC退出並輸出"YOU LOST"*/
if(iKey==ESC)
{
clrscr();
printf("You Lost");
break;
}
for(i=0;i<4;i++) /*如果移動後的人的坐標與箱子坐標重合,則改變箱子坐標向前一格*/
if(Box[i].x==x&&Box[i].y==y)
{
Box[i].x+=(x-tx);
Box[i].y+=(y-ty);
if(chMap[Box[i].y-5][Box[i].x-10]==0) /*如果移動後的箱子坐標會出現在牆上,則使箱子坐標和人坐標都返回移動前的值*/
{
Box[i].x-=(x-tx);
Box[i].y-=(y-ty);
x=tx;
y=ty;
}
break;
}
clrscr();
}
getch();
}

Ⅳ 有沒有人知道怎麼用C語言編寫一個推箱子的小游戲啊我不想要網上那些找的

C語言? 查查

Ⅵ 如何用C語言編寫一如圖模型的推箱子游戲的程序!

/*TC環境下編的*/
#include <dos.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <bios.h>
#include <alloc.h>

typedef struct winer
{
int x,y;
struct winer *p;
}winer;

char status [20][20];
char far *printScreen=(char far* )0xB8000000;

void putoutChar(int y,int x,char ch,char fc,char bc);
void printWall(int x, int y);
void printBox(int x, int y);
void printBoxDes(int x, int y);
void printDestination(int x, int y);
void printDestination1(int x,int y,winer **win,winer **pw);
void printMan(int x, int y);
void init();
winer *initStep1();
winer *initStep2();
winer *initStep3();
winer *initStep4();
void moveBoxSpacetoSpace(int x ,int y, char a);
void moveBoxDestoSpace(int x ,int y, char a) ;
void moveBoxSpacetoDes(int x, int y, char a);
void moveBoxDestoDes(int x, int y, char a);
int judge(int x, int y);
void move(int x, int y, char a);
void reset(int i);

void putoutChar(int y,int x,char ch,char fc,char bc)
{
printScreen[(x*160)+(y<<1)+0]=ch;
printScreen[(x*160)+(y<<1)+1]=(bc*16)+fc;
}
void printWall(int x,int y)
{
putoutChar(y-1,x-1,219,GREEN,BLACK);
status[x][y]='w';
}

void printBox(int x,int y)
{
putoutChar(y-1,x-1,10,WHITE,BLACK);
status[x][y]='b';
}

void printDestination1(int x,int y,winer **win,winer **pw)
{
winer *qw;
putoutChar(y-1,x-1,003,YELLOW,BLACK);
status[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 printDestination(int x,int y)
{
putoutChar(y-1,x-1,003,YELLOW,BLACK);
status[x][y]='m';
}

void printMan(int x,int y)
{
gotoxy(y,x);
_AL=02;
_CX=01;
_AH=0xa;
geninterrupt(0x10);
}

void printBoxDes(int x,int y)
{
putoutChar(y-1,x-1,10,YELLOW,BLACK);
status[x][y]='i';
}

void init()
{
int i,j;
for(i=0;i<20;i++)
for(j=0;j<20;j++)
status[i][j]=0;
_AL=3;
_AH=0;
geninterrupt(0x10);
gotoxy(40,4);
printf("Welcome to the box world!");
gotoxy(40,6);
printf("You can use up, down, left,");
gotoxy(40,8);
printf("right key to control it, or");
gotoxy(40,10);
printf("you can press Esc to quit it.");
gotoxy(40,12);
printf("Press space to reset the game.");
gotoxy(40,14);
printf("Wish you have a good time !");
gotoxy(40,16);
printf("April , 2007");

}
winer *initStep1()
{
int x;
int y;
winer *win=NULL;
winer *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);
printDestination1(4+4,2+10,&win,&pw);
printDestination1(5+4,2+10,&win,&pw);
printDestination1(6+4,2+10,&win,&pw);
printMan(2+4,8+10);
return win;
}

winer *initStep2()
{
int x;
int y;
winer *win=NULL;
winer *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);
printDestination1(5+4,7+10,&win,&pw);
printDestination1(6+4,7+10,&win,&pw);
printDestination1(7+4,7+10,&win,&pw);
printMan(2+4,6+10);
return win;
}
winer *initStep3()
{
int x;
int y;
winer *win=NULL;
winer *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);
printDestination1(2+4,5+10,&win,&pw);
printDestination1(2+4,6+10,&win,&pw);
printDestination1(2+4,7+10,&win,&pw);
printMan(2+4,4+10);
return win;
}

winer *initStep4()
{
int x;
int y;
winer *win=NULL;
winer *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);
printDestination1(3+4,7+10,&win,&pw);
printDestination1(4+4,7+10,&win,&pw);
printDestination1(5+4,7+10,&win,&pw);
printDestination1(4+4,8+10,&win,&pw);
printDestination1(5+4,8+10,&win,&pw);
printMan(2+4,2+10);
return win;
}

void moveBoxSpacetoSpace(int x,int y,char a)
{
switch(a)
{
case 'u':
status[x-1][y]=0;
printf(" ");
printBox(x-2,y);
printMan(x-1,y);
status[x-2][y]='b';
break;
case 'd':
status[x+1][y]=0;
printf(" ");
printBox(x+2,y);
printMan(x+1,y);
status[x+2][y]='b';
break;
case 'l':
status[x][y-1]=0;
printf(" ");
printBox(x,y-2);
printMan(x,y-1);
status[x][y-2]='b';
break;
case 'r':
status[x][y+1]=0;
printf(" ");
printBox(x,y+2);
printMan(x,y+1);
status[x][y+2]='b';
break;
default:
break;
}
}

void moveBoxDestoSpace(int x,int y,char a)
{
switch(a)
{
case 'u':
status[x-1][y]='m';
printf(" ");
printBox(x-2,y);
printMan(x-1,y);
status[x-2][y]='b';
break;
case 'd':
status[x+1][y]='m';
printf(" ");
printBox(x+2,y);
printMan(x+1,y);
status[x+2][y]='b';
break;
case 'l':
status[x][y-1]='m';
printf(" ");
printBox(x,y-2);
printMan(x,y-1);
status[x][y-2]='b';
break;
case 'r':
status[x][y+1]='m';
printf(" ");
printBox(x,y+2);
printMan(x,y+1);
status[x][y+2]='b';
break;
default:
break;
}
}

void moveBoxSpacetoDes(int x,int y,char a)
{
switch(a)
{
case 'u':
status[x-1][y]=0;
printf(" ");
printBoxDes(x-2,y);
printMan(x-1,y);
status[x-2][y]='i';
break;
case 'd':
status[x+1][y]=0;
printf(" ");
printBoxDes(x+2,y);
printMan(x+1,y);
status[x+2][y]='i';
break;
case 'l':
status[x][y-1]=0;
printf(" ");
printBoxDes(x,y-2);
printMan(x,y-1);
status[x][y-2]='i';
break;
case 'r':
status[x][y+1]=0;
printf(" ");
printBoxDes(x,y+2);
printMan(x,y+1);
status[x][y+2]='i';
break;
default:
break;
}
}

void moveBoxDestoDes(int x,int y,char a)
{
switch(a)
{
case 'u':
status[x-1][y]='m';
printf(" ");
printBoxDes(x-2,y);
printMan(x-1,y);
status[x-2][y]='i';
break;
case 'd':
status[x+1][y]='m';
printf(" ");
printBoxDes(x+2,y);
printMan(x+1,y);
status[x+2][y]='i';
break;
case 'l':
status[x][y-1]='m';
printf(" ");
printBoxDes(x,y-2);
printMan(x,y-1);
status[x][y-2]='i';
break;
case 'r':
status[x][y+1]='m';
printf(" ");
printBoxDes(x,y+2);
printMan(x,y+1);
status[x][y+2]='i';
break;
default:
break;
}
}

int judge(int x,int y)
{
int i;
switch(status[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;
}

void 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)
{
printDestination(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)
{
moveBoxSpacetoSpace(x,y,'u');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x-1);
}
else if(judge(x-2,y)==3)
{
moveBoxSpacetoDes(x,y,'u');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x-1);
}
else
gotoxy(y,x);
break;
}
else if(judge(x-1,y)==4)
{
if(judge(x-2,y)==1)
{
moveBoxDestoSpace(x,y,'u');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x-1);
}
else if(judge(x-2,y)==3)
{
moveBoxDestoDes(x,y,'u');
if(judge(x,y)==3)
printDestination(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)
{
printDestination(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)
{
moveBoxSpacetoSpace(x,y,'d');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x+1);
}
else if(judge(x+2,y)==3)
{
moveBoxSpacetoDes(x,y,'d');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x+1);
}
else
gotoxy(y,x);
break;
}
else if(judge(x+1,y)==4)
{
if(judge(x+2,y)==1)
{
moveBoxDestoSpace(x,y,'d');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y,x+1);
}
else if(judge(x+2,y)==3)
{
moveBoxDestoDes(x,y,'d');
if(judge(x,y)==3)
printDestination(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)
{
printDestination(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)
{
moveBoxSpacetoSpace(x,y,'l');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y-1,x);
}
else if(judge(x,y-2)==3)
{
moveBoxSpacetoDes(x,y,'l');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y-1,x);
}
else
gotoxy(y,x);
break;
}
else if(judge(x,y-1)==4)
{
if(judge(x,y-2)==1)
{
moveBoxDestoSpace(x,y,'l');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y-1,x);
}
else if(judge(x,y-2)==3)
{
moveBoxDestoDes(x,y,'l');
if(judge(x,y)==3)
printDestination(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)
{
printDestination(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)
{
moveBoxSpacetoSpace(x,y,'r');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y+1,x);
}
else if(judge(x,y+2)==3)
{
moveBoxSpacetoDes(x,y,'r');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y+1,x);
}
else
gotoxy(y,x);
break;
}
else if(judge(x,y+1)==4)
{
if(judge(x,y+2)==1)
{
moveBoxDestoSpace(x,y,'r');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y+1,x);
}
else if(judge(x,y+2)==3)
{
moveBoxDestoDes(x,y,'r');
if(judge(x,y)==3)
printDestination(x,y);
gotoxy(y+1,x);
}
else
gotoxy(y,x);
break;
}
default:
break;
}
}

void reset(int i)
{
switch(i)
{
case 0:
init();
initStep1();
break;
case 1:
init();
initStep2();
break;
case 2:
init();
initStep3();
break;
case 3:
init();
initStep4();
break;
default:
break;
}
}

void main()
{
int key;
int x;
int y;
int s;
int i=0;
winer *win;
winer *pw;
_AL=3;
_AH=0;
geninterrupt(0x10);
init();
win=initStep1();
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(status[pw->x][pw->y]=='m')
s++;
pw=pw->p;
}
if(s==0)
{
free(win);
gotoxy(25,2);
printf("congratulate! You have done this step!");
getch();
i++;
switch(i)
{
case 1:
init();
win=initStep2();
break;
case 2:
init();
win=initStep3();
break;
case 3:
init();
win=initStep4();
break;
case 4:
gotoxy(15,21);
printf("Congratulation! \n");
gotoxy(15,23);
printf("You have done all the steps, Welcome to play again!");
key=0x011b;
getch();
break;
default:
break;
}
}

}while(key!=0x011b);
_AL=3;
_AH=0;
geninterrupt(0x10);
}

Ⅶ 用C語言如何編寫推箱子,給個思路唄

#include<stdio.h>

#include <conio.h>

#include <windows.h>

#define R 2//小人

#define B 4//箱子

#define O 3//目的地

#define W 43//牆

#define RO 5//箱子與人重合

#define BO 6//箱子與目的地重合

#define Size 13//數組大小

int main ()

{

printf ("推箱子(1~10關): wasd或↑↓←→控制方向。n下一關。r重新開始。 請注意輸入法是否為小寫英文輸入 ");

system ("pause");

MessageBox (NULL,"第一關"," ",MB_OK);//第一關

int move (char a[Size][Size]);

char a[Size][Size]={0};

int i,j;

void all0 (char a[Size][Size]);

NO1:

all0 (a);

for (i=3;i<6;i++)

a[0][i]=W;

a[1][3]=W;

a[1][5]=W;

for (i=0;i<4;i++)

a[2][i]=W;

a[2][5]=W;

a[3][0]=W;

for (i=0;i<3;i++)

a[4][i]=W;

a[4][7]=W;

for (i=5;i<8;i++)

{

a[3][i]=W;

a[i][2]=W;

a[i][4]=W;

a[5][i]=W;

}

a[7][3]=W;

a[1][4]=O;

a[3][1]=O;

a[4][6]=O;

a[6][3]=O;

a[3][2]=B;

a[3][4]=B;

a[4][4]=B;

a[5][3]=B;

a[4][3]=R;

if (move (a))

{

printf ("WIN ");

system ("pause");

}

else

goto NO1;

MessageBox (NULL,"第二關"," ",MB_OK);//第二關

NO2:

all0 (a);

for (i=0;i<5;i++)

{

a[i][0]=W;

a[0][i]=W;

a[i][4]=W;

}

a[5][2]=W;

a[4][2]=W;

for (i=4;i<9;i++)

a[i][1]=W;

for (i=2;i<6;i++)

a[8][i]=W;

a[6][5]=W;

for (i=5;i<9;i++)

a[7][i]=W;

for (i=2;i<8;i++)

a[i][8]=W;

a[2][7]=W;

for (i=2;i<5;i++)

a[i][6]=W;

a[4][5]=W;

a[1][1]=R;

a[2][2]=B;

a[2][3]=B;

a[3][2]=B;

a[3][7]=O;

a[4][7]=O;

a[5][7]=O;

if (move (a))

{

printf ("WIN ");

system ("pause");

}

else

goto NO2;

MessageBox (NULL,"第三關"," ",MB_OK);//第三關

NO3:

all0 (a);

for (i=1;i<8;i++)

a[0][i]=W;

a[1][1]=W;

for (i=7;i<10;i++)

a[1][i]=W;

for (i=0;i<2;i++)

a[2][i]=W;

for (i=3;i<6;i++)

a[2][i]=W;

a[2][9]=W;

a[3][0]=W;

a[3][9]=W;

a[4][0]=W;

a[4][4]=W;

a[4][9]=W;

a[4][8]=W;

a[5][0]=W;

a[5][1]=W;

a[5][4]=W;

a[5][8]=W;

for (i=1;i<9;i++)

a[6][i]=W;

a[2][2]=B;

a[3][4]=B;

a[3][2]=R;

a[3][7]=B;

a[4][6]=B;

a[4][2]=O;

a[4][3]=O;

a[5][2]=O;

a[5][3]=O;

if (move (a))

{

printf ("WIN ");

system ("pause");

}

else

goto NO3;

MessageBox (NULL,"第四關"," ",MB_OK);//第四關

NO4:

all0 (a);

for (i=1;i<5;i++)

{a[0][i]=W;a[7][i]=W;}

a[1][1]=W;

a[1][4]=W;

a[2][1]=R;

a[2][2]=B;

a[2][4]=W;

a[3][1]=W;

a[3][2]=B;

a[3][4]=W;

a[3][5]=W;

a[4][1]=W;

for (i=1;i<8;i++)

a[i][0]=W;

a[4][3]=B;

a[5][2]=B;

a[5][1]=O;

a[6][1]=O;

a[6][2]=O;

a[6][3]=BO;

a[6][4]=O;

for (i=1;i<4;i++)

a[i][4]=W;

for (i=3;i<8;i++)

a[i][5]=W;

if (move (a))

{

printf ("WIN ");

system ("pause");

}

else

goto NO4;

MessageBox (NULL,"第五關"," ",MB_OK);//第五關

NO5:

all0 (a);

for (i=1;i<6;i++)

a[0][i]=W;

for (i=1;i<4;i++)

a[i][1]=W;

for (i=3;i<8;i++)

a[i][0]=W;

for (i=1;i<8;i++)

a[7][i]=W;

for (i=4;i<7;i++)

{a[1][i]=W;a[i][1]=O;}

for (i=3;i<7;i++)

a[i][7]=W;

a[2][6]=W;

a[3][6]=W;

a[1][2]=R;

a[2][3]=B;

a[3][2]=W;

a[4][2]=W;

a[3][4]=W;

a[4][4]=W;

a[5][5]=W;

a[5][2]=B;

a[6][5]=B;

if (move (a))

{

printf ("WIN ");

system ("pause");

}

else

goto NO5;

MessageBox (NULL,"第六關"," ",MB_OK);//第六關

NO6:

all0 (a);

for (i=1;i<8;i++)

a[i][0]=W;

for (i=7;i<11;i++)

a[i][1]=W;

for (i=1;i<4;i++)

{a[1][i]=W;a[i][9]=W;}

for (i=3;i<10;i++)

a[0][i]=W;

for (i=3;i<8;i++)

a[i][10]=W;

for (i=7;i<11;i++)

a[i][12]=W;

a[7][11]=W;

for (i=2;i<13;i++)

a[10][i]=W;

for (i=3;i<6;i++)

{a[i][2]=W;a[8][i]=W;}

for (i=5;i<8;i++)

{a[2][i]=W;a[i][8]=W;}

a[3][4]=W;

a[6][3]=W;

a[4][7]=W;

a[7][6]=W;

a[9][8]=W;

a[9][7]=W;

a[2][4]=O;

a[6][2]=O;

a[4][8]=O;

a[8][6]=O;

a[4][4]=B;

a[4][6]=B;

a[5][5]=BO;

a[6][4]=B;

a[6][6]=B;

a[8][11]=R;

if (move (a))

{

printf ("WIN ");

system ("pause");

}

else

goto NO6;

MessageBox (NULL,"第七關"," ",MB_OK);//第七關

NO7:

all0 (a);

for (i=3;i<10;i++)

a[0][i]=W;

for (i=1;i<6;i++)

a[i][2]=W;

for (i=5;i<8;i++)

a[i][0]=W;

a[5][1]=W;

a[1][3]=W;

a[6][0]=W;

for (i=0;i<9;i++)

a[7][i]=W;

a[5][8]=W;

a[6][8]=W;

for (i=1;i<6;i++)

a[i][9]=W;

a[1][6]=W;

a[2][6]=W;

a[4][5]=W;

a[4][6]=W;

a[5][6]=W;

a[3][3]=B;

a[3][5]=B;

a[3][7]=B;

a[4][4]=B;

a[5][4]=B;

a[1][8]=R;

for (i=1;i<6;i++)

a[6][i]=O;

if (move (a))

{

printf ("WIN ");

system ("pause");

}

else

goto NO7;

MessageBox (NULL,"第八關"," ",MB_OK);//第八關

NO8:

all0 (a);

for (i=3;i<9;i++)

a[0][i]=W;

for (i=1;i<4;i++)

a[1][i]=W;

a[2][1]=W;

a[1][8]=W;

a[2][8]=W;

for (i=2;i<6;i++)

a[i][0]=W;

for (i=1;i<6;i++)

a[5][i]=W;

for (i=2;i<5;i++)

a[i][9]=W;

for (i=4;i<7;i++)

a[i][8]=W;

for (i=5;i<9;i++)

a[6][i]=W;

a[2][5]=W;

a[2][6]=W;

a[2][4]=B;

a[3][3]=B;

a[3][5]=B;

a[4][4]=B;

a[4][6]=B;

a[3][8]=R;

a[3][1]=O;

a[4][1]=O;

for (i=2;i<5;i++)

a[i][2]=O;

if (move (a))

{

printf ("WIN ");

system ("pause");

}

else

goto NO8;

MessageBox (NULL,"第九關"," ",MB_OK);//第九關

NO9:

all0 (a);

for (i=1;i<10;i++)

{a[0][i]=W;a[8][i]=W;}

for (i=1;i<6;i++)

{a[i][1]=W;a[i][9]=W;}

for (i=5;i<9;i++)

{a[i][0]=W;a[i][10]=W;}

for (i=4;i<7;i++)

{a[3][i]=W;a[4][i]=O;a[5][i]=O;}

a[1][4]=W;

a[1][5]=W;

a[4][3]=W;

a[5][3]=W;

a[4][7]=W;

a[5][7]=W;

a[7][6]=W;

a[2][5]=B;

a[3][2]=B;

a[3][8]=B;

a[6][2]=B;

a[6][5]=B;

a[6][8]=B;

a[7][8]=R;

if (move (a))

{

printf ("WIN ");

system ("pause");

}

else

goto NO9;

MessageBox (NULL,"第十關"," ",MB_OK);//第十關

NO10:

all0 (a);

for (i=2;i<8;i++)

a[0][i]=W;

a[1][2]=W;

for (i=0;i<2;i++)

a[2][i]=W;

for (i=3;i<6;i++)

a[i][0]=W;

for (i=1;i<4;i++)

a[5][i]=W;

for (i=3;i<7;i++)

a[6][i]=W;

for (i=1;i<5;i++)

a[i][7]=W;

a[4][6]=W;

a[5][6]=W;

a[3][1]=R;

for (i=3;i<6;i++)

{a[2][i]=B;a[4][i]=O;}

a[3][3]=B;

a[3][4]=O;

a[3][5]=O;

a[4][2]=B;

if (move (a))

{

printf ("WIN ");

system ("pause");

}

else

goto NO10;

MessageBox(NULL,"恭喜您通關了。"," ",MB_OK);

return 0;

}

int move (char a[Size][Size])//控制小人的移動

{

int condition (char a [Size][Size],int x,int y,int b,int c,int d,int e);

void print ( char a [Size][Size]);

int x,y;

char c;

int i,j;

for (i=0;i<Size;i++)//給小人定位

for (j=0;j<Size;j++)

if (a[i][j]==R)

{ x=i;y=j; }

print (a);

loop:

c=getch();

if (c==0)//如果是鍵盤上下左右鍵用掃描碼

c=getch();

switch(c)

{

case 'n':

case 'N': return 1;//下一關

case 'r':

case 'R': return 0;//返回0,重新開始

case 'w':

case 'W':

case 72: if (condition(a,x,y,x-1,y,x-2,y))x=x-1;break;//上

case 'a':

case 'A':

case 75: if (condition(a,x,y,x,y-1,x,y-2))y=y-1;break;//下

case 's':

case 'S':

case 80: if (condition(a,x,y,x+1,y,x+2,y))x=x+1;break;//左

case 'd':

case 'D':

case 77: if (condition(a,x,y,x,y+1,x,y+2))y=y+1;break;//右

default : goto loop;

}

print (a);

for (i=0;i<Size;i++)//用是否存在箱子作勝利條件

for (j=0;j<Size;j++)

if (a[i][j]==B)

goto loop;

return 1;

}

void print ( char a [Size][Size])//輸出數組函數

{

int i,j;

system ("cls");//清屏函數

for (i=0;i<Size;i++)

{

for (j=0;j<Size;j++)

if (a[i][j]!=0)

printf ("%2c",a[i][j]);

else

printf (" ");

printf (" ");

}

printf (" ");

}

int condition (char a [Size][Size],int x,int y,int b,int c,int d,int e)//小人移動後的情況處理

{

if (a[b][c]!=W)

{

if (a[x][y]==R&&a[b][c]==0)

{a[x][y]=0;a[b][c]=R;return 1;}

if (a[x][y]==RO&&a[b][c]==0)

{a[x][y]=O;a[b][c]=R;return 1;}

if ((a[x][y]==R||a[x][y]==RO)&&(a[b][c]==B||a[b][c]==BO)&&(a[d][e]==B||a[d][e]==BO||a[d][e]==W))

return 0;

if (a[x][y]==R&&a[b][c]==O)

{a[x][y]=0;a[b][c]=RO;return 1;}

if (a[x][y]==RO&&a[b][c]==O)

{a[x][y]=O;a[b][c]=RO;return 1;}

if (a[x][y]==R&&a[b][c]==B&&a[d][e]==O)

{a[x][y]=0;a[b][c]=R;a[d][e]=BO;return 1;}

if (a[x][y]==R&&a[b][c]==B&&a[d][e]==0)

{a[x][y]=0;a[b][c]=R;a[d][e]=B;return 1;}

if (a[x][y]==R&&a[b][c]==BO&&a[d][e]==0)

{a[x][y]=0;a[b][c]=RO;a[d][e]=B;return 1;}

if (a[x][y]==R&&a[b][c]==BO&&a[d][e]==O)

{a[x][y]=0;a[b][c]=RO;a[d][e]=BO;return 1;}

if (a[x][y]==RO&&a[b][c]==B&&a[d][e]==O)

{a[x][y]=O;a[b][c]=R;a[d][e]=BO;return 1;}

if (a[x][y]==RO&&a[b][c]==B&&a[d][e]==0)

{a[x][y]=O;a[b][c]=R;a[d][e]=B;return 1;}

if (a[x][y]==RO&&a[b][c]==BO&&a[d][e]==O)

{a[x][y]=O;a[b][c]=RO;a[d][e]=BO;return 1;}

if (a[x][y]==RO&&a[b][c]==BO&&a[d][e]==0)

{a[x][y]=O;a[b][c]=RO;a[d][e]=B;return 1;}

}

return 0;

}

void all0 (char a[Size][Size])//數組成員歸為0

{

int i,j;

for (i=0;i<Size;i++)

for (j=0;j<Size;j++)

a[i][j]=0;

}


Ⅷ 用匯編語言編寫一個推箱子游戲

出來了,代碼如下:
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,0,0,2,0,2,0
db 0,0,2,0,0,0,0,2,0,0
x dw 10
y dw 10
msg db 'car program finish!!$'
speed dw 5
data ends

code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,0a000h
mov es,ax
mov ax,13h
int 10h
call picture
ag: mov ah,7
int 21h
cmp al,'s'
jne ag
start1: in al,60h
cmp al,80h ;if release key
jae keyrelease
cmp al,2 ;1 key
jz upspeed
cmp al,3 ;2 key
jz downspeed
jmp keyrelease
upspeed:
mov si,speed
inc si
mov speed,si
jmp keyrelease
downspeed:
mov si,speed
dec si
mov speed,si
jmp keyrelease
keyrelease:
call clearpicture
mov si,speed
add si,x
mov x,si
call picture
call delay
mov si,x
cmp si,310
jc start1
mov ah,9
mov dx,offset msg
int 21h
mov ah,7
int 21h
mov ax,4c00h
int 21h

picture proc near
mov dx,y
mov bx,0
again: cmp dx,0
je over
add bx,320
dec dx
jmp again
over: mov dx,9
lea si,car
next1: mov cx,10
mov di,x
next: mov al,[si]
mov es:[bx+di],al
inc si
inc di
loop next
add bx,320
dec dx
jne next1
ret
picture endp

clearpicture proc near
mov dx,y
mov bx,0
again2: cmp dx,0
je over2
add bx,320
dec dx
jmp again2
over2: mov dx,9
next12: mov cx,10
mov di,x
next2: mov al,0
mov es:[bx+di],al
inc di
loop next2
add bx,320
dec dx
jne next12
ret
clearpicture endp

delay proc near
push bx
push cx
mov bx,1234
back:
mov cx,66
push ax
wait1:
in al,61h
and al,10h
cmp al,ah
je wait1
mov ah,al
loop wait1
pop ax
dec bx
jne back
pop cx
pop bx
ret
delay endp

code ends
end start

Ⅸ 請問#include <bios.h>,則個是C語言編寫推箱子的頭文件,用VC++6.0編譯會出錯,請問怎麼解決!!

<bios.h> 這個頭文件是TC專用的頭文件,VC中沒有這個頭文件。

你想寫推箱子程序,不知道怎麼刻畫界面的,如果使用VC的對話框等,則有專門接受鍵盤信息的處理函數。

閱讀全文

與怎麼用推箱子編譯相關的資料

熱點內容
極光電商app是什麼軟體 瀏覽:68
php調用html5 瀏覽:498
修改pdf安卓 瀏覽:475
php方法命名 瀏覽:159
200命令 瀏覽:328
圖庫已存在文件夾 瀏覽:728
U8硬體加密和軟體加密區別 瀏覽:282
android設置啟動頁 瀏覽:115
mt4代碼怎麼加密 瀏覽:100
python的除法運算符 瀏覽:251
程序員逼宮老闆 瀏覽:302
亞馬遜雲伺服器多久會暫停 瀏覽:123
旅居游用什麼app 瀏覽:259
代碼加密後有什麼影響 瀏覽:154
繽紛水母系列解壓 瀏覽:993
mc無敵命令 瀏覽:88
windows核心編程光碟 瀏覽:621
美女和程序員相親視頻 瀏覽:659
你熟悉哪些演算法 瀏覽:771
杭州有什麼伺服器地址 瀏覽:1006