Develop
2013.04.23 12:54
[c] 간단한 점 이동 샘플 소스코드
조회 수 6539 댓글 0
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#define STD_HANDLE GetStdHandle(STD_OUTPUT_HANDLE)
void gotoxy(int x, int y)
{
COORD Cur= {(SHORT)x, (SHORT) y};
SetConsoleCursorPosition(STD_HANDLE, Cur);
}
void main()
{
int x = 0; // x좌표
int direction = 1; // 방향. 1이면 오른쪽, -1이면 왼쪽
while(1)
{
while(!kbhit()) // 키보드가 입력되지 않는 한
{
_sleep(500); // 0.5초 쉼
gotoxy(x, 10); // 현재 자리에 있는
putchar(' '); // 점을 없애기 위해 공백 출력
x = x + direction; // x좌표 이동
if(x == 80) x = 0; // 만약에 80이면 한바퀴 돌았으므로 0으로
else if(x == 0) x = 79; // 0이면 왼쪽으로 한바퀴 돌았으므로 오른쪽 끝 79로
gotoxy(x, 10); // 이동한 좌표로
putchar('.'); // 점 출력
}
int key = getch(); // 키보드 입력
if(key == 0) // 특수키이면
{
key = getch(); // 입력받은 것중 나머지
}
if(key == 0x4b) // 왼쪽 커서이면
direction = -1;
else if(key == 0x4d) // 오른쪽 커서이면
direction = 1;
}
}
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
357 | Develop | [html] HTML5 튜토리얼 링크 ㅋㅋ | hooni | 2013.04.23 | 12809 |
356 | System/OS | [linux] 콘솔 기본언어 설정 방법 | hooni | 2013.04.23 | 12824 |
355 | System/OS | [sql] 내 방명록 답글 찾는 쿼리문.. (JOIN 구문) | hooni | 2003.04.23 | 12845 |
354 | System/OS | [linux] ProFTPD 타임아웃 설정 | hooni | 2003.04.23 | 12851 |
353 | Develop | [doc] UI개발시 유용한 소프트웨어 (개발 및 디버깅 툴) | hooni | 2013.04.23 | 12905 |
352 | Develop | [c] 다중연결 서버 만들기 #1 - fork() 사용 | hooni | 2013.04.23 | 12915 |
351 | System/OS | [router] 시스코 라우터 명령어 모드.. | hooni | 2013.04.23 | 12942 |
350 | System/OS | [linux] 아파치 설치/설정(proxy) | hooni | 2003.04.23 | 12965 |
349 | Develop | [js] 자바스크립트의 클로저 (JavaScript's Closure) | hooni | 2013.05.15 | 12975 |
348 | Develop | [php] 심플한 게시판 ㅋㅋ 1 | hooni | 2013.04.23 | 12978 |
347 | System/OS | [linux] ipfwadm를 이용한 패킷필터링(구버전) | hooni | 2003.04.23 | 13009 |
346 | Develop | [js] AngularJS를 소개합니다. | hooni | 2014.01.06 | 13010 |