分享VC下无聊的推箱子!给09的童鞋参考,给我加分也不介意的
#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,0,0,0,0},
{0,0,0,1,3,1,0,0,0,0},
{0,0,0,1,2,1,1,1,1,0},
{0,1,1,1,4,4,2,3,1,0},
{0,1,3,2,4,6,1,1,1,0},
{0,1,1,1,1,4,1,0,0,0},
{0,0,0,0,1,3,1,0,0,0},
{0,0,0,0,1,1,1,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
};
while (true)
{
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;
}
printf("确认找到%d %d",i,j);
input = getch();
switch (input)
{case 'w':
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 's':
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 'a':
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 'd':
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恭喜通关!");
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");
}
}
由于没学图形,所以那几个图标是复制过来的!