#include
#include
#include
#define Esc 0x011b
#define Up 0x4800
#define Down 0x5000
#define Left 0x4b00
#define Right 0x4d00
#define Max 30 /*地图的最大长宽*/
#define MapX 10
#define MapY 5
#define N 60 /*最多地图数*/
/*全局变量*/
char map[N][Max][Max] =
{
{
" ",
" #### ",
" ### @# ",
" # b # ",
" ## # ### ",
" # # #*# ",
" # # b*# ",
" # b *# ",
" ######## ",
" "
},
{
" #####",
"### #",
"# b # ##",
"# # * #",
"# # #",
"## # #",
" #@ ###",
" #####"
},
{
" ##### ",
" # ##",
"##*#b ##",
"# b #",
"#* *#b #",
"### @ ##",
" # # #",
" # #",
" #####"
},
{
"########",
"# #",
"# b b#",
"##b b #",
"#@bb #",
"# #**b",
"# *****#",
"########"
},
{
"#######",
"# #@#",
"# bb #",
"# # b #",
"# * **#",
"# # #",
"#######"
},
{
"#######",
"### *#",
"# bb# #",
"# @b* #",
"#* b# #",
"# * #",
"#######"
},
{
"########",
"# @ *#",
"# ##bb #",
"# b##",
"##b* b*#",
"# *#b##",
"## * #",
"########"
},
{
"########",
"# * b ##",
"## b*b #",
"#***# *#",
"# #b b #",
"# b #*b#",
"# @ #",
"########"
},
{
"#########",
"# #*# #",
"# bbb*#",
"#bbbb #",
"# b@# #",
"#* ###b##",
"#***** *#",
"#########"
},
{
"#########",
"# #####",
"# b b * #",
"# # && #",
"# b# **#",
"# *& #",
"# bb##&",
"### @* #",
"#########"
},
{
"###########",
"###### ##",
"## ##b ##",
"## # bb ##",
"# ###",
"#* #b # ###",
"#*#* # b #",
"#***# bb#@#",
"# ** b #",
"# ########",
"###########"
},
{
"##########",
"# #",
"# # bb##*#",
"# b b@##*#",
"# bb #*#",
"## bb b**#",
"# #****#",
"##########"
},
{
"###########",
"#*********#",
"# #b####* #",
"# b@# # b #",
"# bbb #",
"#bb ## bb#",
"# # #",
"###########"
},
{
"###########",
"#***** # @#",
"#**## b#b##",
"#* # # b ##",
"#**# b #",
"# b b #",
"#bbb# b ##",
"# # #",
"###########"
},
{
" ## ",
" ## ### ",
" ## b b #",
" # #**#b #",
" # bb#&*# #",
" # ****b #",
" # # *#*# #",
"# b##b#*#b #",
"# @b *b #",
" # # ## #",
" ##### ## "
}
};
int facex=0;
int facey=0;
int boxx[20];
int boxy[20];
int aimx[20];
int aimy[20];
int step=0;
int acout=0;
int whichbox; /*移动的是那个箱子*/
int height=0;
int width=0;
int numofmap; /*共有几个地图*/
int num; /*第几个地图*/
/************************/
/*界面处理*/ /*最后画脸*/
void BeginDirection()
{
gotoxy(20,2);
printf("You are expected\n\t\tto move all the box to the * Position!\n\t\tWish you a good luck!!\t\t\t");
}
void NextDirection()
{
gotoxy(20,2);
printf("Congratulation!!\n\t\tYou have made it successfully!!\t\t\n\t\tPress any key to Enter Next Level");
}
void Level()
{
gotoxy(30,20);
textcolor(YELLOW);
cprintf("LEVEL : %d",num);
}
void PaintWall()
{
int i,j;
textcolor(GREEN);
for(i=0;i
gotoxy(MapX,MapY+i);
for(j=0;j
if(map[num][i][j]=='#') cprintf("%c",219);
else putchar(' ');
}
}
}
void PaintSpace()
{
gotoxy(facex+MapX,facey+MapY);
putchar(' ');
}
void PaintFace()
{
textcolor(YELLOW);
gotoxy(facex+MapX,facey+MapY);
cprintf("%c\b",2);
}
void PaintBox()
{
int i;
textcolor(WHITE);
for(i=0;i
gotoxy(aimx[i]+MapX,aimy[i]+MapY);
cprintf("%c",'*');
}
textcolor(CYAN);
for(i=0;i
gotoxy(boxx[i]+MapX,boxy[i]+MapY);
cprintf("%c",5);
}
}
void PaintAim()
{
int i;
textcolor(WHITE);
for(i=0;i
gotoxy(aimx[i]+MapX,aimy[i]+MapY);
cprintf("%c",'*');
}
}
void RePaintAim()
{
gotoxy(facex+MapX,facey+MapY);
textcolor(WHITE);
cprintf("%c",'*');
}
void PaintExit()
{
clrscr();
gotoxy(30,10);
printf("----------");
gotoxy(30,13);
printf("----------");
gotoxy(30,10);
printf("|");
gotoxy(30,11);
printf("|");
gotoxy(30,12);
printf("|");
gotoxy(40,10);
printf("|");
gotoxy(40,11);
printf("|");
gotoxy(40,12);
printf("|");
gotoxy(32,11);
printf("EXIT?");
gotoxy(32,12);
printf("Y/N ");
}
/************************/
/*事件处理*/
void goUp(int key)
{
if(IsMoveBox(key))
{
whichbox=WhichBox(key);
boxy[whichbox]--;
PaintBox();
PaintSpace();
if(IsAim()) RePaintAim();
facey--;
PaintFace();
}
else
{
PaintSpace();
if(IsAim()) RePaintAim();
facey--;
PaintFace();
}
step++;
gotoxy(60,5);
printf("step : %d",step);
}
void goDown(int key)
{
if(IsMoveBox(key))
{
whichbox=WhichBox(key);
boxy[whichbox]++;
PaintBox();
PaintSpace();
if(IsAim()) RePaintAim();
facey++;
PaintFace();
}
else
{
PaintSpace();
if(IsAim()) RePaintAim();
facey++;
PaintFace();
}
step++;
gotoxy(60,5);
printf("step : %d",step);
}
void goLeft(int key)
{
if(IsMoveBox(key))
{
whichbox=WhichBox(key);
boxx[whichbox]--;
PaintBox();
PaintSpace();
if(IsAim()) RePaintAim();
facex--;
PaintFace();
}
else
{
PaintSpace();
if(IsAim()) RePaintAim();
facex--;
PaintFace();
}
step++;
gotoxy(60,5);
printf("step : %d",step);
}
void goRight(int key)
{
if(IsMoveBox(key))
{
whichbox=WhichBox(key);
boxx[whichbox]++;
PaintBox();
PaintSpace();
if(IsAim()) RePaintAim();
facex++;
PaintFace();
}
else
{
PaintSpace();
if(IsAim()) RePaintAim();
facex++;
PaintFace();
}
step++;
gotoxy(60,5);
printf("step : %d",step);
}
/*逻辑处理*/
void Howmanymap()
{
int i;
for(i=0;map[i][0][0]!='\0';i++);
numofmap=i;
}
void seekPosition() /*找出各对像的位置*/
{
int i,j,k=0,p=0,t=0;
for(i=0;i
for(j=0;j
if(map[num][i][j]=='b')
{
boxx[k]=j;
boxy[k]=i;
k++ ;
map[num][i][j]=' ';
}
if(map[num][i][j]=='*')
{
aimx[p]=j;
aimy[p]=i;
p++;
map[num][i][j]=' ';
}
if(map[num][i][j]=='&') /*处理初始时箱子覆盖目标的情况*/
{
boxx[k]=j;
boxy[k]=i;
k++;
aimx[p]=j;
aimy[p]=i;
p++;
map[num][i][j]=' '; /*也同样把它清成空格*/
}
if(map[num][i][j]=='@')
{
facex=j;
facey=i;
map[num][i][j]=' ';
}
if(map[num][i][j]=='\0')
{
t=j;
break;
}
}
if(t>width) width=t;
if(map[num][i][0]=='\0')
{
height=i;
break;
}
}
acout=k;
}
int Exit() /*退出时的界面*/
{
char c;
PaintExit();
scanf("%c",&c);
if(c=='Y'||c=='y') return 1;
else return 0;
}
/***********************/
/***********************/
/*条件判断*/
int CanMove(int key) /*是否能移动*/
{
int can=0;
int i,j;
switch(key)
{
case Up: if(map[num][facey-1][facex]==' ')
{
if(!IsBox(facex,facey-1)) can=1;
else
{
if(map[num][facey-2][facex]==' ')
{
if(!IsBox(facex,facey-2)) can=1;
}
}
}
break;
case Down: if(map[num][facey+1][facex]==' ')
{
if(!IsBox(facex,facey+1)) can=1;
else
{
if(map[num][facey+2][facex]==' ')
{
if(!IsBox(facex,facey+2)) can=1;
}
}
}
break;
case Left: if(map[num][facey][facex-1]==' ')
{
if(!IsBox(facex-1,facey)) can=1;
else
{
if(map[num][facey][facex-2]==' ')
{
if(!IsBox(facex-2,facey)) can=1;
}
}
}
break;
case Right: if(map[num][facey][facex+1]==' ')
{
if(!IsBox(facex+1,facey)) can=1;
else
{
if(map[num][facey][facex+2]==' ')
{
if(!IsBox(facex+2,facey)) can=1;
}
}
}
break;
}
return can;
}
int WhichBox(int key)
{
int i,whichbox;
switch(key)
{
case Up: for(i=0;i
if(boxx[i]==facex && boxy[i]==facey-1)
break;
}
whichbox=i;
break;
case Down: for(i=0;i
if(boxx[i]==facex && boxy[i]==facey+1)
break;
}
whichbox=i;
break;
case Left: for(i=0;i
if(boxx[i]==facex-1 && boxy[i]==facey)
break;
}
whichbox=i;
break;
case Right: for(i=0;i
if(boxx[i]==facex+1 && boxy[i]==facey)
break;
}
whichbox=i;
break;
}
return whichbox;
}
int IsMoveBox(int key) /*是否在移动箱子*/
{
int yes=0;
switch(key)
{
case Up: if(map[num][facey-1][facex]==' ')
{
if(IsBox(facex,facey-1))
{
if(map[num][facey-2][facex]==' ')
{
if(!IsBox(facex,facey-2)) yes=1;
}
}
}
break;
case Down: if(map[num][facey+1][facex]==' ')
{
if(IsBox(facex,facey+1))
{
if(map[num][facey+2][facex]==' ')
{
if(!IsBox(facex,facey+2)) yes=1;
}
}
}
break;
case Left: if(map[num][facey][facex-1]==' ')
{
if(IsBox(facex-1,facey))
{
if(map[num][facey][facex-2]==' ')
{
if(!IsBox(facex-2,facey)) yes=1;
}
}
}
break;
case Right: if(map[num][facey][facex+1]==' ')
{
if(IsBox(facex+1,facey))
{
if(map[num][facey][facex+2]==' ')
{
if(!IsBox(facex+2,facey)) yes=1;
}
}
}
break;
}
return yes;
}
int IsBox(int x,int y)
{
int i;
for(i=0;i
if(boxx[i]==x&&boxy[i]==y)
break;
}
if(i
}
int IsAim()
{
int i;
for(i=0;i
if(facex==aimx[i] && facey==aimy[i])
break;
}
if(i
}
int IsWin()
{
int i,j;
int flag=0;
for(i=0;i
for(j=0;j
if(boxx[i]==aimx[j] && boxy[i]==aimy[j])
flag++;
}
}
if(flag==acout) return 1;
else return 0;
}
/***********************/
int main()
{
int i,j,k,t;
int key;
Howmanymap();
for(i=0;i
clrscr();
num=i; /*gotoxy(1,1);printf("%d\t%d\t%d",height,width,acout);*/
Level();
BeginDirection();
seekPosition();
gotoxy(1,1);printf("%d\t%d\t%d\t%d\t%c",height,width,acout,numofmap,map[num][0][0]); /*检测位置大小*/
PaintWall(); /*画墙*/
PaintAim();
PaintBox();
PaintFace();
gotoxy(60,5);
printf("step : %d",step);
key=0;
while(key!=Esc)
{
key = bioskey(0); /*获得键值*/
switch(key)
{
case Up: if(CanMove(key)) goUp(key); break;
case Down: if(CanMove(key)) goDown(key); break;
case Left: if(CanMove(key)) goLeft(key); break;
case Right: if(CanMove(key)) goRight(key);break;
default : break;
}
if(IsWin())
{
step=0;
textcolor(WHITE);
NextDirection();
break;
}
}
getch();
if(key==Esc)
{
if(Exit())break;
else continue;
}
}
}
打开QQ空间相册,随便一个相册选择添加图片,会有一个选择本地图片的,然后在把喜欢的照片添加进去选择上传就好了
选择图片点击图片另存为然后存到收藏夹再到空间点击上传照片再点普通上传按一下选择图片然后选我点击开始上传就好了
在空间主页点相册,在左上角有上传照片按钮。添加图片即可。