Esempio n. 1
0
        /// <summary>
        /// If the level is over, draws text describing the level's outcome.
        /// </summary>
        private void DrawLevelEndIfNecessary()
        {
            if (isLevelEnd)
            {
                string stringToDisplay = string.Empty;

                if (isUserWon)
                {
                    if (FinalScore != 0 && HighScoreScreen.IsInHighscores(FinalScore))
                    {
                        stringToDisplay = "It's a new\nHigh-Score!";
                    }
                    else
                    {
                        stringToDisplay = "You Win!";
                    }
                }
                else
                {
                    stringToDisplay = "Time Is Up!";
                }

                Vector2 stringVector = font36px.MeasureString(stringToDisplay) * ScreenManager.SpriteBatch.ScaleVector;

                ScreenManager.SpriteBatch.DrawString(font36px, stringToDisplay,
                                                     new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2 - stringVector.X / 2,
                                                                 ScreenManager.GraphicsDevice.Viewport.Height / 2 - stringVector.Y / 2),
                                                     Color.White);
            }
        }
        /// <summary>
        /// Screen update logic
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="otherScreenHasFocus"></param>
        /// <param name="coveredByOtherScreen"></param>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            // If necessary, load the highscore. Remember that calling LoadHighscores multiple times does not have
            // and adverse effect. Highscore will only be loaded once.
            if (!HighScoreScreen.HighscoreLoaded)
            {
                HighScoreScreen.LoadHighscores();
            }
            // If additional thread is running, do nothing
            else if (null != thread)
            {
                // If additional thread finished loading and the screen is not exiting
                if (thread.ThreadState == ThreadState.Stopped && !IsExiting)
                {
                    // Move on to the game play screen once highscore data is loaded
                    foreach (GameScreen screen in ScreenManager.GetScreens())
                    {
                        screen.ExitScreen();
                    }

                    ScreenManager.AddScreen(gameplayScreen, null);
                }
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
        /// <summary>
        /// Starts new level or exit to High Score
        /// </summary>
        /// <param name="input"></param>
        private void StartNewLevelOrExit(InputState input)
        {
            // If there is no next level - go to high score screen
            if (!difficultyMode.HasValue)
            {
                // If is in high score, gets is name
                if (GameplayScreen.FinalScore != 0 && HighScoreScreen.IsInHighscores(GameplayScreen.FinalScore))
                {
                    Guide.BeginShowKeyboardInput(PlayerIndex.One,
                                                 "Player Name", "What is your name (max 15 characters)?", "Player",
                                                 AfterPlayerEnterName, null);
                }
                else
                {
                    foreach (GameScreen screen in ScreenManager.GetScreens())
                    {
                        screen.ExitScreen();
                    }

                    ScreenManager.AddScreen(new BackgroundScreen("highScoreScreen"), null);
                    ScreenManager.AddScreen(new HighScoreScreen(), null);
                }
            }
            // If not already loading
            else if (!isLoading)
            {
                // Start loading the resources in an additional thread
                thread = new Thread(new ThreadStart(gameplayScreen.LoadAssets));

                isLoading = true;
                thread.Start();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// A handler invoked after the user has enter his name.
        /// </summary>
        /// <param name="result"></param>
        private void AfterPlayerEnterName(IAsyncResult result)
        {
            // Gets the name entered
            string playerName = Guide.EndShowKeyboardInput(result);

            if (!string.IsNullOrEmpty(playerName))
            {
                // Ensure that it is valid
                if (playerName != null && playerName.Length > 15)
                {
                    playerName = playerName.Substring(0, 15);
                }

                // Puts it in high score
                HighScoreScreen.PutHighScore(playerName, GameplayScreen.FinalScore);
                HighScoreScreen.HighScoreChanged();
            }

            // Moves to the next screen
            foreach (GameScreen screen in ScreenManager.GetScreens())
            {
                screen.ExitScreen();
            }

            ScreenManager.AddScreen(new BackgroundScreen("highScoreScreen"), null);
            ScreenManager.AddScreen(new HighScoreScreen(), null);
        }
Esempio n. 5
0
        /// <summary>
        /// Respond to "Exit" Item Selection
        /// </summary>
        /// <param name="playerIndex"></param>
        protected override void OnCancel(PlayerIndex playerIndex)
        {
            HighScoreScreen.SaveHighscore();

            ScreenManager.Game.Exit();

            AudioManager.StopSound("MenuMusic_Loop");
        }
Esempio n. 6
0
        /// <summary>
        /// Performs necessary update logic.
        /// </summary>
        /// <param name="gameTime">Game time information.</param>
        /// <param name="otherScreenHasFocus">Whether another screen has the focus.</param>
        /// <param name="coveredByOtherScreen">Whether this screen is covered by another.</param>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            if (isExiting)
            {
                if (!HighScoreScreen.HighscoreSaved)
                {
                    HighScoreScreen.SaveHighscore();
                }
                else
                {
                    isExiting = false;
                    ScreenManager.Game.Exit();
                }
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
Esempio n. 7
0
        /// <summary>
        /// Starts new level or exit to High Score
        /// </summary>
        /// <param name="input"></param>
        private void StartNewLevelOrExit(InputState input)
        {
            // If there is no next level - go to high score screen
            if (!difficultyMode.HasValue)
            {
                // If is in high score, gets is name
                if (GameplayScreen.FinalScore != 0 && HighScoreScreen.IsInHighscores(GameplayScreen.FinalScore))
                {
                    Guide.BeginShowKeyboardInput(PlayerIndex.One,
                                                 "Player Name", "What is your name (max 15 characters)?", "Player",
                                                 AfterPlayerEnterName, null);
                }
                else
                {
                    foreach (GameScreen screen in ScreenManager.GetScreens())
                    {
                        screen.ExitScreen();
                    }

                    ScreenManager.AddScreen(new BackgroundScreen("highScoreScreen"), null);
                    ScreenManager.AddScreen(new HighScoreScreen(), null);
                }
            }
            // If not already loading
            else if (!isLoading)
            {
#if MONOMAC
                // Start loading the resources on main thread
                // If not then all sorts of errors happen for
                // AutoReleasPools and OpenGL does not handle
                // multiple thread to well when using Thread
                MonoMac.AppKit.NSApplication.SharedApplication.BeginInvokeOnMainThread(delegate {
                    gameplayScreen.LoadAssets();
                    isLoading    = false;
                    assetsLoaded = true;
                });
#else
                // Start loading the resources in an additional thread
                thread = new Thread(new ThreadStart(gameplayScreen.LoadAssets));

                isLoading = true;
                thread.Start();
#endif
            }
        }
Esempio n. 8
0
        /// <summary>
        /// A handler invoked after the user has entered his name.
        /// </summary>
        /// <param name="result"></param>
        private void AfterPlayerEnterName(IAsyncResult result)
        {
            // Get the name entered by the user
            string playerName = Guide.EndShowKeyboardInput(result);

            if (!string.IsNullOrEmpty(playerName))
            {
                // Ensure that it is valid
                if (playerName != null && playerName.Length > 15)
                {
                    playerName = playerName.Substring(0, 15);
                }

                // Puts it in high score
                HighScoreScreen.PutHighScore(playerName, Score);
            }

            // Moves to the next screen
            MoveToNextScreen((bool)result.AsyncState);
        }
Esempio n. 9
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            HighScoreScreen.LoadHighscores();

            base.LoadContent();
        }
Esempio n. 10
0
 /// <summary>
 /// Checks if the user's score is a high score.
 /// </summary>
 /// <returns>True if the user has a high score, false otherwise.</returns>
 private bool CheckIsInHighScore()
 {
     // User can be at high score only if he is at Hard level.
     return(gameDifficultyLevel == DifficultyMode.Hard && HighScoreScreen.IsInHighscores(Score));
 }