classdef appLab_4_3_2 < matlab.apps.AppBase

  % Properties that correspond to app components
  properties (Access = public)
    UIFigure        matlab.ui.Figure
    DateiMenu       matlab.ui.container.Menu
    NeuesSpielMenu  matlab.ui.container.Menu
    BeendenMenu     matlab.ui.container.Menu
    InfoMenu        matlab.ui.container.Menu
    UIAxes          matlab.ui.control.UIAxes
  end

  properties (Access = public)
    thisLab   % Objekt der Klasse Labyrinth
  end

  % Callbacks that handle component events
  methods (Access = private)

    % Code that executes after component creation
    function startupFcn(app)
      app.thisLab = Labyrinth_2( app.UIAxes );
      app.thisLab = lade_spiel( app.thisLab );
    end

    % Menu selected function: NeuesSpielMenu
    function NeuesSpielMenuSelected(app, event)
      app.thisLab = lade_spiel( app.thisLab );      
    end

    % Menu selected function: BeendenMenu
    function BeendenMenuSelected(app, event)
      delete( app.UIFigure );
    end

    % Menu selected function: InfoMenu
    function InfoMenuSelected(app, event)
      msgbox( 'Labyrinth-Spiel, (c) U. Stein, 2022' );
    end

    % Key press function: UIFigure
    function UIFigureKeyPress(app, event)
      key = event.Key; 
      app.thisLab = app.thisLab.ziehe( key );
    end
  end

  % Component initialization
  methods (Access = private)

    % Create UIFigure and components
    function createComponents(app)

      % Create UIFigure and hide until all components are created
      app.UIFigure = uifigure('Visible', 'off');
      app.UIFigure.Position = [100 100 600 400];
      app.UIFigure.Name = 'MATLAB App';
      app.UIFigure.KeyPressFcn = createCallbackFcn(app, @UIFigureKeyPress, true);

      % Create DateiMenu
      app.DateiMenu = uimenu(app.UIFigure);
      app.DateiMenu.Text = 'Datei';

      % Create NeuesSpielMenu
      app.NeuesSpielMenu = uimenu(app.DateiMenu);
      app.NeuesSpielMenu.MenuSelectedFcn = createCallbackFcn(app, @NeuesSpielMenuSelected, true);
      app.NeuesSpielMenu.Text = 'Neues Spiel';

      % Create BeendenMenu
      app.BeendenMenu = uimenu(app.DateiMenu);
      app.BeendenMenu.MenuSelectedFcn = createCallbackFcn(app, @BeendenMenuSelected, true);
      app.BeendenMenu.Text = 'Beenden';

      % Create InfoMenu
      app.InfoMenu = uimenu(app.UIFigure);
      app.InfoMenu.MenuSelectedFcn = createCallbackFcn(app, @InfoMenuSelected, true);
      app.InfoMenu.Text = 'Info';

      % Create UIAxes
      app.UIAxes = uiaxes(app.UIFigure);
      title(app.UIAxes, 'Labyrinth Max-Züge')
      zlabel(app.UIAxes, 'Z')
      app.UIAxes.XColor = [1 1 1];
      app.UIAxes.XTick = [];
      app.UIAxes.YColor = [1 1 1];
      app.UIAxes.YTick = [];
      app.UIAxes.Position = [2 1 599 400];

      % Show the figure after all components are created
      app.UIFigure.Visible = 'on';
    end
  end

  % App creation and deletion
  methods (Access = public)

    % Construct app
    function app = appLab_4_3_2

      % Create UIFigure and components
      createComponents(app)

      % Register the app with App Designer
      registerApp(app, app.UIFigure)

      % Execute the startup function
      runStartupFcn(app, @startupFcn)

      if nargout == 0
        clear app
      end
    end

    % Code that executes before app deletion
    function delete(app)

      % Delete UIFigure when app is deleted
      delete(app.UIFigure)
    end
  end
end