Exemple #1
0
        /// <summary>
        /// Asynchronous handler for the highscore player name popup messagebox.
        /// </summary>
        /// <param name="result">The popup messagebox result. The result's
        /// AsyncState property should be true if the user successfully finished
        /// the game, or false otherwise.</param>
        private void ShowHighscorePromptEnded(IAsyncResult result)
        {
            string playerName = Guide.EndShowKeyboardInput(result);

            bool finishedGame = (bool)result.AsyncState;

            if (playerName != null)
            {
                if (playerName.Length > 15)
                {
                    playerName = playerName.Substring(0, 15);
                }

                HighScoreScreen.PutHighScore(playerName, currentLevelNumber);
            }

            if (finishedGame)
            {
                moveToHighScore = true;
            }
            else
            {
                AudioManager.PlaySound("fail");
                isActive           = true;
                currentLevelNumber = 1;
                isLevelChange      = true;
            }
        }
Exemple #2
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;
            }
        }
        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);
        }
        /// <summary>
        /// Asynchronous handler for the highscore player name popup messagebox.
        /// </summary>
        /// <param name="result">The popup messagebox result. The result's
        /// AsyncState should contain the level number which acts as the
        /// highscore.</param>
        private void ShowHighscorePromptEnded(IAsyncResult result)
        {
            string playerName = Guide.EndShowKeyboardInput(result);

            int levelNumber = (int)result.AsyncState;

            if (playerName != null)
            {
                if (playerName.Length > 15)
                {
                    playerName = playerName.Substring(0, 15);
                }

                HighScoreScreen.PutHighScore(playerName, levelNumber);
            }

            moveToHighScore = true;
        }
Exemple #5
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);
        }
Exemple #6
0
        /// <summary>
        /// Respond to "Exit" Item Selection
        /// </summary>
        /// <param name="playerIndex"></param>
        protected override void OnCancel(PlayerIndex playerIndex)
        {
            HighScoreScreen.SaveHighscore();

            ScreenManager.Game.Exit();
        }
Exemple #7
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     AudioManager.LoadSounds();
     HighScoreScreen.LoadHighscores();
     base.LoadContent();
 }