#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<windows.h>
#include<string.h>
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define ATTACK 32
int mapArr[100][100];
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void setColor(int color, int bgcolor)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), ((bgcolor&0xf)<<4) | (color&0xf));
}
void map()
{
int i, j;
for(i=5; i<30; i++)
{
for(j=5; j<30; j++)
{
if(i==5||j==5||i==29||j==29)
{
gotoxy(i, j);
setColor(12, 15);
printf("&");
mapArr[i][j] = 8;
setColor(15, 0);
}
}
}
}
int main()
{
int a,b;
int Score=0;
char key;
int x=17, y=28;
int enemyCount=0;
int mx,my;
srand(time(NULL));
gotoxy(x, y);
printf("*");
map();
a=1;
while(1)
{
Sleep(200);
gotoxy(40,5);
printf("%d",Score);
if(enemyCount<1)
{
mx=rand()%15+6;
my=rand()%15+6;
gotoxy(mx,my);
printf("#");
mapArr[mx][my]=1;
enemyCount++;
}
if(kbhit())
{
b=a;
key=getch();
switch(key)
{
case DOWN:
a=3;
break;
case UP:
a=1;
break;
case LEFT:
a=2;
break;
case RIGHT:
a=4;
}
}
if(a==1&&b!=3)
{
gotoxy(x,y);
printf(" ");
mapArr[x][y]=0;
y--;
if(y==5)
{
return 0;
}
if(mapArr[x][y]==1)
{
enemyCount--;
Score++;
}
}
if(a==2&&b!=4)
{
gotoxy(x,y);
printf(" ");
mapArr[x][y]=0;
x--;
if(x==5)
{
return 0;
}
if(mapArr[x][y]==1)
{
enemyCount--;
Score++;
}
}
if(a==3&&b!=1)
{
gotoxy(x,y);
printf(" ");
mapArr[x][y]=0;
y++;
if(y==29)
{
return 0;
}
if(mapArr[x][y]==1)
{
enemyCount--;
Score++;
}
}
if(a==4&&b!=2)
{
gotoxy(x,y);
printf(" ");
mapArr[x][y]=0;
x++;
if(x==29)
{
return 0;
}
if(mapArr[x][y]==1)
{
enemyCount--;
Score++;
}
}
if(a==1&&b==3)
{
a=3;
}
if(a==3&&b==1)
{
a=1;
}
if(a==2&&b==4)
{
a=4;
}
if(a==4&&b==2)
{
a=2;
}
gotoxy(x,y);
printf("*");
mapArr[x][y]=9;
}
return 0;
}