program race;
uses crt, graph;

var gd, gm, i : integer;
    winkel, winkel2 : real;
    g : 1..7;
    d : 0..1;
    feldx, feldy : array[1..7] of integer;
    ton, tons : integer;

procedure punkt(x, y : integer; farbe: byte);
  begin
    setcolor(farbe);
    setfillstyle(1, farbe);
    pieslice(x, y, 0, 360, 1);
  end;

procedure gang(x, y : integer);
  begin
    setcolor(8);                              {Gangschaltung}
    setfillstyle(1, 8);
    bar(410, 410, 500, 470);
    setlinestyle(0, 0, 3);
    setcolor(0);
    line(420, 420, 420, 460);
    line(455, 420, 455, 460);
    line(490, 420, 490, 460);
    line(420, 440, 490, 440);
    outtextxy(422, 430, '1');
    outtextxy(422, 445, '2');
    outtextxy(457, 430, '3');
    outtextxy(457, 445, '4');
    outtextxy(482, 430, '5');
    outtextxy(482, 445, 'R');
    setcolor(7);
    setfillstyle(1, 7);
    pieslice(x, y, 0, 360, 5);
  end;

procedure amatur;
  begin
    setcolor(lightgray);                {Hintergrund}
    setfillstyle(11, lightgray);
    bar(0, 401, 639, 480);
    setcolor(white);                    {Tacho}
    setfillstyle(1, lightgray);
    pieslice(320, 479, 0, 180, 70);
    setcolor(0);
    setfillstyle(1, 0);
    pieslice(320, 475, 0, 360, 3);
    setlinestyle(0, 0, 3);
    line(280, 475, 320, 475);
    outtextxy(252, 472, '0');
    outtextxy(275, 425, '100');
    outtextxy(343, 425, '200');
    outtextxy(366, 472, '300');
    setlinestyle(0, 0, 0);
    punkt(257, 460, 0);
    line(260, 448, 265, 449);
    punkt(268, 438, 0);
    punkt(298, 416, 0);
    line(320, 411, 320, 415);
    punkt(342, 416, 0);
    punkt(372, 438, 0);
    line(380, 448, 375, 449);
    punkt(384, 460, 0);
    setcolor(white);                    {Drehzahl}
    setfillstyle(1, lightgray);
    pieslice(180, 479, 0, 180, 60);
    setcolor(0);
    setfillstyle(1, 0);
    pieslice(180, 475, 0, 360, 3);
    setlinestyle(0, 0, 3);
    line(140, 475, 180, 475);
    setlinestyle(0, 0, 0);
    outtextxy(122, 470, '0');
    outtextxy(147, 430, '5');
    outtextxy(200, 431, '10');
    setcolor(4);
    outtextxy(225, 470, '15');
    punkt(127, 463, 0);
    punkt(130, 454, 0);
    punkt(135, 446, 0);
    punkt(141, 439, 0);
    punkt(160, 426, 0);
    punkt(172, 424, 0);
    punkt(189, 424, 0);
    punkt(200, 426, 0);
    punkt(220, 439, 0);
    punkt(226, 446, 0);
    punkt(231, 454, 4);
    punkt(234, 463, 4);
    gang(440, 440);
    setviewport(0, 0, 639, 400, true);
  end;

procedure spiel;
  begin
    setcolor(green);       {Hintergrund}
    setfillstyle(1, green);
    bar(0, 200, 639, 400);
    setcolor(11);
    setfillstyle(1, 11);
    bar(0, 0, 639, 200);
    setcolor(8);                    {Straáe}
    setlinestyle(0, 0, 0);
    line(-400, 400, 50, 201);
    line(0, 201, 500, 201);
    line(500, 201, 640, 400);
    line(640, 400, -100, 400);
    setfillstyle(1, 8);
    floodfill(320, 380, 8);
    setlinestyle(0, 0, 3);
    setcolor(15);
    line(635, 400, 495, 201);
    line(-5, 230, 55, 200);
    line(0, 400, 125, 300);
    delay(1000);
    setviewport(0, 0, 639, 479, false);
    gang(420, 420);
    d:=0;
    g:=1;
    winkel2:=Pi;
    ton:=100;
    for i:=7*180 downto 0 do
      begin
        if (i mod 10 = 0) and (d=0) then d:=1
          else if (i mod 10 = 0) and (d=1) then d:=0;
        winkel:=i/7*Pi/180;
        winkel2:=winkel2-Pi/360;
        ton:=ton+15;
        if winkel2<=27*Pi/180 then ton:=1900;
        if winkel2<=27*Pi/180 then g:=g+1;
        if winkel2<=27*Pi/180 then gang(feldx[g], feldy[g]);
        if winkel2<=27*Pi/180 then winkel2:=150*Pi/180;
        setcolor(0);
        setlinestyle(0, 0, 3);
        line(320, 475, round(cos(winkel)*40+320), 475-round(sin(winkel)*40));
        pieslice(320, 475, 0, 360, 2);
        line(180, 475, round(cos(winkel2)*40+180), 475-round(sin(winkel2)*40));
        pieslice(180, 475, 0, 360, 2);
        setcolor(15);
        if d=0 then line(0, 400, 125, 300);
        if d=1 then line(125, 300, 250, 201);
        sound(ton);
        delay(5);
        nosound;
        if keypressed then readln;
        setcolor(7);
        setlinestyle(0, 0, 3);
        if i>0 then line(320, 475, round(cos(winkel)*40+320),
                              475-round(sin(winkel)*40));
        if i>0 then line(180, 475, round(cos(winkel2)*40+180),
                              475-round(sin(winkel2)*40));
        setcolor(8);
        if (d=0) and (i>0) then line(0, 400, 125, 300);
        if (d=1) and (i>0) then line(125, 300, 250, 201);
      end;
  end;

begin
  gd:=9; gm:=2;
  feldx[1]:=420; feldy[1]:=420;
  feldx[2]:=420; feldy[2]:=460;
  feldx[3]:=455; feldy[3]:=420;
  feldx[4]:=455; feldy[4]:=460;
  feldx[5]:=490; feldy[5]:=420;
  feldx[6]:=490; feldy[6]:=420;
  feldx[7]:=490; feldy[7]:=420;
  initgraph(gd, gm, 'd:\tp\bgi');
  amatur;
  spiel;
  readln;
  closegraph;
end.