c언어 졸라맨 이동

C언어 졸라맨 이동.

안녕하세요.

오늘은 공부하기 싫어서 특수문자로 졸라맨을 만들고 이동시켜보는 간단한 프로그램을 만들었습니다.

사실 코딩은 별거 없었는데 졸라맨 만드는게 힘들었어요.(특수문자로 그림을 처음 그려봐서..)

  • 간단한 코드 설명.
  • 졸라맨 이동 코드.
  • 코드 실행 결과.

간단한 코드 설명.

전에 블로그에 작성했던 gotoxy를 이번에 사용했습니다.

[프로그래밍/C 언어] - c언어 좌표를 받아 커서이동 gotoxy

 

c언어 좌표를 받아 커서이동 gotoxy

커서이동 함수 gotoxy c언어로 매크로를 만들어보고 싶어서 찾아보다가 알게되었습니다. 이 함수를 이용해서 콘솔에 원하는 좌표에 찍는것이 가능했습니다. (내가 원하는 내용이랑은 살짝 달랐습

intunknown.tistory.com

gotoxy로 원하는 위치에 원하는 특수문자를 출력하였습니다.

서있을때 움직일때의 모션을 번갈아가며 출력하여 움직이는 것처럼 만들었습니다.

왼쪽=244 75, 오른쪽=244 77인데 제가 char로 작성을 해서 if(c==-32)부분을 넣었습니다.

졸라맨 이동 코드.

실행사진 과 간단한 설명

#include<stdio.h>
#include<windows.h>
#include<conio.h>

#define LEFT 75
#define RIGHT 77

void gotoxy(int x, int y);
int move(int gps);
void man(int m); 
void man2(int m);
void man3(int m);

int main(){
	int gps=0;
	int i;
	man(gps);
	while(1){
		if(_kbhit()){ //키보드가 눌리면 실행.
			gps=move(gps);	
		}
		Sleep(10);
	}
}
/*goto*/
void gotoxy(int x, int y)
{
        COORD Pos = {x, y};
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
/*캐릭터 움직임*/
int move(int gps){
	char c;
	c=_getch();
	if(c==-32){
		c=_getch();
		switch(c){
			case RIGHT:
				gps=gps+1;
				man2(gps);
				Sleep(50);
				man(gps);
				break;
			case LEFT:
				gps=gps-1;
				man3(gps);
				Sleep(50);
				man(gps);
				break;
 		}
 	}
	return gps;
}
/*캐릭터 그려주기*/
void man(int m){
	int first=m;
	int hight=0;
	system("cls");//이전 내용은 지워짐.  
	gotoxy(first+2,hight);
	printf("●\n");
	gotoxy(first+1,hight+1);
	printf("┎╋┑\n");
	gotoxy(first,hight+2);
	printf(" !┃ !\n");
	gotoxy(first+2,hight+3);
	printf("┻\n");
	gotoxy(first+1,hight+4);
	printf("↓↓\n");
	gotoxy(first+1,hight+5);
	printf("↓↓\n");
	gotoxy(first,hight+6);
	printf("▨▨▨\n");
	
}
void man2(int m){
	int first=m;
	int hight=0;
	system("cls");//이전 내용은 지워짐.  
	gotoxy(first+2,hight);
	printf("●\n");
	gotoxy(first+1,hight+1);
	printf("┎╋┑\n");
	gotoxy(first+1,hight+2);
	printf("!┃ !\n");
	gotoxy(first+2,hight+3);
	printf("┻\n");
	gotoxy(first+1,hight+4);
	printf("↓ ↘\n");
	gotoxy(first,hight+5);
	printf("↙   ↓\n");
	gotoxy(first,hight+6);
	printf("▨▨▨\n");
}

void man3(int m){
	int first=m;
	int hight=0;
	system("cls");//이전 내용은 지워짐.  
	gotoxy(first+2,hight);
	printf("●\n");
	gotoxy(first+1,hight+1);
	printf("┎╋┑\n");
	gotoxy(first+1,hight+2);
	printf("!┃ !\n");
	gotoxy(first+2,hight+3);
	printf("┻\n");
	gotoxy(first,hight+4);
	printf("↙ ↓\n");
	gotoxy(first,hight+5);
	printf("↓  ↘\n");
	gotoxy(first,hight+6);
	printf("▨▨▨\n");
}

코드 실행 결과.

코드 실행 동영상입니다.

 

Designed by JB FACTORY