program tuchi;
uses crt, graph;
var tucha1, tucha2:integer;
gd,gm:integer;
way1, way2, x:integer;
begin
gd:=0; gm:=0;
initgraph(gd,gm,'');
tucha1:=18; tucha2:=500;
outtextxy(250,460,'Press Enter...');
readln;
repeat
delay(10);
setcolor(black);
circle(tucha1,23,18);
circle(tucha1+36,23,18);
circle(tucha1+36+36,23,18);
circle(tucha1+36+36+36,23,18);
circle(tucha2,23,18);
circle(tucha2+36,23,18);
circle(tucha2+36+36,23,18);
circle(tucha2+36+36+36,23,18);
if tucha1=18 then way1:=2
else if tucha1=500 then way1:=1;
if tucha2=18 then way2:=2
else if tucha2=500 then way2:=1;
if way1=2 then tucha1:=tucha1+1 else tucha1:=tucha1-1;
if way2=2 then tucha2:=tucha2+1 else tucha2:=tucha2-1;
if((tucha1+144=tucha2)and(way1=2)){встретились вперед}
or((tucha1=tucha2+144)and(way1=1)){встретились назад}
then
begin
setcolor(14);
if way1=2 then x:=tucha1+126{вперед}
else x:=tucha1-18;{назад}
line(x,23,x,460);
setcolor(white);
circle(tucha1,23,18); {зафиксируем тучи}
circle(tucha1+36,23,18);
circle(tucha1+36+36,23,18);
circle(tucha1+36+36+36,23,18);
circle(tucha2,23,18);
circle(tucha2+36,23,18);
circle(tucha2+36+36,23,18);
circle(tucha2+36+36+36,23,18);
delay(200);
setcolor(0);
line(x,23,x,460);
end;
setcolor(white);
circle(tucha1,23,18);
circle(tucha1+36,23,18);
circle(tucha1+36+36,23,18);
circle(tucha1+36+36+36,23,18);
circle(tucha2,23,18);
circle(tucha2+36,23,18);
circle(tucha2+36+36,23,18);
circle(tucha2+36+36+36,23,18);
until keypressed;
closegraph;
end.