Пример #1
0
        /// <summary>
        /// Обработка команды контроллера внутри логики модели.
        /// </summary>
        /// <param name="parCommand">Команда.</param>
        protected override void HandleCommand(ModelCommand parCommand)
        {
            _stateMachine.ChangeState(parCommand);
            SelectedMenuItem = _stateMachine.SelectedMenuItem;
            MenuHeader       = _stateMachine.MenuHeader;
            switch (_stateMachine.CurrentCommand)
            {
            case ModelStateMachineCommand.LoadMenu:
                LoadAnotherModel?.Invoke(GameModelType.Menu);
                break;

            case ModelStateMachineCommand.LoadLevel:
                LoadAnotherModel?.Invoke(GameModelType.Level, _stateMachine.SelectedMenuItem);
                break;

            case ModelStateMachineCommand.LoadFirstLevel:
                int firstLevelID = LevelLoader.CheckAvailableLevels().Min();
                LoadAnotherModel?.Invoke(GameModelType.Level, firstLevelID);
                break;

            case ModelStateMachineCommand.LoadLastLevel:
                int lastLevelID = SaveFile.GetInstance().LevelToLoad;
                LoadAnotherModel?.Invoke(GameModelType.Level, lastLevelID);
                break;

            case ModelStateMachineCommand.Exit:
                CloseApplication?.Invoke();
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Обработка команды контроллера внутри логики модели.
        /// </summary>
        /// <param name="parCommand">Команда.</param>
        protected override void HandleCommand(ModelCommand parCommand)
        {
            _stateMachine.ChangeState(parCommand);
            SelectedMenuItem = _stateMachine.SelectedMenuItem;
            MenuHeader       = _stateMachine.MenuHeader;
            ShadowLevel      = _stateMachine.ShadowLevel;
            switch (_stateMachine.CurrentCommand)
            {
            case ModelStateMachineCommand.Pause:
                this.Pause();
                break;

            case ModelStateMachineCommand.Resume:
                this.Resume();
                break;

            case ModelStateMachineCommand.LoadMenu:
                this.Stop();
                LoadAnotherModel?.Invoke(GameModelType.Menu);
                break;

            case ModelStateMachineCommand.LoadLevel:
                this.Stop();
                LoadAnotherModel?.Invoke(GameModelType.Level, _model.LevelID);
                break;

            case ModelStateMachineCommand.LoadNextLevel:
                this.Stop();
                try
                {
                    List <int> levels        = LevelLoader.CheckAvailableLevels().OrderBy(x => x).ToList();
                    int        currentNumber = levels.FindIndex(x => x == _model.LevelID);
                    int        nextLevelID   = levels[currentNumber + 1];
                    LoadAnotherModel?.Invoke(GameModelType.Level, nextLevelID);
                }
                catch
                {
                    LoadAnotherModel?.Invoke(GameModelType.Menu);
                }
                break;
            }
        }