#include <stdio.h>
#include<math.h>
#include <time.h>
#include <windows.h>
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
#define SPACE 32
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,sas=1,v=0,f=0,r=1,px=10,py=10,hp=3,pk=0,pdk=1,pd=0,sax,say,sa[3]={0,1,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");
}
//폭탄위치 설정
px=rand()%24+1;
py=rand()%24+1;
gotoxy(px,py);
printf("$");
map[px][py]=3;
//반복
while(1)
{
if(hp>0)
{
//3초마다다 한번씩
if(pk==30)
{
//십자모양 폭탄 출력과정
for(i=0; i<=2; i++)
{
if(map[px][py-1+i]==5)
{
gotoxy(px,py-1+i);
printf("#");
}
else
{
gotoxy(px,py-1+i);
printf("$");
map[px][py-1+i]=3;
}
}
for(i=0; i<=2; i++)
{
if(map[px-1+i][py]==5)
{
gotoxy(px-1+i,py);
printf("#");
}
else
{
gotoxy(px-1+i,py);
printf("$");
map[px-1+i][py]=3;
}
}
//폭탄터짐 신호
pdk=0;
//카운트다운 준비
pk=0;
}
pk++;
if(pdk==0)
{
//폭탄터짐 신호라면?
//카운트 다운
pd++;
}
if(pd==10)
{//1초가 지났다면?
//다지우기
for(i=0; i<=2; i++)
{
gotoxy(px,py-1+i);
printf(" ");
map[px][py-1+i]=0;
}
for(i=0; i<=2; i++)
{
gotoxy(px-1+i,py);
printf(" ");
map[px-1+i][py]=0;
}
//또다른 폭탄 만들기
px=rand()%24+1;
py=rand()%24+1;
gotoxy(px,py);
printf("$");
map[px][py]=3;
//이제는 카운트 않하고 카운트는=0
pd=0;
pdk=1;
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");
}
}
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("남은몫슴 %d개",hp);
Sleep(500);
gotoxy(1,1);
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");
}
sx=10;
sy=10;
hp--;
r=1;
}
if(sas==0)
{
gotoxy(sax,say);
printf(" ");
sax=sx;
say=sy;
sas=1;
}
if(sa[2]==0)
{
gotoxy(sax,say);
printf(" ");
map[sax][say]=0;
gotoxy(sax+sa[1],say);
printf("*");
sax+=sa[1];
map[sax][say]=8;
}
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;
case SPACE:
//오른쪽으로 가고있다면?
sas=0;
if(directX==1)
{//sa[1]를 1 즉 오른쪽으로 한다
sa[1]=1;
//sa[2]0으로 바꾼 이유는 x좌표를 움직여야 하기 때문이다
sa[2]=0;
sa[3]=1;
}
//위와 같다 ....
if(directX==-1)
{
sa[1] =-1;
sa[2]=0;
sa[3]=1;
}
if(directY==1)
{
sa[1] =1;
sa[3]=0;
sa[2]=1;
}
if(directY==-1)
{
sa[1]=-1;
sa[3]=0;
sa[2]=1;
}
}
}
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||map[sx+directX][sy+directY]==3)
{
r=0;
}
}
Sleep(100);
}
else
{
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;
}
}
}