Exemple #1
0
        /// <summary>
        /// Initialize
        /// </summary>
        protected override void Initialize( )
        {
            base.Initialize( );

            _config = new ConfigurationService(_deviceMNG);
            _config.LoadConfiguration( );
            _config.AssignIngameConfiguration( );

            _canvas = new SpriteBatch(GraphicsDevice);

            _input   = new InputService( );
            _content = new ContentService(Content, GraphicsDevice, _canvas);

            // Console
            LOG.Add("Initializing console commands...");
            _console = new GameConsole(_input, _content, _config);
            _console.Initialize(_content);
            _console.SetAction("hide", 0, (args) => _console.IsVisible = false);
            _console.SetAction("exit", 0, (args) => Exit( ));
            _console.SetAction("debug", 0, (args) => _config.Change("debug_mode", !_config.DebugMode));
            _console.SetAction("translate", 1, (args) => LOG.Add(TranslationService.Get(args[0]), LogType.Success));
            _console.SetAction("new_game", 0, (args) => {
                _state.ChangeState(GameStateType.Gameplay);
                ((GameplayState)_state.GetCurrentState( )).NewGame(args.Length >= 1 ? args[0] : null);
                MediaPlayer.Stop( );
            });

            // Content
            LOG.Add("Loading application's content");
            DH.Content = _content;
            _content.LoadContent( );
            _content.UpdateDynamicContent(_config);

            // States
            LOG.Add("Initializing states...");
            _state = new StateService( );
            _state.Register(GameStateType.MainMenu, new MainMenuState(_content, _input, _config, _state, _console));
            _state.Register(GameStateType.Gameplay, new GameplayState(_content, _input, _config, _state, _console));
            _state.Register(GameStateType.Credits, new CreditsState( ));
            _state.Register(GameStateType.Settings, new SettingsState(_content, _input, _config, _state));
            _state.Register(GameStateType.Tutorial, new TutorialState( ));
            _state.Register(GameStateType.Pause, new PauseState(_content, _input, _config));
            _state.ChangeState(GameStateType.MainMenu);

            // Audio
            LOG.Add("Initializing audio...");
            MediaPlayer.IsRepeating = true; // Temporary
            AudioHelper.Music(_content.GetRandomSong( ));

            // Common
            LOG.Add("Finalizing initialization...");
            RandomService.Random = new Random( );
            TranslationService.LoadTranslations <LanguageModel>(_config.Language);

            LOG.Add($"App ready, version {VERSION}", LogType.Success);
        }