program LAB_2;
uses crt, graph;
const
	UP = 1; DOWN = 2; LEFT = 3; RIGHT = 4;
	Path_of_driver = 'C:\TURBO_PASCAL_7.1\BGI';
        N = 100;
type
	tPoint = object
		private
			x, y, color : integer;
		public
			procedure show;
			procedure hide;
                        procedure setPosition(_x, _y : integer);
                        procedure setColor(_color : integer);
			procedure move(direction : integer);
	end;

procedure tPoint.setPosition(_x, _y : integer);
begin
     x := _x;
     y := _y;
end;

procedure tPoint.setColor(_color : integer);
begin
     color := _color;
end;

procedure tPoint.move(direction : integer);
begin
	hide;
	case direction of
		UP : y := y + 2;
		DOWN : y := y - 2;
		LEFT : x := x - 2;
		RIGHT : x := x + 2;
	end;
	show;
end;

Procedure tPoint.Hide;
begin
   PutPixel(x,y,GetBkColor);
end;


Procedure tPoint.Show;
begin
	PutPixel(x,y,color);
end;

var
   mas:array[1..N] of tPoint;
   gm,gd:integer;
   Q,a:char;
   Srt:integer;


procedure Point(x:integer);
var
   i,b,count:integer;
   a:char;
begin
   randomize;
   cleardevice;
   for i:=1 to N do
   begin
     mas[i].setColor(random(GetMaxColor));
     mas[i].setPosition(random(GetMaxX), random(GetMaxY));
     mas[i].show;
   end;
   count:=0;
   repeat
     if x=1 then a:=readkey;
     inc(Count);
     if Count>3000 then
        begin
             Count:=0;
             a:=readkey;
        end;
     b:=RANDOM(4);
     if x=1 then
     case a of
     #75:  for i:=1 to N do mas[i].move(LEFT);
     #72:  for i:=1 to N do mas[i].move(DOWN);
     #77:  for i:=1 to N do mas[i].move(RIGHT);
     #80:  for i:=1 to N do mas[i].move(UP);
     end;

     if x=2 then
     case b of
     1:  for i:=1 to N do mas[i].move(LEFT);
     2:  for i:=1 to N do mas[i].move(DOWN);
     3:  for i:=1 to N do mas[i].move(RIGHT);
     0:  for i:=1 to N do mas[i].move(UP);
     end;

   until a=#27;
end;

BEGIN
     clrscr;
     gd := Detect;
     InitGraph(gd, gm, Path_of_driver);
     if GraphResult <> grok then begin
         write('error:', GraphErrorMsg(GraphResult));
         readln;
         halt;
     end;

  repeat
  RestoreCrtMode;
  writeln('                                     MENU');
  writeln;
  writeln ('                                  1: Strelki');
  writeln ('                                  2: Random  ');
  writeln ('                                  3: Exit  ');
  writeln('                                Esc: Exit in the menu!');
  readln(srt);
  SetGraphMode(gm);
  if srt=1  then
       begin
         Point(1);
       end;
    if srt=2  then
       begin
         Point(2);
       end;
  RestoreCrtMode;
until srt=3;
closegraph;
clrscr;
END.
