C语言_getcwd函数 c语言getenv函数( 十 )


c语言推箱子//空:0墙:1箱子:3巢:4箱子与巢重合:5
[MAPCOUNT]
map_count=8
[MAP1]
w=8
h=8
nest_count=4
l1=0 0 0 1 1 1 0 0
l2=0 0 0 1 3 1 0 0
l3=1 1 1 1 0 1 0 0
l4=1 3 2 0 2 1 1 1
l5=1 1 1 4 2 0 3 1
l6=0 0 1 2 1 1 1 1
l7=0 0 1 3 1 0 0 0
l8=0 0 1 1 1 0 0 0
[MAP2]
w=9
h=9
nest_count=3
l1=1 1 1 1 1 0 0 0 0
l2=1 4 0 0 1 0 0 0 0
l3=1 0 2 2 1 0 1 1 1
l4=1 0 2 0 1 0 1 3 1
l5=1 1 1 0 1 1 1 3 1
l6=0 1 1 0 0 0 0 3 1
l7=0 1 0 0 0 1 0 0 1
l8=0 1 0 0 0 1 1 1 1
l9=0 1 1 1 1 1 0 0 0
[MAP3]
w=10
h=7
nest_count=4
l1=0 1 1 1 1 1 1 1 0 0
l2=0 1 0 0 0 0 0 1 1 1
l3=1 1 2 1 1 1 0 0 0 1
l4=1 0 4 0 2 0 0 2 0 1
l5=1 0 3 3 1 0 2 0 1 1
l6=1 1 3 3 1 0 0 0 1 0
l7=0 1 1 1 1 1 1 1 1 0
[MAP4]
w=6
h=8
nest_count=5
l1=0 1 1 1 1 0
l2=1 1 0 0 1 0
l3=1 4 2 0 1 0
l4=1 1 2 0 1 1
l5=1 1 0 2 0 1
l6=1 3 2 0 0 1
l7=1 3 3 5 3 1
l8=1 1 1 1 1 1
//以上为地图数据文件,保存为boxdata.dat文件
//空:0墙:1箱子:3巢:4箱子与巢重合:5
#include stdio.h
#include stdlib.h
#include stdbool.h
#include windows.h
#include string.h
typedef struct
{
int x;
int y;
} PT;
int** s;
PT man;
PT* nest=NULL;
PT prev;
int nest_count=0;
int map_count=0;
int gate=1;
int w,h;
char work_dir[100]={'\0'};
char data_file[100]={'\0'};
void GetDataFromFile();
void GetIntFromLineString(char* ch, int len, int i);
void Draw();
bool is_Success();
int main()
{
printf("Loading...");
CONSOLE_CURSOR_INFO cci;
cci.bVisible = FALSE;
cci.dwSize = sizeof(cci);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, cci);
_getcwd(work_dir,100);
strcpy(data_file,work_dir);
strcat(data_file,"\\boxdata.dat");
if(access(data_file,0))
{
printf("Don't find map data file !");
getch();
exit(0);
}
while(1)
{
GetDataFromFile();
int sel=0;
Draw();
while(1)
{
fflush(stdin);
sel=getch();
if(sel==224)
{
sel=getch();
prev=man;
if(sel==77)//right
{
if(s[man.y][man.x+1]==2)
{
if(s[man.y][man.x+2]==0 || s[man.y][man.x+2]==3)
{
s[man.y][man.x+2]=2;
s[man.y][man.x+1]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
else if(s[man.y][man.x+1]==0 || s[man.y][man.x+1]==3)
{
s[man.y][man.x+1]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
else if(sel==80)//down
{
if(s[man.y+1][man.x]==2)
{
if(s[man.y+2][man.x]==0 || s[man.y+2][man.x]==3)
{
s[man.y+2][man.x]=2;
s[man.y+1][man.x]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
else if(s[man.y+1][man.x]==0 || s[man.y+1][man.x]==3)
{
s[man.y+1][man.x]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
else if(sel==72)//up
{
if(s[man.y-1][man.x]==2)
{
if(s[man.y-2][man.x]==0 || s[man.y-2][man.x]==3)
{
s[man.y-2][man.x]=2;
s[man.y-1][man.x]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
else if(s[man.y-1][man.x]==0 || s[man.y-1][man.x]==3)
{
s[man.y-1][man.x]=4;
s[man.y][man.x]=0;
}
else
{
continue;
}
}
else if(sel==75)//left
{
if(s[man.y][man.x-1]==2)
{
if(s[man.y][man.x-2]==0 || s[man.y][man.x-2]==3)

推荐阅读