Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MaratB/6664346 to your computer and use it in GitHub Desktop.
Save MaratB/6664346 to your computer and use it in GitHub Desktop.
#include <conio.h>
#include <graphics.h>
void Draw ( int x, int y, int color )
{
setfillstyle ( 1, color ); // Сплошная заливка, цвет color
bar ( x, y, x+20, y+20 ); // залитый квадрат
}
main()
{
int x,y,code;
initwindow (400, 400);
setfillstyle(1, COLOR(0,0,255));
bar (0, 0, 400, 400);
x = 0; y = 0; // нач. координаты квадрата
{
Draw ( x, y, COLOR(255,255,0) ); // рисуем квадрат
code = getch(); // ждем нажатия клавиши
if ( code == 27 ) break; // если Esc, то выход
Draw ( x, y, COLOR(0,0,255) ); // стираем квадрат
switch ( code ) //выбор движения
{
case 75: x -=10; break; // влево
case 77: x +=10; break; // вправо
case 72: y -=10; break; // вверх
case 80: y +=10; // вниз
}
}
getch();
closegraph();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment