#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[50][50] = {0};
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void setColor(int x)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);
}
int main()
{
char x;
int sx = 5, sy = 5, directX = 0, directY = 0,yju = 0,yjd = 0,a[101][2],b=4,i,o,rx,ry,ax=0,ay=0,u=0,v=0,f;
for(i=1; i<=25; i++)
{
for(o=1; o<=25; o++)
{
if(i==1||o==1||o==25||i==25)
{
setColor(4);
gotoxy(i,o);
printf("#");
map[i][o]=5;
setColor(1);
}
printf(" ");
}
printf("\n");
}
while(1)
{
if(ax==1)
{
ax=ax+1;
}
gotoxy(ax,ay);
printf(" ");
map[ax][ay]=0;
if(v==0)
{
if(2>rand()%10)
{
rx=rand()%24;
ry=rand()%24;
gotoxy(rx,ry);
printf("@");
map[rx][ry]=9;
v=1
}
}
ax=rx;
ay=ry;
for(i=1; i<=25; i++)
{
for(o=1; o<=25; o++)
{
gotoxy(i+30,o);
if(map[i][o]==5||map[i][o]==9)
{
setColor(4);
}
else
{
setColor(1);
}
printf("%d",map[i][o]);
}
printf("\n");
}
// for(i=1;i<2;i++)
{
gotoxy(sx,sy);
printf(" ");
sx += directX;
sy += directY;
gotoxy(sx,sy);
printf("+");
if(kbhit())
{
x = getch();
switch(x)
{
case LEFT:
directX = -1;
directY=0;
//printf("LEFT");
break;
case RIGHT:
directX = 1;
directY=0;
//printf("RIGHT");
break;
case UP:
directY=-1;
directX=0;
break;
case DOWN:
directY=1;
directX=0;
break;
}
}
}
Sleep(300);
}
}