求助大神,帮我把推箱子这个程序代码写完整来,别人写的,代码不够完善,箱子推不上去呀?????
#include <stdio.h>#include <stdlib.h>
#include <conio.h>
int i,j;
void MAP(int map[10][10]);
int main()
{
char input;
int point=0;
int map[10][10] = {
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,1,1,1,1,0,0,0},
{0,0,0,1,3,3,1,0,0,0},
{0,0,1,1,2,3,1,1,0,0},
{0,0,1,2,4,4,3,1,0,0},
{0,1,1,2,2,2,2,1,1,0},
{0,1,2,2,1,4,4,2,1,0},
{0,1,2,2,2,6,2,2,1,0},
{0,1,1,1,1,1,1,1,1,0},
{0,0,0,0,0,0,0,0,0,0},
};
while (1)
{
system("CLS");
MAP(map);
//找到初始位置
for (i=0;i<10;i++)
{
for (j=0;j<10;j++)
{
if (map[i][j]==6)
break;
}
if (map[i][j]==6)
break;
}
input = getch();
switch (input)
{case 72://上移
if(map[i-1][j]==2)
{
map[i][j]=2;
map[i-1][j]=6;
}
if(map[i-1][j]==4)
{
if (map[i-2][j]==2)
{
map[i][j]=2;
map[i-1][j]=6;
map[i-2][j]=4;
}
if (map[i-2][j]==3)
{
map[i][j]=2;
map[i-1][j]=6;
map[i-2][j]=5;
point++;
}
}
break;
case 80://下移
if(map[i+1][j]==2)
{
map[i][j]=2;
map[i+1][j]=6;
}
else if(map[i+1][j]==4)
{
if (map[i+2][j]==2)
{
map[i][j]=2;
map[i+1][j]=6;
map[i+2][j]=4;
}
else if (map[i+2][j]==3)
{
map[i][j]=2;
map[i+1][j]=6;
map[i+2][j]=5;
point++;
}
}
break;
case 75://左移
if(map[i][j-1]==2)
{
map[i][j]=2;
map[i][j-1]=6;
}
else if(map[i][j-1]==4)
{
if (map[i][j-2]==2)
{
map[i][j]=2;
map[i][j-1]=6;
map[i][j-2]=4;
}
else if (map[i][j-2]==3)
{
map[i][j]=2;
map[i][j-1]=6;
map[i][j-2]=5;
point++;
}
}
break;
case 77://右移
if(map[i][j+1]==2)
{
map[i][j]=2;
map[i][j+1]=6;
}
else if(map[i][j+1]==4)
{
if (map[i][j+2]==2)
{
map[i][j]=2;
map[i][j+1]=6;
map[i][j+2]=4;
}
else if (map[i][j+2]==3)
{
map[i][j]=2;
map[i][j+1]=6;
map[i][j+2]=5;
point++;
}
}
break;
}
if (point==4)
{
system("CLS");
MAP(map);
break;
}
}
printf("\n恭喜通关!\n");
return 0;
}
void MAP(int map[10][10])
{
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
switch(map[i][j])
{
case 0:
printf(" ");
break;
case 1:
printf("■");
break;
case 2:
printf(" ");
break;
case 3:
printf("×");
break;
case 4:
printf("◎");
break;
case 5:
printf("☆");
break;
case 6:
printf("♂");
break;
}
}
printf("\n");
}
}