Created
November 14, 2012 17:33
-
-
Save Jack2/4073535 to your computer and use it in GitHub Desktop.
[C++]move_example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Turboc.h" | |
#include <iostream> | |
#include <conio.h> | |
using namespace std; | |
int main() | |
{ | |
const int LEFT = 75; //#define LEFT 75 대신 사용 | |
const int RIGHT = 77; //#define RIGHT 77 대신 사용 | |
const int UP = 72; //#define UP 72 대신 사용 | |
const int DOWN = 80; //#define DOWN 80 대신 사용 | |
int key; //움직일 때 필요한 변수 | |
int x=0,y=0; // x좌표, y좌표 | |
cout << "*"; | |
//방향키를 움직이는 대로 * 출력 | |
do | |
{ | |
key = getch(); // 자동입력 | |
switch(key) // key변수 - 스위치 | |
{ | |
case UP : // #define UP 에 대한 것 (위로 움직일 때) | |
if(y>0){ | |
gotoxy(x,y--); cout << " "; //위로 움직일 때마다 * 감소 | |
gotoxy(x,y); cout << "*"; //x,y좌표에 대한 값 * 출력 | |
} | |
break; | |
case DOWN : // #define DOWN 에 대한 것 (아래로 움직일 때) | |
gotoxy(x,y++); cout << " "; // 아래로 움직일 때마다 * 증가 | |
gotoxy(x,y); cout << "*"; //x,y좌표에 대한 값 * 출력 | |
break; | |
case LEFT : //#define LEFT 에 대한 것 (왼쪽으로 움직일 때) | |
if(x>0){ | |
gotoxy(x--,y); cout << " "; //왼쪽으로 움직일 때마다 * 감소 | |
gotoxy(x,y); cout << "*"; //x,y좌표에 대한 값 * 출력 | |
} | |
break; | |
case RIGHT : //#define RIGHT 에 대한 것 (오른쪽으로 움직일 때) | |
gotoxy(x++,y); cout << " "; //오른쪽으로 움직일 때마다 * 증가 | |
gotoxy(x,y); cout << "*"; //x,y좌표에 대한 값 * 출력 | |
break; | |
} | |
} while(key != 'q'); | |
//해당 프로그램을 종료하려면 q 입력 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment