#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=0,r=1;
srand(time(NULL));
for(i=1; i<=25; i++)
{
for(o=1; o<=25; o++)
{
if(i==1||o==1||o==25||i==25)
{
gotoxy(i,o);
printf("#");
map[i][o]=5;
}
printf(" ");
}
printf("\n");
}
while(1)
{
if(ax==1)
{
ax++;
}
if(v==0)
{
if(2>rand()%10)
{
rx=rand()%24+1;
ry=rand()%24+1;
gotoxy(rx,ry);
printf("@");
map[rx][ry]=9;
v=1;
}
}
ax=rx;
ay=ry;
{
gotoxy(sx,sy);
printf(" ");
sx += directX;
sy += directY;
gotoxy(sx,sy);
printf("+");
if(r==0)
{
gotoxy(sx,sy);
setColor(2);
printf("!");
Sleep(2000);
for(i=1;i<=100;i++)
{
for(o=1;o<=25;o++)
{
gotoxy(i,o);
printf(" ");
}
}
gotoxy(50,20);
printf("game over");
Sleep(500);
gotoxy(1,1);
break;
}
if(kbhit())
{
x = getch();
switch(x)
{
case LEFT:
directX = -1;
directY=0;
break;
case RIGHT:
directX = 1;
directY=0;
break;
case UP:
directY=-1;
directX=0;
break;
case DOWN:
directY=1;
directX=0;
break;
}
}
if(map[sx+directX][sy+directY]==9)
{
map[rx][ry]=0;
gotoxy(ax+directX,ay+directY);
printf(" ");
f++;
v=0;
}gotoxy(70,20);printf("먹은사과 %d",f);
if(map[sx+directX][sy+directY]==5)
{
r=0;
}
}
Sleep(100);
}
}