Example #1
0
        public ScorePage(
            AssetsLoader assets,
            ISettingsRepository settingsRepository,
            IScreenTransformationMatrixProvider matrixScaleProvider,
            ILocalizedStringsRepository localizedStringsRepository)
        {
            _font                = assets.Font;
            _background          = assets.OtherSprites["scoreBackground"];
            _matrixScaleProvider = matrixScaleProvider;

            _titleText          = localizedStringsRepository.Get(GameStringsLoader.ScorePageTitleString);
            _titleScalingObject = new ScalingObject(1f, 1.2f, 1.0f);
            _titleDrawingInfos  = new DrawingInfos()
            {
                Position = new Vector2(matrixScaleProvider.VirtualWidth / 2f, 100f),
                Origin   = _font.GetTextCenter(_titleText)
            };

            float textsScale = 0.4f;

            var bestFarts           = settingsRepository.GetOrSetInt(GameScores.BestFartsScoreKey, default);
            var bestNumberOfMeters  = settingsRepository.GetOrSetInt(GameScores.BestNumberOfMetersScoreKey, default);
            var bestVegetablesEaten = settingsRepository.GetOrSetInt(GameScores.BestVegetablesEatenScoreKey, default);

            _scoreInfos = new List <ScoreRecordText>()
            {
                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.BestNumberOfMetersScoreKey)}{bestNumberOfMeters}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_titleDrawingInfos.Position.X / 2, _titleDrawingInfos.Position.Y + 100f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                }),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.BestVegetablesEatenScoreKey)}{bestVegetablesEaten}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_titleDrawingInfos.Position.X / 2, _titleDrawingInfos.Position.Y + 140f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                }),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.BestFartsScoreKey)}{bestFarts}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_titleDrawingInfos.Position.X / 2, _titleDrawingInfos.Position.Y + 180f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                }),
            };

            _nTexts        = _scoreInfos.Count;
            _currentTextId = 0;
            _fadeObject    = new FadeObject(TimeSpan.FromMilliseconds(500), Color.White);
            _fadeObject.FadeInCompleted += _textFadeObject_FadeInCompleted;
            _fadeObject.FadeIn();
        }
Example #2
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();
        }
Example #3
0
        private void HandleLost()
        {
            _soundManager.PlayLoose();
            var currentRecord = _settingsRepository.GetOrSetInt(Definitions.SCORE_KEY, 0);

            var scoreTextGameover = $"{_localizedStringsRepository.Get(GameStringsLoader.ScoreStringKey)}:{_score}";

            if (_score > currentRecord)
            {
                _settingsRepository.SetInt(Definitions.SCORE_KEY, _score);
                scoreTextGameover = $"{scoreTextGameover}\nRECORD!";
            }

            _currentGameState     = GameStates.Lost;
            _gameOverOverlayPopup = new OverlayPopup(
                "GAME OVER",
                scoreTextGameover,
                _writingFont,
                _matrixScaleProvider,
                _localizedStringsRepository,
                () => _gameOrchestrator.Replay(),
                () => _gameOrchestrator.SetMenuState());
        }
Example #4
0
        public GameButtonsManager(
            AssetsLoader assetsLoader,
            ILocalizedStringsRepository localizedStringsRepository,
            Vector2 startingPosition)
        {
            _buttons             = new GameButton[_totalNumberOfButtons];
            _activeButtonsNumber = 3;
            _startingPosition    = startingPosition;

            SpawnableColors = new ColorWithName[]
            {
                new ColorWithName(
                    Color.Yellow,
                    localizedStringsRepository.Get(GameStringsLoader.YellowColorKey),
                    localizedStringsRepository.Get(GameStringsLoader.SecondaryLanguageYellowColorKey)),

                new ColorWithName(
                    Color.Red,
                    localizedStringsRepository.Get(GameStringsLoader.RedColorKey),
                    localizedStringsRepository.Get(GameStringsLoader.SecondaryLanguageRedColorKey)),

                new ColorWithName(
                    Color.Blue,
                    localizedStringsRepository.Get(GameStringsLoader.BlueColorKey),
                    localizedStringsRepository.Get(GameStringsLoader.SecondaryLanguageBlueColorKey)),

                new ColorWithName(
                    new Color(0, 255, 0),
                    localizedStringsRepository.Get(GameStringsLoader.GreenColorKey),
                    localizedStringsRepository.Get(GameStringsLoader.SecondaryLanguageGreenColorKey)),

                new ColorWithName(
                    new Color(255, 115, 0),
                    localizedStringsRepository.Get(GameStringsLoader.OrangeColorKey),
                    localizedStringsRepository.Get(GameStringsLoader.SecondaryLanguageOrangeColorKey)),

                new ColorWithName(
                    new Color(255, 0, 255),
                    localizedStringsRepository.Get(GameStringsLoader.VioletColorKey),
                    localizedStringsRepository.Get(GameStringsLoader.SecondaryLanguageVioletColorKey)),

                new ColorWithName(
                    new Color(150, 150, 150),
                    localizedStringsRepository.Get(GameStringsLoader.GrayColorKey),
                    localizedStringsRepository.Get(GameStringsLoader.SecondaryLanguageGrayColorKey)),

                new ColorWithName(
                    Color.White,
                    localizedStringsRepository.Get(GameStringsLoader.WhiteColorKey),
                    localizedStringsRepository.Get(GameStringsLoader.SecondaryLanguageWhiteColorKey)),

                new ColorWithName(
                    new Color(0, 255, 255),
                    localizedStringsRepository.Get(GameStringsLoader.LightBlueColorKey),
                    localizedStringsRepository.Get(GameStringsLoader.SecondaryLanguageLightBlueColorKey))
            };

            for (int c = 0; c < 3; ++c)
            {
                for (int r = 0; r < 3; ++r)
                {
                    int index = (c * 3) + r;
                    _buttons[index] = new GameButton(
                        assetsLoader,
                        _squaredButtonSize,
                        SpawnableColors[index]);
                }
            }
        }
Example #5
0
        public OverlayPopup(
            string title,
            string text,
            SpriteFont font,
            IScreenTransformationMatrixProvider matrixScaleProvider,
            ILocalizedStringsRepository localizedStringsRepository,
            Action playAgainFunction,
            Action exitFunction)
        {
            _font = font;

            _backgroundRectangle = new Rectangle(0, 0, matrixScaleProvider.VirtualWidth, matrixScaleProvider.VirtualHeight);
            _backgroundColor     = Color.Gray.WithAlpha(0.7f);

            int popupRectangleWidth = 900;

            _popupRectangle = new Rectangle(
                (matrixScaleProvider.VirtualWidth - popupRectangleWidth) / 2, 260,
                popupRectangleWidth, popupRectangleWidth + 200);
            _popupBackgroundColor = Definitions.PrimaryBackgroundColor.WithAlpha(1f);

            _popupRectangleShadow = new Rectangle(
                _popupRectangle.X + 15,
                _popupRectangle.Y + 15,
                _popupRectangle.Width,
                _popupRectangle.Height);
            _popupShadowBackgroundColor = Color.Black.WithAlpha(1f);

            _titleDrawingInfos = new DrawingInfos()
            {
                Position = new Vector2(
                    matrixScaleProvider.VirtualWidth / 2,
                    _popupRectangle.Y + _popupRectangle.Height / 4),
                Origin       = _font.GetTextCenter(title),
                OverlayColor = Color.Black
            };

            _textDrawingInfos = new DrawingInfos()
            {
                Position     = _titleDrawingInfos.Position + new Vector2(0f, 200f),
                Origin       = _font.GetTextCenter(text),
                Scale        = 0.6f,
                OverlayColor = Color.White
            };

            TitleText = title;
            Text      = text;

            _playAgainButton = new FloatingTextButton(
                localizedStringsRepository.Get(GameStringsLoader.PlayAgainStringKey),
                new DrawingInfos()
            {
                Position     = _textDrawingInfos.Position + new Vector2(0f, 250f),
                Origin       = _font.GetTextCenter(localizedStringsRepository.Get(GameStringsLoader.PlayAgainStringKey)),
                OverlayColor = Definitions.PrimaryForegroundColor,
            },
                _font,
                playAgainFunction,
                0.7f, 0.8f);

            _exitButton = new FloatingTextButton(
                localizedStringsRepository.Get(GameStringsLoader.ExitStringKey),
                new DrawingInfos()
            {
                Position     = _textDrawingInfos.Position + new Vector2(0f, 450f),
                Origin       = _font.GetTextCenter(localizedStringsRepository.Get(GameStringsLoader.ExitStringKey)),
                OverlayColor = Definitions.PrimaryForegroundColor
            },
                _font,
                exitFunction,
                0.7f, 0.8f);
        }
Example #6
0
        public MainMenuPage(
            AssetsLoader assetsLoader,
            GameOrchestrator gameOrchestrator,
            IScreenTransformationMatrixProvider matrixScaleProvider,
            ILocalizedStringsRepository localizedStringsRepository,
            RateMeDialog rateMeDialog,
            ISettingsRepository settingsRepository)
        {
            _backgroundRectangle = new Rectangle(0, 0, matrixScaleProvider.VirtualWidth, matrixScaleProvider.VirtualHeight);

            var titleFont = assetsLoader.TitleFont;

            _writingFont  = assetsLoader.WritingFont;
            _rateMeDialog = rateMeDialog ?? throw new ArgumentNullException(nameof(rateMeDialog));

            const string titleText = "RELLOW";

            _title = new FloatingText(
                titleText,
                new DrawingInfos()
            {
                Position     = new Vector2(matrixScaleProvider.VirtualWidth / 2f, 250f),
                Origin       = titleFont.GetTextCenter(titleText),
                OverlayColor = _foregroundColor
            },
                titleFont);

            var playText = localizedStringsRepository.Get(GameStringsLoader.PlayStringKey);

            _playButton = new FloatingTextButton(
                playText,
                new DrawingInfos()
            {
                Position     = new Vector2(matrixScaleProvider.VirtualWidth / 2f, 850f),
                Origin       = _writingFont.GetTextCenter(playText),
                OverlayColor = _foregroundColor
            },
                _writingFont,
                () =>
            {
                gameOrchestrator.SetGameState();
            });

            var aboutText = localizedStringsRepository.Get(GameStringsLoader.AboutStringKey);

            _aboutButton = new FloatingTextButton(
                aboutText,
                new DrawingInfos()
            {
                Position     = new Vector2(matrixScaleProvider.VirtualWidth / 2f, 1150f),
                Origin       = _writingFont.GetTextCenter(aboutText),
                OverlayColor = _foregroundColor
            },
                _writingFont,
                () =>
            {
                gameOrchestrator.SetAboutState();
            });

            var currentScore = settingsRepository.GetOrSetInt(Definitions.SCORE_KEY, 0);

            _scoreText         = $"{localizedStringsRepository.Get(GameStringsLoader.ScoreStringKey)}:{currentScore}";
            _scoreDrawingInfos = new DrawingInfos()
            {
                Position     = new Vector2(matrixScaleProvider.VirtualWidth / 2f, matrixScaleProvider.VirtualHeight - 250f - 200f),
                Origin       = _writingFont.GetTextCenter(_scoreText),
                OverlayColor = _scoreColor,
                Scale        = 0.5f
            };
        }
Example #7
0
        public GameOverPage(
            IScreenTransformationMatrixProvider matrixScaleProvider,
            AssetsLoader assets,
            ISettingsRepository settingsRepository,
            int thisGameNumberOfVegetablesEaten,
            int thisGameNumberOfMeters,
            int thisGameNumberOfFarts,
            ILocalizedStringsRepository localizedStringsRepository)
        {
            _font                = assets.Font;
            _background          = assets.OtherSprites["gameoverBackground"];
            _matrixScaleProvider = matrixScaleProvider;

            _gameOverTextDrawingInfos = new DrawingInfos()
            {
                Position = new Vector2()
                {
                    X = matrixScaleProvider.VirtualWidth / 2f, Y = 100f
                },
                Origin = _font.GetTextCenter(_gameOverText)
            };
            _gameOverScalingObject = new ScalingObject(1f, 1.2f, 1.0f);

            var bestFarts           = settingsRepository.GetOrSetInt(GameScores.BestFartsScoreKey, default(int));
            var bestNumberOfMeters  = settingsRepository.GetOrSetInt(GameScores.BestNumberOfMetersScoreKey, default(int));
            var bestVegetablesEaten = settingsRepository.GetOrSetInt(GameScores.BestVegetablesEatenScoreKey, default(int));

            var bestNumberOfVegetablesEatenRecord = false;

            if (thisGameNumberOfVegetablesEaten > bestVegetablesEaten)
            {
                settingsRepository.SetInt(GameScores.BestVegetablesEatenScoreKey, thisGameNumberOfVegetablesEaten);
                bestNumberOfVegetablesEatenRecord = true;
            }

            var bestAliveTimeRecord = false;

            if (thisGameNumberOfMeters > bestNumberOfMeters)
            {
                settingsRepository.SetInt(GameScores.BestNumberOfMetersScoreKey, thisGameNumberOfMeters);
                bestAliveTimeRecord = true;
            }

            var bestNumberOfFartsRecord = false;

            if (thisGameNumberOfFarts > bestFarts)
            {
                settingsRepository.SetInt(GameScores.BestFartsScoreKey, thisGameNumberOfFarts);
                bestNumberOfFartsRecord = true;
            }

            const float textsScale = 0.4f;

            _scoreInfos = new List <ScoreRecordText>()
            {
                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.NumberOfMetersString)}{thisGameNumberOfMeters}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_gameOverTextDrawingInfos.Position.X / 2, _gameOverTextDrawingInfos.Position.Y + 200f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                },
                    !bestAliveTimeRecord ? "       " : "Record!"),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.NumbersOfFartsString)}{thisGameNumberOfFarts}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_gameOverTextDrawingInfos.Position.X / 2, _gameOverTextDrawingInfos.Position.Y + 125f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                },
                    !bestNumberOfFartsRecord ? "       " : "Record!"),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.NumberOfVegetablesEaten)}{thisGameNumberOfVegetablesEaten}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_gameOverTextDrawingInfos.Position.X / 2, _gameOverTextDrawingInfos.Position.Y + 162f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                },
                    !bestNumberOfVegetablesEatenRecord ? "       " : "Record!"),
            };

            _nTexts        = _scoreInfos.Count;
            _currentTextId = 0;
            _fadeObject    = new FadeObject(TimeSpan.FromMilliseconds(200), Color.White);
            _fadeObject.FadeInCompleted += _textFadeObject_FadeInCompleted;
            _fadeObject.FadeIn();
        }
Example #8
0
        public MainMenuPage(
            AssetsLoader assets,
            RateMeDialog rateMeDialog,
            SoundManager soundManager,
            IScreenTransformationMatrixProvider matrixScaleProvider,
            ILocalizedStringsRepository localizedStringsRepository)
        {
            _font = assets.Font;
            _matrixScaleProvider = matrixScaleProvider;
            _rateMeDialog        = rateMeDialog ?? throw new ArgumentNullException(nameof(rateMeDialog));
            _soundManager        = soundManager ?? throw new ArgumentNullException(nameof(soundManager));

            _background      = assets.OtherSprites["menuBackground"];
            _playText        = localizedStringsRepository.Get(GameStringsLoader.PlayButtonString);
            _scoreText       = localizedStringsRepository.Get(GameStringsLoader.ScoreButtonString);
            _fartText        = localizedStringsRepository.Get(GameStringsLoader.FartButtonString);
            _titleImage      = assets.OtherSprites["gameTitle"];
            _achievementText = "about";

            _titleScalingObject = new ScalingObject(1f, 1.2f, 1.0f);
            _titleDrawingInfos  = new DrawingInfos()
            {
                Position = new Vector2(matrixScaleProvider.VirtualWidth / 2f, 100f),
                Origin   = _titleImage.SpriteCenter
            };

            _playScalingObject = new ScalingObject(0.5f, 0.7f, 1f);
            _playDrawingInfos  = new DrawingInfos()
            {
                Position = new Vector2(140f, 250f),
                Origin   = _font.GetTextCenter(_playText)
            };
            _playTextSize = _font.MeasureString(_playText);

            _fartScalingObject = new ScalingObject(0.5f, 0.7f, 1f);
            _fartDrawingInfos  = new DrawingInfos()
            {
                Position     = new Vector2(140f, 320f),
                Origin       = _font.GetTextCenter(_fartText),
                OverlayColor = new Color(155, 88, 48)
            };
            _fartTextSize = _font.MeasureString(_fartText);

            _scoreTextSize      = _font.MeasureString(_scoreText);
            _scoreScalingObject = new ScalingObject(0.5f, 0.7f, 1f);
            _scoreDrawingInfos  = new DrawingInfos()
            {
                Position = new Vector2(matrixScaleProvider.VirtualWidth - 150f, 250f),
                Origin   = _font.GetTextCenter(_scoreText)
            };

            _aboutTextSize      = _font.MeasureString(_achievementText);
            _aboutScalingObject = new ScalingObject(0.5f, 0.7f, 1f);
            _aboutDrawingInfos  = new DrawingInfos()
            {
                Position = new Vector2(matrixScaleProvider.VirtualWidth - 150f, 320f),
                Origin   = _font.GetTextCenter(_achievementText)
            };

            _soundManager.PlayMenuBackground();
        }
Example #9
0
        /// <summary>
        /// Constructs the dialog
        /// </summary>
        /// <param name="launchesUntilPrompt"></param>
        /// <param name="maxRateShowTimes"></param>
        /// <param name="rateAppUri"></param>
        /// <param name="dialogDefinition"></param>
        /// <param name="font"></param>
        /// <param name="localizedStringsRepository"></param>
        /// <param name="rateMeDialogStrings"></param>
        /// <param name="webPageOpener"></param>
        /// <param name="settingsRepository"></param>
        /// <param name="buttonADefinition"></param>
        /// <param name="buttonBDefinition"></param>
        /// <param name="backgroundColor"></param>
        /// <param name="buttonsBackgroundColor"></param>
        /// <param name="buttonsShadowColor"></param>
        /// <param name="backgroundShadowColor"></param>
        /// <param name="titleColor"></param>
        /// <param name="buttonsTextColor"></param>
        /// <param name="titlePositionOffset"></param>
        /// <param name="buttonTextPadding"></param>
        /// <param name="titlePadding"></param>
        public RateMeDialog(
            int launchesUntilPrompt,
            int maxRateShowTimes,
            Uri rateAppUri,
            Rectangle dialogDefinition,
            SpriteFont font,
            ILocalizedStringsRepository localizedStringsRepository,
            RateMeDialogStrings rateMeDialogStrings,
            IWebPageOpener webPageOpener,
            ISettingsRepository settingsRepository,
            Rectangle buttonADefinition,
            Rectangle buttonBDefinition,
            Color backgroundColor,
            Color buttonsBackgroundColor,
            Color buttonsShadowColor,
            Color backgroundShadowColor,
            Color titleColor,
            Color buttonsTextColor,
            Vector2 titlePositionOffset,
            float buttonTextPadding,
            float titlePadding)
        {
            _launchesUntilPrompt        = launchesUntilPrompt;
            _maxRateShowTimes           = maxRateShowTimes;
            _rateAppUri                 = rateAppUri;
            _localizedStringsRepository = localizedStringsRepository;
            _settingsRepository         = settingsRepository;

            AddStrings(rateMeDialogStrings);

            var buttonA = new ButtonWithText(
                font: font,
                text: localizedStringsRepository.Get(_rateItButtonTextKey),
                collisionRectangle: buttonADefinition,
                backgroundColor: buttonsBackgroundColor,
                textColor: buttonsTextColor,
                shadowColor: buttonsShadowColor,
                onClick: () =>
            {
                _settingsRepository.SetBool(_dontShowAgainSettingKey, true);
                ShouldShowDialog = false;
                webPageOpener.OpenWebpage(_rateAppUri);
            },
                textPadding: buttonTextPadding);

            var buttonB = new ButtonWithText(
                font: font,
                text: localizedStringsRepository.Get(_notNowButtonTextKey),
                collisionRectangle: buttonBDefinition,
                backgroundColor: buttonsBackgroundColor,
                textColor: buttonsTextColor,
                shadowColor: buttonsShadowColor,
                onClick: () =>
            {
                // If users says "Not now", I reset the app launch count
                _settingsRepository.SetInt(_appLaunchCountSettingKey, 0);
                ShouldShowDialog = false;
            },
                textPadding: buttonTextPadding);

            var minScale = Math.Min(buttonA.TextScale, buttonB.TextScale);

            buttonA.TextScale = minScale;
            buttonB.TextScale = minScale;

            _titleButtonButtonDialog = new Dialog(
                title: localizedStringsRepository.Get(_messageTextKey),
                font: font,
                dialogWindowDefinition: dialogDefinition,
                titlePositionOffset: titlePositionOffset,
                backgroundColor: backgroundColor,
                backgroundShadowColor: backgroundShadowColor,
                titleColor: titleColor,
                titlePadding: titlePadding,
                buttons: new ButtonWithText[] { buttonA, buttonB });

            EvaluateRateMe();
        }