#include <stdio.h>
#include <math.h>
#include <time.h>
#include <windows.h>
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
int map[500][500] = {0};
void f()
{
}
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int main()
{
char n;
int a=5,b=5,x=0,y=0,v=0,i,j,d=0,l,e,bx=0,by=0;
srand(time(NULL));
for(;;)
{
gotoxy(bx,by);
printf (" ");
map[bx][by]=0;
l = rand()%30;
e = rand()%30;
gotoxy(l,e);
printf ("*");
map [l][e]=4;
bx=l;
by=e;
for (i=1; i<=30; i++)
{
for (j=1; j<=30; j++)
{
gotoxy(i+50,j);
printf ("%d", map[i][j]);
}
printf("\n");
}
gotoxy(0,0);
Sleep(2000);
while(1)
{
gotoxy(a,b);
printf(" ");
a=a+x;
b=b+y;
if (map[a][b]=0)
{
break;
}
gotoxy(a,b);
printf("0");
if (kbhit())
{
n = getch();
switch (n)
{
case LEFT:
x=-1;
y=0;
break;
case RIGHT:
x=1;
y=0;
break;
case UP:
y=-1;
x=0;
break;
case DOWN:
y=1;
x=0;
break;
}
}
if (x!=0)
{
Sleep(20);
}
else
{
Sleep(40);
}
}
}
return 0;
}