走迷宫代码:
#include<stdio.h>
#include<getch.h>
#include<stdlib.h>
int main()
{
char map[10][10] = {
{’#’,’#’,’#’,’#’,’#’,’#’,’#’,’#’,’#’,’#’},
{’#’,’@’,’#’,’ ‘,’ ‘,’ ‘,’#’,’ ‘,’ ‘,’ ‘},
{’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’#’},
{’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’#’},
{’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’#’},
{’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’#’},
{’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’#’},
{’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’ ‘,’#’,’#’},
{’#’,’ ‘,’ ‘,’ ‘,’#’,’ ‘,’ ‘,’ ‘,’#’,’#’},
{’#’,’#’,’#’,’#’,’#’,’#’,’#’,’#’,’#’,’#’}
};
char mouse_x = 1,mouse_y = 1;
time_t start_time = time(NULL);
for(;😉
{
system(“clear”);
for(int i= 0 ;i<10;i++)
{
for(int j =0;j<10;j++)
{
printf("%c",map[i][j]);
}
printf("\n");
}
if(1mouse_x&&9mouse_y)
{ time_t end_time = time(NULL);
printf(“victory,共用时%u秒\n”,end_time-start_time);
return 0;
}
switch(getch())
{
case 183:
if(’ '== map[mouse_x-1][mouse_y])
{
map[mouse_x-1][mouse_y] = ‘@’;
map[mouse_x–][mouse_y] = ’ ‘;
}
break;
case 184:
if(’ '== map[mouse_x+1][mouse_y])
{
map[mouse_x+1][mouse_y] = ‘@’;
map[mouse_x++][mouse_y] = ’ ';
}
break;
case 185:
if(' '== map[mouse_x][mouse_y+1])
{
map[mouse_x][mouse_y+1] = '@';
map[mouse_x][mouse_y++] = ' ';
}
break;
case 186:
if(' '== map[mouse_x][mouse_y-1])
{
map[mouse_x][mouse_y-1] = '@';
map[mouse_x][mouse_y--] = ' ';
}
break;
}
}
}
推箱子代码
#include<stdio.h>
#include<getch.h>
#include<stdlib.h>
int main()
{
int i,j;
int map[8][8]={