예제 #1
0
        /// <summary>
        /// Finish the current game
        /// </summary>
        private void FinishCurrentGame()
        {
            isActive = false;

            if (HighScoreScreen.IsInHighscores(currentLevelNumber))
            {
                // Show the device's keyboard to enter a name for the highscore
                Guide.BeginShowKeyboardInput(PlayerIndex.One,
                                             Constants.HighscorePopupTitle, Constants.HighscorePopupText,
                                             Constants.HighscorePopupDefault, ShowHighscorePromptEnded, true);
            }
            else
            {
                moveToHighScore = true;
            }
        }
예제 #2
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            if (checkHighscore && (!Guide.IsVisible))
            {
                checkHighscore = false;

                var gameplayScreen = GetGameplayScreen();

                var levelNumber = gameplayScreen.currentLevel.levelNumber;

                if (HighScoreScreen.IsInHighscores(levelNumber))
                {
                    // Show the device's keyboard to record a high score
                    Guide.BeginShowKeyboardInput(PlayerIndex.One,
                                                 Constants.HighscorePopupTitle, Constants.HighscorePopupText,
                                                 Constants.HighscorePopupDefault, ShowHighscorePromptEnded,
                                                 levelNumber);
                }
                else
                {
                    moveToMainMenu = true;
                }
            }
            else if (moveToHighScore)
            {
                foreach (GameScreen screen in ScreenManager.GetScreens())
                {
                    screen.ExitScreen();
                }

                ScreenManager.AddScreen(new BackgroundScreen(true), null);
                ScreenManager.AddScreen(new HighScoreScreen(), null);
            }
            else if (moveToMainMenu)
            {
                foreach (GameScreen screen in ScreenManager.GetScreens())
                {
                    screen.ExitScreen();
                }

                ScreenManager.AddScreen(new BackgroundScreen(false), null);
                ScreenManager.AddScreen(new MainMenuScreen(), null);
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
예제 #3
0
        /// <summary>
        /// Update all the game component
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="otherScreenHasFocus"></param>
        /// <param name="coveredByOtherScreen"></param>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            // Do not advance to the highscore screen if sounds are playing
            if (moveToHighScore && !AudioManager.AreSoundsPlaying())
            {
                ScreenManager.Game.Components.Remove(currentLevel);

                foreach (GameScreen screen in ScreenManager.GetScreens())
                {
                    screen.ExitScreen();
                }

                ScreenManager.AddScreen(new BackgroundScreen(true), null);
                ScreenManager.AddScreen(new HighScoreScreen(), null);
            }

            // Do not perform advance update logic if the game is inactive or we are
            // moving to the highscore screen
            if (!IsActive || moveToHighScore)
            {
                base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
                return;
            }

            if ((inputState == TouchInputState.GracePeriod) && (isActive))
            {
                inputTimeMeasure += gameTime.ElapsedGameTime;

                // if the input grace period is over, handle the touch input
                if (inputTimeMeasure >= inputGracePeriod)
                {
                    currentLevel.RegisterTouch(lastPressInput);
                    inputState = TouchInputState.Idle;
                }
            }

            // If the user passed the level, advance to the next or finish the game if
            // the current level was last
            if (currentLevel.CurrentState == LevelState.FinishedOk && isActive)
            {
                AudioManager.PlaySound("success");

                if (currentLevelNumber < maxLevelNumber)
                {
                    currentLevelNumber++;
                    isLevelChange = true;
                }
                else
                {
                    FinishCurrentGame();
                }
            }
            // If the user failed to pass the level, revert to level one, allowing the
            // user to register a highscore if he reached a high enough level
            else if (currentLevel.CurrentState == LevelState.FinishedFail)
            {
                isActive = false;

                if (HighScoreScreen.IsInHighscores(currentLevelNumber))
                {
                    // The player has a highscore - show the device's keyboard
                    Guide.BeginShowKeyboardInput(PlayerIndex.One,
                                                 Constants.HighscorePopupTitle, Constants.HighscorePopupText,
                                                 Constants.HighscorePopupDefault, ShowHighscorePromptEnded,
                                                 false);
                }
                else
                {
                    AudioManager.PlaySound("fail");
                    isActive           = true;
                    currentLevelNumber = 1;
                    isLevelChange      = true;
                }
            }

            if (isLevelChange)
            {
                ScreenManager.Game.Components.Remove(currentLevel);

                currentLevel = new Level(ScreenManager.Game,
                                         ScreenManager.SpriteBatch,
                                         currentLevelNumber, buttonsTexture);
                currentLevel.IsActive = true;

                ScreenManager.Game.Components.Add(currentLevel);

                isLevelChange = false;
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }