uses Graph;

const Delay = 5;

type
 Ball = record
 x, y, r, dx, dy: integer;
 c: Color;
 procedure Draw;
 begin
 Brush.Color := c;
 FillCircle(x, y, r);
 end;
 
 constructor Create(xx, yy, rr: integer; cc: Color);
 begin
 x := xx;
 y := yy;
 r := rr;
 c := cc;
 repeat
 dx := Random(-3,3);
 dy := Random(-3,3);
 until (dx <> 0) or (dy <> 0);
 end;

 procedure Move;
 begin
 if (x + dx - r <= 0) or (x + dx + r >= Window.Width) then
 dx := -dx;
 if (y + dy - r <= 0) or (y + dy + r >= Window.Height) then
 dy := -dy;
 x := x + dx;
 y := y + dy;
 Draw;
 end;
 end;

var b1, b2, b3: Ball;

begin
 Window.Title := 'Отражение шариков';
 Window.SetSize(400,300);
 b1 := new Ball(270, 180, 20, Color.Green);
 b2 := new Ball(270, 180, 20, Color.Blue);
 b3 := new Ball(270, 180, 20, Color.Red);
 while True do
 begin
 Window.Clear;
 b1.Move;
 b2.Move;
 b3.Move;
 Sleep(Delay);
 end;
end.


 Похожие публикации
2015-10-14 • Просмотров [ 485 ]