title: creating a pause menu in delphi
body: <p>Background: I have created a maze game that is playable, however when the maze gets bigger there are more chances to go wrong and takes ages to reach the start of the maze again, I've been told that's really annoying.</p>
  
  <p>Question: I want to create a pause game function that when the user presses the button key a menu pops up that allows the user to be able to either return to main menu or restart the maze.</p>
  
  <p>I have very little knowledge on where to start this in the code as I don't want to mess up anything that has already been added.</p>
  
  <p>I've added the draw maze //creates the maze, 
  initialise visited and walk // removes the walls of the maze, 
  Form key down//moves the player 
  and Timer//collision detection procedures below. </p>
  
  <p>hopefully someone can help?</p>
  
  <p>Many Thanks.</p>
  
  <pre><code>`procedure TfrmMazeDesign.draw_maze(square_size: integer);
        var
          row, col : integer;
  
  
        begin
           // setup default walls as "WWWW" wall on all four sides.
          SetLength(Shapes,height+3, width+3, 2 ) ;
  
          for row := 1 to  height do
              begin
                  for col := 1 to width+2 do
                    begin
  
                        Shapes[row,col,0]:= TShape.Create(Self);
                        Shapes[row,col,0].Parent := Self;
  
                        with Shapes[row,col,0] do
                        begin
                          Width := 5;
                          Height := square_size;
                          Left := 100+ ((col-1) * square_size);
                          Top := 50+ ((row-1) * square_size);
                          Brush.Color := RGB(255, 255,25);
                          Shape := stRectangle;
                        end;
  
  
                    end;
              end;
  
  
          for row := 1 to height+1  do
              begin
                  for col := 1 to width+1 do
                    begin
  
                        Shapes[row,col,1]:= TShape.Create(Self);
                        Shapes[row,col,1].Parent := Self;
  
                        with Shapes[row,col,1] do
                        begin
                          Width := square_size;
                          Height := 5;
                          Left := 100+ ((col-1) * square_size);
                          Top :=  50+ ((row-1) * square_size);
                          Brush.Color := RGB(255, 255,25);
                          Shape := stRectangle;
                        end;
  
                   end;
            end;
  
  
        end;
  
  
  
  
  procedure  TfrmMazeDesign.initialise_visited(var visited: Tvisited);
  
  var
    row, col: integer;
  
  
  begin
  
    for  row := 0 to height+2 do
      for col := 0 to width+2  do
        if (col = 0) or (row = 0) or (row = height+1) or (col= width+2) then
          visited[row,col] := True
        else
          visited[row,col] := False;
  
  
  
  end;
  
  
  
  
  procedure TFrmMazeDesign.walk(visited: Tvisited; x: integer; y:integer);
    var
      xx,yy, counter, ran_direction: integer;
      direction: Tstringlist;  //  1= Up, 2= right, 3 = down, 4 = left
      text: string;
  
  
  begin
     visited[x,y] := True;
     direction  := TStringlist.Create;
     direction.Add('1');
     direction.Add('2');
     direction.Add('3');
     direction.Add('4');
     for counter := direction.Count - 1 downto 0 do
        direction.Exchange(counter, Random(counter+1));
  
  
  
     for counter := 0 to direction.Count-1 do
        begin
         ran_direction := StrtoInt(direction[counter]);
         if ran_direction= 1 then
            begin
              xx := x-1;
              yy := y
            end;
         if ran_direction = 2 then
            begin
              xx := x+1;
              yy := y
            end;
         if ran_direction = 3 then
            begin
              xx := x;
              yy := y-1
            end;
         if ran_direction= 4 then
            begin
              xx := x;
              yy := y+1
            end;
  
  
         if  visited[xx,yy] = False then
            begin
              if xx = x then
                  shapes[x,Max(yy,y),0].visible := False;
              if yy = y then
                  shapes[Max(xx,x),y,1].visible := False;
               walk (visited, xx,yy)
             end;
        end;
  
  end;
  
  
  procedure TfrmMazeDesign.FormKeyDown(Sender: TObject; var Key: Word;
    Shift: TShiftState);
    begin
  case Key of
      VK_UP:
      direction := 1;
      VK_DOWN:
      direction := 2;
      VK_LEFT:
      direction := 3;
      VK_RIGHT:
      direction := 4;
    end;
  
  end;
  
  procedure TfrmMazeDesign.FormOpen(Sender: TObject);
  var
  
    block_height: integer;
    xx,yy: integer;
    visited: Tvisited;
    monster, monster2: TMonster;
  
    Shape_height : integer;
    Shape_Width : integer;
    imgfinish_height : integer;
    maze_width : integer;
  
  
  begin
  
    width := frmdifficulty.ScrollBar1.Position;
    height := frmdifficulty.ScrollBar1.Position;
    maze_width := 650;
  
    block_height := maze_width div width;
    Shape_height :=  round( block_height * 0.5);
    imgfinish_height := round(block_height * 0.5);
  
    draw_maze(block_height);
    SetLength(visited, height+10, width+10) ;
    initialise_visited(visited);
    walk(visited,3,3);
    ShpUser.height := Shape_height;
    ShpUser.Width  := Shape_height;
    imgfinish.width := Shape_height;
    imgfinish.height := shape_height;
  
  
    ShpUser.Shape := UShapeEditor.frmShape.shpShape.Shape;
    ShpUser.Brush.color := UShapeEditor.frmShape.shpShape.Brush.color;
  
    FDateTimeTo := StrToDateTime(FormatDateTime('dd' + FormatSettings.DateSeparator + 'mm' +
    FormatSettings.DateSeparator + 'yyyy', Now)); Incsecond(time,120);
  
    Timer1.Enabled := True;
  
  
    monster := TMonster.Create(Self);
    monster.Parent := Self;
    monster.SetSizes(width, height, shape_height, 55+ maze_width + 10,665);
    monster.start;
  
    monster2 := TMonster.Create(Self);
    monster2.Parent := Self;
    monster2.SetSizes(width, height, shape_height, 50+ maze_width + 10,565);
    monster2.start;
  
    end;
  
  procedure TfrmMazeDesign.Timer1Timer(Sender: TObject);
  
  var IntersectionRect: TRect;
      collision, test_collision : boolean;
      up : boolean;
      right : boolean;
      max_width, max_height : integer;
      xx, yy : integer ;
      aRect1: TRect;
      buttonSelected : Integer;
      collisionend: boolean;
      frmMazeDesign: TfrmMazeDesign;
      row, col, hoz_vert : integer;
  begin
  
    hoz_vert := 0;
  
    xx := 0;
    yy := 0;
  
    case direction of
      1:begin        //Up
            yy := -3;
        end;
      2: begin       //down
            yy := + 3;
         end;
  
      3:  begin      //left
             xx := -3;
         end;
  
      4:  begin        //right
             xx := + 3;
          end;
  
    end;
  
  
    repeat
      if hoz_Vert = 0 then begin
        max_width := width +3;
        max_height := Height+1;
      end else begin
        max_width := width+2;
        max_height := Height+2;
      end;
  
      row := 1;
      repeat
        col := 1;
  
  
        repeat
          aRect1 := Rect(ShpUser.Left+xx, ShpUser.Top+yy, ShpUser.Left+ShpUser.width+xx, ShpUser.top+ ShpUser.Height+yy);
          if Shapes[row,col,hoz_vert].visible = True then
            collision :=  IntersectRect(IntersectionRect, aRect1, Shapes[row,col,hoz_vert].BoundsRect)  ;
  
          col := col + 1;
  
        until (collision) or (col = max_width);
        row := row + 1 ;
      until (collision) or (row = max_height);
      hoz_vert := hoz_vert +1;
    until (collision) or (hoz_vert = 2);
  
    if (collision = False) and (direction &lt;&gt; 0) then begin
      ShpUser.Top := ShpUser.Top + yy;
      ShpUser.Left := ShpUser.Left + xx;
    end;
  
  
        if IntersectRect(IntersectionRect, imgfinish.BoundsRect, Shpuser.BoundsRect) then
        begin
        Collisionend := true;
        if collisionend = true  then
         frmfinish.Show;
          direction:= 0;
        end;`
  </code></pre>