//#include <stdio.h>
//int main()
//{
// int n;
// scanf("%d", &n);
// printf("2 ");
// while (n!=0)
// {
// printf("%d", n%2);
// n=n/2;
// }
// printf("8 ");
//
// return 0;
//}
// rand() -> 0 ~ 42742사이의 랜덤 정수
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
int itemx=10,itemy=10;
int itemx2=0, itemy2=0;
void move(int x, int y)
{
COORD Pos;
Pos.X = x;
Pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
int main()
{
int is_2nd = 0;
srand(time(NULL));
int sum=0;
int x = 3, y = 5;
move(0,23);
printf("x : %02d y : %02d",x,y);
itemx = rand()%29+1 ;
itemy = rand()%18+2 ;
move (itemx, itemy); //item 출력
printf("1");
move(x,y); //player 출력
printf("0");
move(0, 0);
printf("score : %d", sum);
move (0, 22);
printf("STAGE 1"); //stage 1\
move (0, 1);
for (int i=1 ; i<=31 ; i++)
{
printf("*");
}
move (0, 21);
for (int i=1 ; i<=31 ; i++)
{
printf("*");
}
for (int i=1 ; i<=20 ; i++)
{
move (0, i);
printf("*");
}
for (int i=1 ; i<=21 ; i++)
{
move (31, i);
printf("*");
}
while(1)
{
char c = _getch(); // 문자 입력받는데 콘솔에 안보이게
move(x,y); //player 이전 위치 삭제
printf(" ");
//player 위치 이동
if (c=='a'){
if(x>1) x--;
}
else if(c=='w'){
if (y>2) y--;
}
else if(c=='s'){
if (y<20) y++;
}
else if(c=='d'){
if (x<30) x++;
}
move(x,y); //player 출력
printf("0");
move(0,23);
printf("x : %02d y : %02d",x,y); //player 위치
if (x==itemx && y==itemy) // 플레이어가 아이템 위치에 도달했다면,
{
sum+=10;
// itemx와 itemy의 위치를 (랜덤 위치로 )변경
itemx = rand()%29+1 ;
itemy = rand()%18+2 ;
move (itemx, itemy); //item 출력
printf("1");
move (0, 0);
printf("score : %d", sum);
}
if (is_2nd==0 && sum>=100)
{
is_2nd=1;
itemx2 = rand()%29+1 ;
itemy2 = rand()%18+2 ;
move (itemx2, itemy2); //item2 출력
printf("2");
move (0, 22);
printf("STAGE 2");
}
if (x==itemx2 && y==itemy2) // 플레이어가 아이템 위치에 도달했다면,
{
sum+=30;
// itemx2와 itemy2의 위치를 (랜덤 위치로 )변경
itemx2 = rand()%30+1 ;
itemy2 = rand()%20+2 ;
move (itemx2, itemy2); //item2 출력
printf("2");
move (0, 0);
printf("score : %d", sum);
}
}
return 0;
}