Uses CRT,Graph;
Var
 C :char;
 W : word;
 l,r,u,d : boolean;
 a : array [1..79, 1..24] of boolean;
{-----------------======================-----------------}
Procedure Ext;
var Gd, Gm :integer;
begin
  Sound(100);
  Delay(2000);
  Nosound;
  Gd := Detect;
  InitGraph(Gd, Gm, '');
  if GraphResult <> grOk then Halt(1);
  ClearDevice;
  SetColor(Magenta);
  SetTextStyle(TriplexFont, HorizDir,10);
  OutTextXY(150,100,'Game');
  OutTextXY(170,200,'OveR');
  ReadKey;
  CloseGraph;
  Halt
end; {Ext}
{-------------------------------------------------------}
Procedure StartUp;
var
  Gd, Gm : Integer;
begin
  Gd := Detect;
  InitGraph(Gd, Gm, '');
  if GraphResult <> grOk then Halt(1);
  ClearDevice;
  SetColor(Blue);
  SetTextStyle(3, HorizDir,8);
  OutTextXY(80,100,'Game Piton');
  SetColor(White);
  SetTextStyle(1,HorizDir,2);
  OutTextXY(200,450,'///Press any key\\\');
  ReadKey;
  CloseGraph
end; {StartUp}
{------------------==================-------------------}
Procedure Game;
begin
  l := false;
  r := false;
  u := false;
  d := false;
  clrscr;
  GotoXY(40,13);
  repeat
    c := readkey;
    if c = #0 then
      Begin
        w := ord(readkey);
        case w of
          77 : begin
                 if WhereX > 78 then ext;
                   if u then
                     begin
                       GotoXY(WhereX-1,WhereY);
                       Write('É');
                       a[WhereX-1,WhereY] := true;
                       u := false;
                     end;
                   if d then
                     begin
                       GotoXY(WhereX-1,WhereY);
                       Write('È');
                       a[WhereX-1,WhereY] := true;
                       d := false;
                     end;
                     if a[WhereX,WhereY] then ext;
                     Write('Í');
                     a[WhereX-1,WhereY] := true;
                     l := false;
                     r := true;
               end;
          75 : Begin
                 if WhereX > 2 then
                   begin
                     if u then
                       begin
                         GotoXY(WhereX-1,WhereY);
                         Write('»');
                         a[WhereX-1,WhereY] := true;
                         u := false
                       end;
                     if d then
                       begin
                         GotoXY(WhereX-1,WhereY);
                         Write('¼');
                         a[WhereX-1,WhereY] := true;
                         d := false
                       end;
                       if a[WhereX-2,WhereY] then ext;
                       GotoXY(WhereX - 2, WhereY);
                       Write('Í');
                       a[WhereX-1,WhereY] := true;
                       r := false;
                       l := true
                   end
                 else ext;
                 end;
          72 : begin
                 if WhereY > 2 then
                   begin
                     if l then
                       begin
                         GotoXY(WhereX-1,WhereY);
                         Write('È');
                         a[WhereX-1,WhereY] := true;
                         l := false
                       end;
                     if r then
                       begin
                         GotoXY(WhereX-1,WhereY);
                         Write('¼');
                         a[WhereX-1,WhereY] := true;
                         r := false
                       end;
                       if a[WhereX-1,WhereY-1] then ext;
                       GotoXY(WhereX - 1, WhereY - 1);
                       Write('º');
                       a[WhereX-1,WhereY] := true;
                       d := false;
                       u := true
                 end
                 else ext;
               end;
          80 : begin
                 if WhereY < 24 then
                   begin
                     if l then
                       begin
                         GotoXY(WhereX-1,WhereY);
                         Write('É');
                         a[WhereX-1,WhereY] := true;
                         l := false
                       end;
                     if r then
                       begin
                         GotoXY(WhereX-1,WhereY);
                         Write('»');
                         a[WhereX-1,WhereY] := true;
                         r := false
                       end;
                       if a[WhereX-1,WhereY+1] then ext;
                       GotoXY(WhereX-1,WhereY + 1);
                       Write('º');
                       a[WhereX-1,WhereY] := true;
                       u := false;
                       d := true;
                   end
                 else ext;
               end;
        Else ClrScr;
        end;
      end;
  Until c = #27;
  ext;
end;{game}
{----------------------------------------------------------------------}
Begin
  StartUp;
  Game
end.
