#include<stdio.h>
#include<time.h>
#include <windows.h>
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
int i=5,j=5,q=0,w=0,e,r,g,h;
int t=1;
int s[11],d[11]; // fake item position list
int itemi,itemj; // real item position
char fc = '@'; // fake item character
void move(int x, int y)
{
COORD Pos;
Pos.X = y;
Pos.Y = x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
void textcolor(int colorNum) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colorNum);
}
void menu()
{
move(27,5);
printf(" i : %2d j : %2d ",i,j);
printf("'r' = red, 'b' = blue, 'w' = white");
move(28,6);
printf("your score is %d",q);
}
void paint_outline()
{ for(e=1 ;e<=26 ;e++)
{
move(e,1);
printf("#");
}
for(e=1 ;e<=58 ;e++)
{
move(1,e);
printf("#");
}
for(e=1 ;e<=26 ;e++)
{
move(e,58);
printf("#");
}
}
void kilLER()
{
s[t] = rand()%20+1;
d[t] = rand()%50+1;
if(s[t] == 1 || d[t] == 58)
{
s[t]++;
}
if(d == 1)
{
d[t]++;
}
move(s[t],d[t]);
printf("%c",fc);
t++;
}
int main()
{
srand(time(NULL));
char c;
system("color 61");
move(i,j);
printf("*");
menu();
paint_outline();
itemi = rand()%20+1;
itemj = rand()%50+1;
if(itemi == 1 || itemi == 58)
{
itemi++;
}
if(itemj == 1)
{
itemj++;
}
move(itemi,itemj);
printf("@");
move(29,10);
printf("%d",t-1);
kilLER();
int v=0;
while(1)
{
for(g=1 ;g<=t ;g++)
{
move(29,10);
printf("%d",t-1);
if(t == 11)
{
while(1)
{
system("color 29");
system("color 7d");
move(15,10);
printf("YOU WIN ");
}
}
if(i == s[g] && j == d[g])
{
while(1)
{
system("color 7f");
system("color 74");
move(15,10);
printf("GAME OVER ");
}
}
}
for(v=1 ;v<=58 ;v++)
{
if(i == 1 && j == v)
{
system("color 7f");
system("color 74");
move(15,10);
printf("GAME OVER ");
}
}
for(v=1 ;v<=58 ;v++)
{
if(i == v && j == 1)
{
system("color 7f");
system("color 74");
move(15,10);
printf("GAME OVER ");
}
}
for(v=1 ;v<=58 ;v++)
{
if(i == v && j == 58)
{
system("color 7f");
system("color 74");
move(15,10);
printf("GAME OVER ");
}
}
if (_kbhit()) { // 키보드 걔속 입력받기
c = _getch(); //문자하나입력받기 , 만댝 -32가 들어오면 방향키라는뜻
if (c=='r')
{
system("color 6C");
move(26,10);
printf(" ");
printf(" red color");
}
else if (c=='b')
{
system("color 69");
move(26,10);
printf(" ");
printf(" blue color");
}
else if (c=='w')
{
system("color 6F");
move(26,10);
printf(" ");
printf(" white color");
}
else if (c == -32) { //방향키가 들어왔따면
c = _getch(); // 어떤방향키인지?
move(i,j);
printf(" ");
switch (c) {
case LEFT:
if(j == 1)
{
break;
}
j--;
//textcolor(q);
//system("color 69");
break;
case RIGHT:
if(j == 58)
{
break;
}
j++;
//textcolor(q);
//system("color 6D");
break;
case UP:
if(i == 1)
{
break;
}
i--;
//system("color 6A");
break;
case DOWN:
if(i == 25)
{
break;
}
i++;
break;
} // switch (c)
if(i == itemi && j == itemj)
{
q=q+10;
itemi = rand()%20+1;
itemj = rand()%50+1;
if(itemi == 1 || itemi == 58)
{
itemi++;
}
if(itemj == 1)
{
itemj++;
}
move(itemi,itemj);
printf("@");
kilLER();
}
move(i,j);
printf("*");
}
menu();
}
}
return 0;
}
// ㅁㅁㅁㅁㅁ ㅁㅁㅁㅁㅁ
//
// ㅁㅁ ㅁㅁ
// ㅁㅁ ㅁㅁ
// ㅁㅁ
//
// ㅁㅁㅁㅁㅁㅁㅁ
// ㅁ*%#$@&*ㅁ
// ㅁㅁㅁㅁㅁ



