Created
September 22, 2013 22:22
-
-
Save MaratB/6664432 to your computer and use it in GitHub Desktop.
This file contains 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 <conio.h> | |
#include <graphics.h> | |
void Draw ( int x, int y, int color ) | |
{ | |
setfillstyle ( 1, color ); | |
bar ( x, y, x+20, y+20 ); | |
} | |
main() | |
{ | |
int x,y,code,dx,dy; | |
initwindow (400, 400); | |
setfillstyle(1, COLOR(0,0,255)); | |
bar (0, 0, 400, 400); | |
x = 0; y = 0; // нач. координаты квадрата | |
dx = 1; dy = 0; // сначала двигаемся вправо | |
while ( 1 ) | |
{ | |
if ( kbhit() ) // если нажата клавиша | |
{ | |
code = getch(); //какая клавиша нажата | |
if ( code == 27 ) break; // если Esc, то выход | |
switch ( code ) // изменить направление движения | |
{ | |
case 75: dx = -1; dy = 0; break; | |
case 77: dx = 1; dy = 0; break; | |
case 72: dx = 0; dy = -1; break; | |
case 80: dx = 0; dy = 1; | |
} | |
} | |
Draw ( x, y, COLOR(255,255,0) ); //рисуем | |
delay ( 10 ); // задержка | |
Draw ( x, y, COLOR(0,0,255) ); //стираем | |
x += dx; // двигаем | |
y += dy; | |
} | |
getch(); | |
closegraph(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment