代码
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
main()
{
int i,j,c,flag,sign,counter;
int array[10][10],area,x,y;
for(i=0;i<10;i++)
for(j=0;j<10;j++)
array[i][j]=46;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
printf("%c",array[i][j]);
printf("\n");
}
srand((unsigned)time(NULL));
printf("Notion!While the value of x and y less than 10 and positive integret,\n"
"Please the beginning place of the game (x,y):");
scanf("%d,%d",&x,&y);
array[x][y]=65;
for(c=66;c<=90;c++)
{
do
{
counter=rand()%4;
switch(counter)
{
case 0: /* Moving toward right*/
{
if(array[x][y+1]==46&&y+1<10)
{
array[x][++y]=c;
flag=1;
break;
}
else
{
flag=0;
break;
}
}
/* Moving toward down*/
case 1:
{
if(array[x+1][y]==46&&x+1<10)
{
array[++x][y]=c;
flag=1;
break;
}
else
{
flag=0;
break;
}
}
/* Moving toward left*/
case 2:
{
if(array[x][y-1]==46&&y-1>0)
{
array[x][--y]=c;
flag=1;
break;
}
else
{
flag=0;
break;
}
}
/* Moving toward up*/
case 3:
{
if(array[x-1][y]==46&&x-1>0)
{
array[--x][y]=c;
flag=1;
break;
}
else
{
flag=0;
break;
}
}
}
}while(flag!=1);
flag=0;
sign=(array[x][y+1]==46||array[x][y-1]==46||array[x-1][y]==46||array[x+1][y]==46);
if(sign==0)
break;
}
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
printf("%c",array[i][j]);
printf("\n");
}
getch();
}