Uses Crt,Graph;
const Path_of_driver='F:\BGI';
Type
TPoint = object
x,y:integer;
color:word;
procedure Init(InitX,InitY:integer;col:word);
procedure Hide;
procedure Draw;
procedure SetX(NewX:integer);
procedure SetY(NewY:integer);
function GetX:integer;
function GetY:integer;
procedure Move(NewX,NewY:integer);
end;
Procedure TPoint.Init(InitX,InitY:integer; col:word);
begin
x:=InitX;
y:=InitY;
color:=col;
end;
Procedure TPoint.Hide;
begin
PutPixel(x,y,GetBkColor);
end;
Procedure TPoint.Draw;
begin
PutPixel(x,y,color);
end;
Function TPoint.GetX:integer;
begin
GetX:=x;
end;
Function TPoint.GetY:integer;
begin
GetY:=y;
end;
Procedure TPoint.SetX(NewX:integer);
begin
x:=NewX;
end;
Procedure TPoint.SetY(NewY:integer);
begin
y:=NewY;
end;
procedure TPoint.Move(NewX,NewY:integer);
begin
Hide;
x:=NewX;
y:=NewY;
Draw;
end;
Procedure Coords(a:char; var NewX,NewY:integer; h:integer);
begin
if a=#0 then begin
a:=readkey;
case a of
#80: begin Inc(NewY,h); if NewY>GetMaxY-20 then NewY:=20;
end;
#75: begin dec(NewX,h); if NewX<10 then NewX:=GetMaxX-10;
end;
#77: begin inc(NewX,h); if NewX>GetMaxX-10 then NewX:=10;
end;
#72: begin dec(NewY,h); if NewY<20 then NewY:=GetMaxY-20;
end;
end;
end
end;
VAR gd,gm,NewX,NewY,h,x,y,vh,i: integer;
color: word;
Q,a:char;
str:string;
tp:TPoint;
mas:array[1..100] of TPoint;
BEGIN
Randomize;
gd:=Detect;
InitGraph(gd,gm,Path_of_driver);
if GraphResult<>grok then begin
write('error:',GraphErrorMsg(GraphResult));
halt;
end;
tp.Init(GetMaxX div 2,GetMaxY div 2,10);
NewX:=GetMaxX div 2;
NewY:=GetMaxY div 2;
h:=2;
RestoreCrtMode;
Q:='y';
While Q<>'n' do begin
writeln('Chtoby dvigat tochki vvedite: 1 ');
writeln('Chtoby tochki dvigalis sami vvedite: 2 ');
readln(str);
if str='1' then begin writeln('Chtoby dvigat tochki ispolzujte strelki'); end;
writeln('Nazhmite: Enter');
readln;
SetGraphMode(gm);
repeat
a:=readkey;
Coords(a,NewX,NewY,h);
if str='1' then begin
for vh:=1 to 100 do begin
tp.SetX(Random(640));
tp.SetY(Random(480));
mas[vh].Hide;
mas[vh].Init(tp.GetX,tp.GetY,10);
mas[vh].Draw;
mas[vh].Move(tp.GetX,tp.GetY);
end;
end;
until a=#27;
RestoreCrtMode;
write('Continue? (y/n) ');
readln(Q);
end;
closegraph;
clrscr;
END.
Сообщение отредактировано: Sanekkk1 -