准备好盒子三面的图样,新建文件,A4纸大小。
在设置中调整好长、宽、高;前景色为灰色,背景色为黑色,渐变,径向渐变,从文件左下靠中间位置拉动,滤镜,杂色,添加杂色。
做好背景,我们开始拖准备好的,把平面图放大,然后用矩形框框住,要跟取图的部分一样大小,拖到我们的文件中。
用移动工具调整位置。
按住ctrl+t,旋转,大约45°到80°左右,按住ctrl并将鼠标放到上面空块上,把向下按。调好后在按住ctrl将鼠标放到左边上面空块上,把扭曲一点。
先将其右上角对齐,按住ctrl同时将鼠标放在左上角中间的小空块,对齐(放大镜放大,一定要一丝不差的对齐)。按住ctrl同时将鼠标放在左上角下面的小空块,做一点透视,调好以后回车。
将其三张焦点处对齐,按住ctrl同时将鼠标放在右边中间的小空块,对齐上面(放大镜放大,一定要一丝不差的对齐)。按住ctrl同时将鼠标放在下边中间的小空块,将左边对齐,按住ctrl同时将鼠标放在右下角,做一点透视。做好以后回车。这样就做好了。
/TC环境下编的/
#include <dosh>
#include <stdioh>
#include <ctypeh>
#include <conioh>
#include <biosh>
#include <alloch>
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[(x160)+(y<<1)+0]=ch;
printScreen[(x160)+(y<<1)+1]=(bc16)+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);
}
import javautilScanner; public class Temp1 { / @param args / public static void main(String[] args) { Scanner input=new Scanner(Systemin); Systemoutprintln("请输入箱子的长宽高(如:3 4 5):"); new Temp1(inputnextInt(), inputnextInt(), inputnextInt()); } public Temp1(int a,int b,int c) { Systemoutprintln("长"+a+"宽"+b+"高"+c+"的箱子体积为:"+(abc)); } }
推箱子游戏是一款很有趣味的游戏,其开发过程有一定的技巧和方法,其中涉及到软中断、二维数组、键盘 *** 作以及图形化函数等方面的知识。本游戏的开发者需要基本掌握显示器中断寄存器的设置。二维数组及结构体的定义、键盘上键值的获取、图形方式下光标的显示各定位,以及部分图形函数的使用。
具体架构我不说了,直接上代码:
1、程序预处理
程序预处理部分包括加载头文件、定义全局变量和定义数据结构,并对它们进行初始化工作。其中加载头文件的代码如下:
#include <dosh>
#include <stdioh>
#include <ctypeh>
#include <conioh>
#include <biosh>
#include <alloch>
2、初始化模块
该模块主要用于对屏幕和关卡的初始化,初始化关卡时是调用画图模块中画图函数。该模块包括以下几个函数。
(1) void init(),初始化屏幕的大小、显示方式、显示 *** 作提示信息和版权信息。
(2) winer initStep1(),初始化游戏的第一关。
(3) winer initStep2(),初始化游戏的第二关。
(4) winer initStep3(),初始化游戏的第三关。
(5) winer initStep4(),初始化游戏的第四关。
其中初始化屏幕函数的详细代码如下:
void init()
{
int i,j;
for(i=0;i<20;i++)
for(j=0;j<20;j++)
/屏幕2020范围内状态初始化为0,表示什么都没有/
status[i][j]=0;
/设置寄存器AX低位,8025彩色方式显示/
_AL=3;
/设置寄存器AX高位/
_AH=0;
geninterrupt(0x10);
/移动光标到指定位置输出屏幕信息/
gotoxy(41,4);
printf(" --------- up");
gotoxy(41,6);
printf(" --------- down");
gotoxy(41,8);
printf(" --------- left");
gotoxy(41,10);
printf(" --------- right");
gotoxy(40,12);
printf("Space ----- reset");
gotoxy(40,14);
printf("Esc ------- quit");
gotoxy(18,24);
printf("CopyRight: 2008 LuoFuxing");
gotoxy(40,4);
_CX=01;
_AH=0xa;
_AL=24;
geninterrupt(0x10);
gotoxy(40,6);
_CX=01;
_AH=0xa;
_AL=25;
geninterrupt(0x10);
gotoxy(40,8);
_CX=01;
_AH=0xa;
_AL=27;
geninterrupt(0x10);
gotoxy(40,10);
_CX=01;
_AH=0xa;
_AL=26;
geninterrupt(0x10);
}
3、 画图模块
该模块主要用于画图 *** 作,包括画墙、画箱子、画目的地和画小人等。该模块包括以下几个函数。
(1) void printWall(int x,int y),用于画墙。
(2) void printBox(int x,int y),在空白地(非目的地)画箱子。
(3) void printBoxDes(int x,int y),在目的地画箱子。
(4) void printDestination(int x,int y),画目的地函数。
(5) void printDestination1(int x,int y,winer win,winer pw),画目的地函数,并记录每个目的地的位置。
(6) void printMan(int x,int y),画小人函数。
其中画墙函数的代码如下:
void printWall(int x,int y)
{
/以黑色为背景画绿色墙,用小方块表示/
putoutChar(y-1,x-1,219,GREEN,BLACK);
/记录状态为墙/
status[x][y]='w';
}
4、 移动箱子模块
该模块是实现箱子的移动。根据游戏规则,箱子可以在空地之间、目的地之间、空地和目的地之间来回移动,因此,实现本模块共有以下4个函数。
(1) void moveBoxSpacetoSpace(int x,int y,char a),把箱子从空地移动到空地。
(2) void moveBoxDestoSpace(int x,int y,char a),把箱子从目的地移动到空地。
(3) void moveBoxSpacetoDes(int x,int y,char a),把箱子从空地移动到目的地。
(4) void moveBoxDestoDes(int x,int y,char a),把箱子从目的地移动到目的地。
其中从空地移动箱子到空地函数的详细代码如下:
void moveBoxSpacetoSpace(int x,int y,char a)
{
switch(a)
{
/如果按向上键/
case 'u':
/重设((x-1),y)位置的状态为0/
status[x-1][y]=0;
/清空(x,y)处原有的小人/
printf(" ");
/在((x-2),y)处重新画箱子/
printBox(x-2,y);
/在((x-1),y)处重新画小人/
printMan(x-1,y);
/重设((x-2),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;
}
}
5、 移动小人模块
移动小人模块是本程序的核心模块,仅由move()函数来实现。Move()函数控制小人的移动,并调用画图模块、移动箱子模块中的函数来实现箱子的重画、移动等 *** 作。其 *** 作流程可参见图(三)。部分代码如下:
void move(int x,int y,char a)
{
switch(a)
{
/如果按向上键/
case 'u':
/如果(x-1,y)即小人的下一步状态为墙/
if(!judge(x-1,y))
{
/则跳转到(y,x),并跳出循环/
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;
}
/如果下一步状态为0/
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;
}
……
……
6、 功能控制模块
功能控制模块包括屏幕输出功能、关卡重置功能和坐标位置状态的判断功能。该模块包括以下几个函数。
(1) void putoutChar(int y,int x,char fc,char bc),在屏幕上指定的位置输出指定的字符。
(2) int judge(int x,int y),判断位置(x,y)处的状态,状态值可参见“数据结构设计”部分。
(3) void reset (int i),重置关卡。
其中在屏幕上的指定位置输出指定的字符函数的代码如下:
void putoutChar(int y,int x,char ch,char fc,char bc)
{
/屏幕输出字符/
printScreen[(x160)+(y<<1)+0]=ch;
/指定字符颜色fc,背景色bc/
printScreen[(x160)+(y<<1)+1]=(bc16)+fc;
}
7、 主函数
主函数实现整个程序的控制,其游戏 *** 作流程可参见图(二)。详细代码如下:
void main()
{
/记录按下的键/
int key;
int x;
int y;
/记录未被推到目的地的箱子个数/
int s;
/记录已经过了几关/
int i=0;
winer win;
winer pw;
/设置寄存器AX低位/
_AL=3;
/设置寄存器AX高位/
_AH=0;
geninterrupt(0x10);
init();
win=initStep1();
do{
/设置AH,读取光标位置/
_AH=3;
geninterrupt(0x10);
/读取光标所在的行,加1/
x=_DH+1;
/读取光标所在的列,加1/
y=_DL+1;
/bioskey(1)返回0,直到有键按下/
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)
{
/如果目的地的状态为m,不是i,表示还有箱子
未被推到目的地,该关还未完成/
if(status[pw->x][pw->y]=='m')
/未被推到目的地的箱子数/
s++;
/判断下一个目的地的状态/
pw=pw->p;
}
/该关完成/
if(s==0)
{
/释放分配的空间/
free(win);
gotoxy(15,20);
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,22);
printf("You have done all the steps, You are very clever!");
/设置键为Esc以便退出程序/
key=0x011b;
/按任意键结束/
getch();
break;
default:
break;
}
}
}while(key!=0x011b);
_AL=3;
_AH=0;
geninterrupt(0x10);
}
以上就是关于如何用PS做一个长63,宽54,高52cm的纸箱子全部的内容,包括:如何用PS做一个长63,宽54,高52cm的纸箱子、如何用C语言编写一如图模型的推箱子游戏的程序!、编写一个程序,计算箱子的体积,将每个箱子的高度,宽度和长度参数的值传递给构造方法,计算并显示体积等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)