program Geisterfahrer(input,output);
(* Quelle: http://www.iee.et.tu-dresden.de/~kc-club/09/RUBRIK17.HTM *)

(*
  #$82 - Cursor ein
  #$83 - Cursor aus
*)

var
  l3f3f        : array[0..10,1..3] of integer;
  l3f3d        : array[1..2] of byte;
  l3f3c        : char;
  l3f36        : real;
  l3f34        : integer;
  l3f32        : integer;
  l3f30        : integer;
  l3f2e        : integer;
  l3f2c        : integer;
  l3f2a        : integer;
  l3f28        : integer;
  l3f27        : byte;
  l3f26        : byte;
  l3f25        : byte;
  l3f24        : byte;
const
  CRTcolumns   = $0168;
  CRTlines     = $0169;
  l1fe7        : byte = 20;
  l1fe8        : array[1..2]      of string[9] =('_/~~\___.',
                                                 '<o----o->');
  l1ffc        : array[1..6,1..2] of string[10]=((' __/&&\_  ',
                                                  '"-o---o-  '),
                                                 (' /&|||||| ',
                                                  '<-o----o> '),
                                                 (' _/&|ooo_ ',
                                                  '<=o===o=+ '),
                                                 ('  _i_/&\  ',
                                                  ' |o===O+` '),
                                                 (' __/&&&\  ',
                                                  '<-o----o` '),
                                                 (' ___/&\__ ',
                                                  '<-o---o-+ '));
procedure l2080(l3f23,l3f22:byte);
Begin
  gotoxy(l3f23+l3f24,l3f22+l3f25);
End;

procedure l20ad;
Begin
  for l3f34:=1 to 2 do
  begin
    l3f3d[l3f34]:=l3f3d[l3f34]-1;
    if l3f3d[l3f34]=0 then
    begin
      l2080(l3f3d[l3f34]+1,3);
      write(' ');
      l2080(l3f3d[l3f34]+1,14);
      write(' ');
      l3f3d[l3f34]:=60;
    end;
    l2080(l3f3d[l3f34],3);
    write('. ');
    l2080(l3f3d[l3f34],14);
    write('. ');
  end;
End;

procedure l21aa;
Begin
  for l3f34:=1 to 9 do
  begin
    if l3f3f[l3f34,3]>0 then
    begin
      l3f2c:=l3f3f[l3f34,1];
      if l3f2c<1 then l3f2c:=1;
      l3f2a:=2-l3f3f[l3f34,1];
      if l3f2a<1 then l3f2a:=1;
      l3f28:=61-l3f3f[l3f34,1];
      if l3f28>10 then l3f28:=10;
      l2080(l3f2c,l3f3f[l3f34,2]);
      write(copy(l1ffc[l3f3f[l3f34,3],1],l3f2a,l3f28));
      l2080(l3f2c,1+l3f3f[l3f34,2]);
      write(copy(l1ffc[l3f3f[l3f34,3],2],l3f2a,l3f28));
      l3f3f[l3f34,1]:=l3f3f[l3f34,1]-1;
      if l3f3f[l3f34,1]=-10 then l3f3f[l3f34,3]:=0;
    end;
  end;
End;

procedure l2411;
Begin
  read(kbd,l3f3c);
  case l3f3c of
    #$1a,'5','8' : begin
                     l3f26:=l3f26-1;
                     l2080(l1fe7,l3f26+2);
                     write('         ');
                   end;
      #$0a,'2'   : begin
                     l3f26:=l3f26+1;
                     l2080(l1fe7,l3f26-1);
                     write('         ');
                   end;
  end;
  l2080(l1fe7,l3f26);
  write(l1fe8[1]);
  l2080(l1fe7,l3f26+1);
  write(l1fe8[2]);
End;

procedure l2530(l3f11:byte);
Begin
  for l3f34:=9 downto 0 do
  begin
    if l3f3f[l3f34,3]=0 then
    begin
      l3f3f[l3f34,1]:=60;
      l3f3f[l3f34,2]:=l3f11;
      l3f3f[l3f34,3]:=1+random(6);
      exit;
    end;
  end;
End;

procedure l25f0;
Begin
  for l3f34:=1 to 9 do
  begin
    if ((l3f26=4) or (l3f26=12)) or
       (((l3f3f[l3f34,3]>0) and (l3f3f[l3f34,1] in [l1fe7-9..l1fe7+7])) and
       (l3f3f[l3f34,2] in [l3f26-1..l3f26+1])) then
    begin
      l2080(12,15);
      write('CRASH bei ',l3f36:1:1,' km.  Nochmal? (Y/N) ',#$82);
      for l3f34:=1 to 10 do
      begin
        write(#7);
        delay(50);
      end;
      repeat
        read(kbd,l3f3c);
        l3f3c:=upcase(l3f3c);
      until l3f3c in ['Y','J','N'];
      write(l3f3c,#$83);
      exit;
    end;
  end;
End;

BEGIN
  write(#$83,#7#7);
  l3f25:=(mem[CRTlines]-14) DIV 2;
  l3f24:=(mem[CRTcolumns]-62) DIV 2;
  repeat
    clrscr;
    l3f32:=24;
    l3f30:=100;
    l3f36:=0;
    l3f26:=8;
    l3f3d[1]:=5;
    l3f3d[2]:=35;
    for l3f34:=1 to 9 do l3f3f[l3f34,3]:=0;
    l3f2e:=0;
    l2080(8,1);
    write('GEISTERFAHRER - bis 1.5 km ist Dummheit !!!  ');
    for l3f34:=60 downto 1 do
    begin
      l2080(l3f34,4);
      write('=');
      l2080(l3f34,13);
      write('=');
    end;
    l2080(l1fe7,l3f26);
    write(l1fe8[1]);
    l2080(l1fe7,l3f26+1);
    write(l1fe8[2]);
    repeat
      if odd(l3f2e) then l20ad;
      if l3f2e=0 then
      begin
        repeat
          l3f27:=random(15);
        until l3f27 in [3,5..7,9..14];
        if (l3f27 and 1)=1 then l2530(5);
        if (l3f27 and 2)=2 then l2530(7);
        if (l3f27 and 4)=4 then l2530(9);
        if (l3f27 and 8)=8 then l2530(11);
      end;
      l21aa;
      if keypressed then l2411
                    else l3f3c:=#00;
      l25f0;
      l3f2e:=l3f2e+1;
      if l3f2e=l3f32 then
      begin
        l3f2e:=0;
        l3f30:=l3f30-5;
        if l3f30<0 then l3f30:=0;
        l3f36:=l3f36+0.1;
        l2080(26,15);
        write(#7,l3f36:1:1,' km');
        if round(l3f36*10) in [20,30,40,50] then l3f32:=l3f32-1;
      end;
      l2080(1,15);
      delay(l3f30);
    until l3f3c in [^C,'N','Y','J'];
  until l3f3c in [^C,'N'];
  l2080(14,2);
  write('Spalten(168H)=',mem[CRTcolumns],'  Zeilen(169H)=',mem[CRTlines]);
  l2080(60,14);
  write(#$82);
END.

