uses graphABC;
var x, y, n, h, c, d, a, b, q, w, m, l, x1, y1,co,col,b1, q1, w1, m1, l1, x2, y2,col1: integer;
begin
Window.Title := 'Круги';
Font.Color := clwhite;//цвет шриФта
x:=random(Window.Width); //Начальные
y:=random(Window.height);//Позиции
x1:=random(Window.Width);//Кругов
y1:=random(Window.height);//.....
x2:=random(Window.Width);//......
y2:=random(Window.height);//.....
c:=5;d:=5;q:=5;w:=5;q1:=5;w1:=5;// дополнительные переменные для рандомного движения
co:=0;col:=0;col1:=0; //переменные отвечающие за цвет
repeat //цикл рисования кругов
//1 круг ////////////////////////////////////////////////////
//------Условия навправления движения и его изменение----------------------------------------------------------
if a=0 then begin n:=(random(c+6)-ABS(c)); h:=(random(d+6)-ABS(d));
c:=5;d:=5; a:=1; end;
//------Рисование круга задание цвета условия столкновения с гарницами и текст-----------------------------------------------
LockDrawing;
Brush.Color := clRed;
if co=1 then Brush.Color := clBlue;
x:=x+n; y:=y+h;
if x<10 then begin a:=0; c:=0; end;
if y<10 then begin a:=0; d:=0; end;
if x>Window.Width-10 then begin a:=0; c:=-5; end;
if y>Window.height-10 then begin a:=0; d:=-5; end;
if (x=0) or (y=0) then a:=0;
circle(x,y,10);
TextOut(x-4,y-6,'A');
//---------------------------------------------------------------
//2 круг /////////////////////////////////////////////////////
if b=0 then begin m:=(random(q+6)-ABS(q)); l:=(random(w+6)-ABS(w));
q:=5;w:=5; b:=1;end;
if col=0 then Brush.Color := clBlack;
if col=1 then Brush.Color := clRed;
x1:=x1+m; y1:=y1+l;
if x1<10 then begin b:=0; q:=0; end;
if y1<10 then begin b:=0; w:=0; end;
if x1>Window.Width-10 then begin b:=0; q:=-5; end;
if y1>Window.height-10 then begin b:=0; w:=-5; end;
if (x1=0) or (y1=0) then b:=0;
circle(x1,y1,10);
TextOut(x1-4,y1-6,'B');
//3 круг /////////////////////////////////////////////////////
if b1=0 then begin m1:=(random(q1+6)-ABS(q1)); l1:=(random(w1+6)-ABS(w1));
q1:=5;w1:=5; b1:=1;end;
if col1=0 then Brush.Color := clBlue;
x2:=x2+m1; y2:=y2+l1;
if x2<10 then begin b1:=0; q1:=0; end;
if y2<10 then begin b1:=0; w1:=0; end;
if x2>Window.Width-10 then begin b1:=0; q1:=-5; end;
if y2>Window.height-10 then begin b1:=0; w1:=-5; end;
if (x2=0) or (y2=0) then b1:=0;
circle(x2,y2,10);
TextOut(x2-4,y2-6,'C');
//Тут круги меняют цвет при сталкивании//////////////////////////////////////////////////////////
if (ABS(x-x1)<=20) and (ABS(y-y1)<=20) then col:=1;
if (ABS(x-x2)<=20) and (ABS(y-y2)<=20) then co:=1;
if (ABS(x1-x2)<=20) and (ABS(y1-y2)<=20) and (col=1) then col:=0;
if (ABS(x-x2)<=20) and (ABS(y-y2)<=20) and (co=0) then co:=1;
Redraw;
Window.Clear(clWhite);
sleep(20);
until 2<1;
end.
С радостью выслушаю советы=) И да, так как в результате хоче получить 20 шаров, а алгоритм уже подтормажует то хотелось бы полегче код, просто в голову не лезет уже.
И да, пишу на Pascal.ABC
Сообщение отредактировано: Hatia -