Develop
2013.04.23 12:54
[c] 간단한 점 이동 샘플 소스코드
조회 수 6541 댓글 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;
}
}
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
309 | Develop | [PHP] Mac OS에서 PHP 7 설치하기 | hooni | 2018.05.11 | 4871 |
308 | System/OS | [linux] CentOS 6.5 에서 "Bringing up interface eth0: Determining if ip address 121.78.127.197 is already in use for device eth0..." | hooni | 2014.04.05 | 4828 |
307 | Develop | [android] 안드로이드 동영상 스트리밍 예제 2 | hooni | 2015.01.02 | 4808 |
306 | Develop | [ios] UITableView 특정 Row만 Update | hooni | 2014.04.08 | 4766 |
305 | Develop | [ios] Objective-C 프로퍼티의 strong, weak, assign | hooni | 2014.03.17 | 4680 |
304 | Develop | [ios] UUID 생성 + Key Chain 연동 | hooni | 2016.05.13 | 4648 |
303 | System/OS | [linux] resolv.con 초기화 되는 문제 | hooni | 2014.04.05 | 4608 |
302 | System/OS | [linux] CentOS Apache Httpd에 https 적용 | hooni | 2014.03.05 | 4476 |
301 | System/OS | [linux] 초간단 SquirrelMail 설치/설정 (다람쥐 메일) | hooni | 2017.12.11 | 4445 |
300 | Develop | [ios] 앱딜리게이트 라이프사이클 (AppDelegate Lifecycle) | hooni | 2014.05.09 | 4445 |
299 | Develop | [ios] URL Scheme 이용하여 앱 설치 확인 | hooni | 2014.03.10 | 4362 |
298 | System/OS | [linux] split 명령어 | hooni | 2014.03.11 | 4301 |