/*
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <Windows.h>
void textcolor(int colorNum) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colorNum);
}
void gotoxy(int x, int y)
{
COORD Pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
int main()
{
char str[101];
int n,i,j;
scanf("%d",&n);
srand(time(NULL));
for(i=3;i<n+3;i++){
for(j=1;j<=250;j++){
int a = j;
int b = i;
gotoxy(a,b);
textcolor(j%16);
printf("o");
Sleep(1);
}
printf("\n");
}
}
*/
/**
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <Windows.h>
void textcolor(int colorNum) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colorNum);
}
void gotoxy(int x, int y)
{
COORD Pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
int main()
{
char p;
int x=5, y=5;
while(1)
{
gotoxy(10,10);
scanf("%c",&p);
if(p=='a')
{
x=x-10; //왼쪽으로 이동
}
else if(p=='d')
{
x=x+10; //오른쪽으로 이동
}
if(p=='w')
{
y=y-10;
}
if(p=='s')
{
y=y+10;
}
system("cls");
gotoxy(x,y);
printf("#");
Sleep(100);
}
}
**/
#include <stdio.h>
#include <windows.h>
#include <Windows.h>
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
int x=5, y=5,i,j;
void gotoxy(int x, int y)
{
COORD Pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
void map()
{
gotoxy(0,0);
for(i=1; i<=49; i++)
{
for(j=1; j<=49; j++)
{
if(i!=0||i!=49||j!=0||j!=49)
{
printf(" ");
}
}
printf("\n");
}
}
// 1. 매크로로 좌우상하를 설정한다.
int main(void)
{
char c;
int size=1;
gotoxy(0,0);
for(i=1; i<=50; i++)
{
for(j=1; j<=50; j++)
{
if(i==1||i==50||j==1||j==50)
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
gotoxy(10,10);
while (1)
{
if (_kbhit()) // 2. while문안에서 키보드 눌렸을 시 if문이 실행된다.
{
c = _getch(); // 3. 방향키가 입력됬을 때 224 00 이 버퍼에 있다. 224부터 빼준다.
if (c == -32) // 4. -32로 입력되면
{
c = _getch();// 5. 뒤의 값 00을 판별하여 좌우상하 출력
switch (c)
{
case LEFT:
if(x>1)
{
x=x-size;
}
break;
case RIGHT:
if(x<48)
{
x=x+size;
}
break;
case UP:
if(y>1)
{
y=y-size;
}
break;
case DOWN:
if(y<48)
{
y=y+size;
}
break;
}
map();
gotoxy(x,y);
printf("#");
gotoxy(52,30);
printf("x : %d y :%d",x,y);
}
}
}
return 0;
}