#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];
int xb=17,yb=17;
int d;
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,c,d,i;
int Score=0;
char key;
int x=17, y=28;
int enemyCount=0;
int mx,my;
float deathTime = 30;
int enemyMc = 0;
int enemyDirect = -1; // 1, 2, 3, 4
srand(time(NULL));
gotoxy(x, y);
printf("*");
map();
a=1;
while(1)
{
Sleep(100);
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(6,2);
deathTime -= 0.1;
printf("LIFE TIME:%03.2f S", deathTime);
if(deathTime<=0)
{
return 0;
}
if(mapArr[x][y]==1)
{
deathTime += 5;
}
gotoxy(x,y);
printf("*");
mapArr[x][y]=9;
/*
for(d=0; d<Score; d++)
{
xb=xa[d]-xa[d+2];
yb=ya[d]-ya[d+2];
gotoxy(xa[d+2],ya[d+2]);
printf(" ");
gotoxy(xa[d+2]+xb,ya[d+2]+yb);
printf("*");
}
*/
if(enemyMc==0)
{
enemyMc = rand()%10+1; // 1~ 10
// 방향 설정하기는 희권이의 목 1
enemyDirect = rand()%4+1; // 1~ 4
}
else
{
// enemyMc != 0
// xb, yb
mapArr[xb][yb] = 0;
switch(enemyDirect)
{
// 벽 생각은 하지 않고 일단 하기 2
case 1:
gotoxy(xb,yb);
printf(" ");
if(mapArr[xb][yb-1]==8)
{
enemyMc = 1;
break;
}
else
{
yb--;
gotoxy(xb,yb);
printf("@");
}
break;
case 2:
gotoxy(xb,yb);
printf(" ");
if(mapArr[xb][yb+1]==8)
{
enemyMc = 1;
break;
}
else
{
yb++;
gotoxy(xb,yb);
printf("@");
}
break;
case 3:
gotoxy(xb,yb);
printf(" ");
if(mapArr[xb-1][yb]==8)
{
enemyMc = 1;
break;
}
else
{
xb--;
gotoxy(xb,yb);
printf("@");
}
break;
case 4:
gotoxy(xb,yb);
printf(" ");
if(mapArr[xb+1][yb]==8)
{
enemyMc = 1;
break;
}
else
{
xb++;
gotoxy(xb,yb);
printf("@");
}
break;
default:
break;
}
mapArr[xb][yb] = 5;
enemyMc--;
}
gotoxy(5,3);
setColor(15,15);
printf(" ");
setColor(15,0);
for(d=0; d<deathTime/5-1; d++)
{
gotoxy(d+5,3);
setColor(12,12);
printf(" ");
setColor(15,0);
}
}
return 0;
}