#include <stdio.h>
#include <windows.h>
#include <Windows.h>
#include <conio.h>
#include <stdlib.h>
#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
#include <process.h>
#include <stdlib.h>
#include <time.h>
int player[2]={57,25},end=0,start=0,random=0,t=0,atacker[2]={0,0},oneandom,twoandom,random;
//x=14 9칸 이동
//y=6 9칸 이동
char map[128][56]={};
int cluck(){
while(end!=1)
{
Sleep(1000);
t++;
}
}
void setcolor(unsigned short text, unsigned short back){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), text | (back << 4));
}
void gotoxy(int x, int y){
COORD pos={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void mapload(){
int xwall,ywall;
for(ywall=0;ywall<=55;ywall++)
{
for(xwall=0;xwall<=128;xwall++)
{
printf("%c",map[xwall][ywall]);
}
printf("\n");
}
}
int play(){
setcolor(12, 0);
char heart[6][100]={" #### #### ","##############","##############"," ########## "," ###### "," ## "};
gotoxy(player[0],player[1]);
for(int i=0, x=player[1];i<6;i++,x++)
{
gotoxy(player[0],x);
printf("%s\n",heart[i]);
}
setcolor(14, 0);
char hurt[100]={"!!!!!!!!!!!!!!"};
switch(random%2)
{
case 1:gotoxy(oneandom*6,twoandom*14);break;
case 2:gotoxy(twoandom*6,oneandom*14);break;
}
for(int i=0;i<6;i++){
printf("%s\n",hurt);
}
gotoxy(0,56);
setcolor(15, 0);
printf("time %d",t);
}
int notplay(){
char heart[6][100]={" "," "," "," "," "," "};
gotoxy(player[0],player[1]);
for(int i=0, x=player[1];i<6;i++,x++){
gotoxy(player[0],x);
printf("%s\n",heart[i]);
}
}
int scan(){
char c;
if (_kbhit()) { //키보드 입력 확인 (true / false)
c = _getch(); // 방향키 입력시 224 00이 들어오게 되기에 앞에 있는 값 224를 없앰
if (c == -32) { // -32로 입력되면
c = _getch(); // 새로 입력값을 판별하여 상하좌우 출력
switch (c) {
case 75:
//printf("왼쪽으로 이동\n");
if(player[0]>2)
player[0]-=14;
break;
case 77:
//printf("오른쪽으로 이동\n");
if(player[0]<113)
player[0]+=14;
break;
case 72:
//printf("위로 이동\n");
if(player[1]!=1)
player[1]-=6;
break;
case 80:
//printf("아래로 이동\n");
if(player[1]<48)
player[1]+=6;
break;
}
//gotoxy(player[0],player[1]);
//play();
}
}
}
int move(){
while(end!=1)
{
play();
Sleep(50);
notplay();
scan();
return 0;
}
}
int tack(){
srand(time(NULL));
oneandom= (rand() % 9)+1;
srand(time(NULL));
random = (rand() % 4)+1;
switch(random%2)
{
case 1: for(twoandom=1;twoandom<10;twoandom++){Sleep(500);}break;
case 2: for(twoandom=9;twoandom>0;twoandom--){Sleep(500);}break;
}
}/*
}
int atack(){
while(end!=1){
_beginthreadex(NULL, 0, tack, 0, 0, NULL);
Sleep(1500);
}
}*/
int main(){
setcolor(15, 0);
system("title heart");
system("mode con:cols=200 lines=200");
int xwall,ywall;
Sleep(2000);
for(ywall=0;ywall<=55;ywall++)
{
for(xwall=0;xwall<=128;xwall++)
{
if(xwall==0||xwall==128||ywall==0||ywall==55)
map[xwall][ywall]='#';
else
map[xwall][ywall]=' ';
}
}
mapload();
_beginthreadex(NULL, 0, cluck, 0, 0, NULL);
/*beginthreadex(NULL, 0, atack, 0, 0, NULL);*/
_beginthreadex(NULL, 0, move, 0, 0, NULL);
while(t<60){
_beginthreadex(NULL, 0, tack, 0, 0, NULL);
Sleep(1500);
}
end=1;
Sleep(10);
gotoxy(0,56);
setcolor(15, 0);
printf(" ");
setcolor(15, 0);
gotoxy(57,25);
printf("time 60");
gotoxy(57,26);
}
// https://m.blog.naver.com/dgsw102/221235029416