uses Crt, Graph; const do_exit: boolean = false; type PTObj = ^TObj; TObj = object X, Y, DX, DY: Integer; constructor Init; destructor done; virtual; procedure show(is_active: boolean); virtual; procedure recalc; virtual; function get_color: integer; virtual; end; PTRandomObj = ^TRandomObj; TRandomObj = object(TObj) Tick: integer; constructor Init; destructor done; virtual; procedure recalc; virtual; function get_color: integer; virtual; end; PTControlObj = ^TControlObj; TControlObj = object(TObj) constructor Init; destructor done; virtual; procedure recalc; virtual; function get_color: integer; virtual; end; constructor TObj.Init; begin X := random(getmaxx - 200 + 1) + 100; Y := random(getmaxy - 100 + 1) + 50; DX := random(11) - 5; DY := random(11) - 5; end; destructor TObj.done; begin end; function TObj.get_color: integer; begin get_color := getbkcolor end; procedure TObj.recalc; begin Inc(X, DX); Inc(Y, DY); end; procedure TObj.show(is_active: boolean); const R = 5; begin if is_active then setcolor(get_color) else setcolor(TObj.get_color); circle(X, Y, R); end; constructor TRandomObj.Init; begin Inherited Init; Tick := 0; end; destructor TRandomObj.done; begin Inherited Done end; procedure TRandomObj.recalc; begin if Tick < 10 then begin TObj.ReCalc; Inc(Tick) end else begin DX := random(11) - 5; DY := random(11) - 5; Tick := 0; end; end; function TRandomObj.get_color: integer; begin get_color := White end; constructor TControlObj.Init; begin Inherited Init; DX := 0; DY := 0; end; destructor TControlObj.done; begin Inherited Done end; procedure TControlObj.recalc; begin if keypressed then begin case readkey of #0 : readkey; #27: do_exit := true; #56: { 8: up } begin DX := 0; DY := -5 end; #50: { 2: dn } begin DX := 0; DY := +5 end; #52: { 4: lt } begin DX := -5; DY := 0 end; #54: { 6: rg } begin DX := +5; DY := 0 end; end; while keypressed do readkey; end; TObj.ReCalc; end; function TControlObj.get_color: integer; begin get_color := Red end; const n_objects = 5; var grDriver, grMode, ErrCode: Integer; buffer: array[1 .. n_objects] of PTObj; i: integer; begin grDriver := Detect; InitGraph(grDriver, grMode, ''); ErrCode := GraphResult; if ErrCode <> grOk then begin Writeln('Graphics error:', GraphErrorMsg(ErrCode)); readln; halt(100); end; for i := 1 to n_objects do begin if i <> n_objects then buffer[i] := new(PTRandomObj, Init) else buffer[i] := new(PTControlObj, Init); end; repeat delay(4000); for i := 1 to n_objects do with buffer[i]^ do begin Show(False); ReCalc; Show(True); end; until do_exit; readln; CloseGraph; end.