///◎,⊙
#include<stdio.h>
#include<windows.h>
#include <stdlib.h> //srand, rand를 사용하기 위한 헤더파일
#include <time.h> // time을 사용하기 위한 헤더파일
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
int len=50;
int ix, iy; //item의 위치
int x=25;
int y=25;
int hx,hy;
int h=1;
void gotoxy(int x, int y)
{
COORD Pos = {(x - 1)*2, (y - 1)};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
void view_map()
{
for(int j=1;j<=len;j++)
{
for(int i=1;i<=len;i++)
{
gotoxy(i,j);
if(i==1||j==1||i==len||j==len)
{
printf("*");
}
else if(i==x&&j==y){
printf("@");
}
else if(i==ix&&j==iy ){
printf("~");
}
else if(i==hx&&j==hy)
{
printf("⊙");
}
else
{
printf(" ");
}
}
}
}
void make_item()
{
ix = rand()%(len-2)+2;
iy = rand()%(len-2)+2;
}
void make_health_itme()
{
hx = rand()%(len-2)+2;
hy = rand()%(len-2)+2;
}
int main()
{
system( "mode con lines=55 cols=110" );
int dir=0,n;
char c;
srand(time(NULL));
make_item();
make_health_itme();
view_map();
for (;;) {
if (_kbhit()) { //키보드 입력 확인 (true / false)
c = _getch();
if (c == -32) { //방향키입력했을때
c = _getch();
switch (c) {
case LEFT:
dir=1;
if(x-1>1) x-=1;
break;
case RIGHT:
dir=2;
if(x+1<len) x+=1;
break;
case UP:
if(y-1>1) y-=1;
break;
case DOWN:
if(y+1<len) y+=1;
break;
}
}
if(x==hx&&y==hy && h<=5)
{
h+=1;
make_health_itme();
}
if(x==ix&&y==iy) //만나면 바로쥬금 -> 수정
{
if(h==0)
{
system("cls");
Sleep(500);
gotoxy(x,y); printf("@=Die");
Sleep(500);
system("cls");
Sleep(500);
gotoxy(x,y); printf("@=Die");
Sleep(500);
system("cls");
Sleep(500);
gotoxy(x,y); printf("FALL");
Sleep(2000);
system("cls");
make_item();
}
else
{
Sleep(1000);
}
}
view_map();
gotoxy(2,52); printf("플레이어위치 : x = %2d y = %2d \n",x,y);
printf("아이템의위치 : ix = %2d iy = %2d \n",ix,iy);
if(h==1)
{
printf("생명:⊙◎◎◎◎");
}
else if(h==2)
{
printf("생명:⊙⊙◎◎◎");
}
else if(h==3)
{
printf("생명:⊙⊙⊙◎◎");
}
else if(h==4)
{
printf("생명:⊙⊙⊙⊙◎");
}
else
{
printf("생명:⊙⊙⊙⊙⊙");
}
}
}
}