uses graph,crt; label 1,2; var a,d,m,pX,pY,S,vS,X,Y,vX,vY,rX,rY,Dy : Integer; begin S:=2; X:=1; Y:=1; vX:=1; vY:=1; rX:=1; rY:=1; vS:=2; Dy:=10; randomize; d:=VGA; m:=2; initgraph(d, m, 'c:\bp\bgi'); setColor(5); For pX:=1 to 3 do For pY:=1 to 4 do Rectangle(pX*50,pY*50,pX*50+35,pY*50+35); SetColor(7); Rectangle(35,35,201,251); setcolor (0); line(35,251,50,251); setcolor (7); line(35,251,35,270); line(50,251,50,270); repeat 1: if S=2 then vS:=Random(3)+1; if S=3 then vS:=Random(3)+2; if S=4 then begin vS:=Random(3)+1; Case vS of 1 : vS:=1; 2 : vS:=3; 3 : vS:=4; end; end; if S=1 then begin vS:=Random(3)+1; Case vS of 1 : vS:=1; 2 : vS:=2; 3 : vS:=4; end; end; Case vS of 1 : if vX>1 then Dec(vX); 2 : if vY<5 then Inc(vY); 3 : if vX<4 then Inc(vX); 4 : if vY>1 then Dec(vY); end; if (X=1) and (Y=5) and (vS=4) then goto 2; if (X=vX) and (Y=vY) then goto 1; X:=vX; Y:=vY; S:=vS; if S=3 then begin For a:=rX*50 to X*50 do begin SetColor(15); Circle(a-7,Y*50-6,5); Delay(Dy); SetColor(0); Circle(a-7,Y*50-6,5); SetColor(2); Circle(3*50-7,3*50-6,5); end; end; if S=1 then begin For a:=rX*50 downto X*50 do begin SetColor(15); Circle(a-7,Y*50-6,5); Delay(Dy); SetColor(0); Circle(a-7,Y*50-6,5); SetColor(2); Circle(3*50-7,3*50-6,5); end; end; if S=2 then begin For a:=rY*50 to Y*50 do begin SetColor(15); Circle(X*50-7,a-6,5); Delay(Dy); SetColor(0); Circle(X*50-7,a-6,5); SetColor(2); Circle(3*50-7,3*50-6,5); end; end; if S=4 then begin For a:=rY*50 downto Y*50 do begin SetColor(15); Circle(X*50-7,a-6,5); Delay(Dy); SetColor(0); Circle(X*50-7,a-6,5); SetColor(2); Circle(3*50-7,3*50-6,5); end; end; if (X=3) and (Y=3) then Inc(Dy,10); if (X=1) and (Y=5) and (S=4) then goto 2; rX:=X; rY:=Y; until keypressed; 2:CloseGraph; end.