Exemple #1
0
        public RellowGame(
            IScreenTransformationMatrixProvider matrixScaleProvider,
            AssetsLoader assetsLoader,
            GameOrchestrator gameOrchestrator,
            SoundManager soundManager,
            ISettingsRepository settingsRepository,
            ILocalizedStringsRepository localizedStringsRepository)
        {
            _localizedStringsRepository = localizedStringsRepository;
            _matrixScaleProvider        = matrixScaleProvider ?? throw new ArgumentNullException(nameof(matrixScaleProvider));

            _gameButtonsManager = new GameButtonsManager(
                assetsLoader,
                localizedStringsRepository,
                new Vector2(60f, 800f));

            _scoreDifferentialPopups = new List <PopupText>();

            _soundManager       = soundManager ?? throw new ArgumentNullException(nameof(soundManager));
            _gameOrchestrator   = gameOrchestrator ?? throw new ArgumentNullException(nameof(gameOrchestrator));
            _settingsRepository = settingsRepository ?? throw new ArgumentNullException(nameof(settingsRepository));

            _currentGameState = GameStates.PlayingWaitingForInput;
            _gameColors       = new UIColors(_gameButtonsManager.SpawnableColors.Select(c => c.ColorGraphic).ToArray());

            _choiceTime = TimeSpan.FromSeconds(2.5);

            _backgroundRectangle = new Rectangle(0, 0, matrixScaleProvider.VirtualWidth, matrixScaleProvider.VirtualHeight);

            _scoreTextTitle = localizedStringsRepository.Get(GameStringsLoader.ScoreStringKey);

            _gameButtonsManager = new GameButtonsManager(
                assetsLoader,
                localizedStringsRepository,
                new Vector2(60f, 720f));
            _gameButtonsManager.OnLost += _gameButtonsManager_OnLost;
            _gameButtonsManager.OnWon  += _gameButtonsManager_OnWon;

            _writingFont = assetsLoader.WritingFont;

            _colorTextBackgroundRectangle = new Rectangle(
                0, 500,
                matrixScaleProvider.VirtualWidth,
                120);

            _numberOfVictories = 0;
            _score             = 0;

            _timeProgressBar = new ProgressBar(
                new Rectangle(
                    0, 0,
                    matrixScaleProvider.VirtualWidth,
                    matrixScaleProvider.VirtualHeight),
                _gameColors.TimerBarColor,
                (int)_choiceTime.TotalMilliseconds);

            UpdateScoreString();
            NewRound();
        }
        private void LoadGameAssets()
        {
            new GameStringsLoader(_localizedStringsRepository, _gameCulture);

            _assetsLoader = new AssetsLoader(
                Content,
                _textFileAssetsLoader);
            _mousePointer = _assetsLoader.Sprites["manina"];
            _soundManager = new SoundManager(_assetsLoader);

            var gameFactory = new Func <RellowGame>(
                () => new RellowGame(
                    _matrixScaleProvider,
                    _assetsLoader,
                    _orchestrator,
                    _soundManager,
                    _settingsRepository,
                    _localizedStringsRepository));

            var dialogDefinition = new Rectangle(
                100, 550, _matrixScaleProvider.VirtualWidth - 200, _matrixScaleProvider.VirtualHeight / 3);
            var rateMeDialog = new RateMeDialog(
                launchesUntilPrompt: 2,
                maxRateShowTimes: 2,
                rateAppUri: _rateMeUri,
                dialogDefinition: dialogDefinition,
                font: _assetsLoader.WritingFont,
                localizedStringsRepository: _localizedStringsRepository,
                rateMeDialogStrings: _gameCulture.TwoLetterISOLanguageName == "it" ? (RateMeDialogStrings) new DefaultItalianRateMeDialogStrings(_gameName) : (RateMeDialogStrings) new DefaultEnglishRateMeDialogStrings(_gameName),
                webPageOpener: _webPageOpener,
                settingsRepository: _settingsRepository,
                buttonADefinition: new Rectangle(
                    dialogDefinition.X + dialogDefinition.Width / 2 - 250,
                    dialogDefinition.Y + 350,
                    500, 100),
                buttonBDefinition: new Rectangle(
                    dialogDefinition.X + dialogDefinition.Width / 2 - 250,
                    dialogDefinition.Y + 500,
                    500, 100),
                backgroundColor: Color.DarkGray.WithAlpha(1f),
                buttonsBackgroundColor: Definitions.PrimaryBackgroundColor.WithAlpha(1f),
                buttonsShadowColor: Color.Black,
                backgroundShadowColor: Color.Black.WithAlpha(1f),
                titleColor: Color.Black,
                buttonsTextColor: Definitions.PrimaryForegroundColor,
                titlePositionOffset: new Vector2(dialogDefinition.Width / 2, 80f),
                buttonTextPadding: 60f,
                titlePadding: 90f);

            var mainMenuFactory = new Func <MainMenuPage>(
                () => new MainMenuPage(
                    _assetsLoader,
                    _orchestrator,
                    _matrixScaleProvider,
                    _localizedStringsRepository,
                    rateMeDialog,
                    _settingsRepository));

            _orchestrator = new GameOrchestrator(
                gameFactory,
                mainMenuFactory,
                GraphicsDevice,
                _matrixScaleProvider,
                _soundManager,
                _webPageOpener);

            _inputListeners = new List <IInputListener>();

            if (_isPc)
            {
                var mouseListener = new MouseListener(_matrixScaleProvider);
                mouseListener.MouseDown += MouseListener_MouseClicked;
                _inputListeners.Add(mouseListener);
            }
            else
            {
                var touchListener = new TouchListener(_matrixScaleProvider);
                touchListener.TouchStarted += TouchListener_TouchEnded;

                var gamepadListener = new GamePadListener();
                gamepadListener.ButtonDown += GamepadListener_ButtonDown;

                _inputListeners.Add(touchListener);
                _inputListeners.Add(gamepadListener);
            }

            // Perchè il back di Android lo prende la tastiera
            var keyboardListener = new KeyboardListener();

            keyboardListener.KeyPressed += KeyboardListener_KeyPressed;
            _inputListeners.Add(keyboardListener);
        }