Esempio n. 1
0
 /// <summary>
 /// Tells the screen to go away. Unlike ScreenManager.RemoveScreen, which
 /// instantly kills the screen, this method respects the transition timings
 /// and will give the screen a chance to gradually transition off.
 /// </summary>
 public void ExitScreen()
 {
     if (TransitionOffTime == TimeSpan.Zero)
     {
         // If the screen has a zero transition time, remove it immediately.
         ScreenManager.RemoveScreen(this);
     }
     else
     {
         // Otherwise flag that it should transition off and then exit.
         isExiting = true;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Checks whether the current game is over, and if so performs the necessary actions.
        /// </summary>
        /// <returns>True if the current game is over and false otherwise.</returns>
        private bool CheckIfCurrentGameFinished()
        {
            levelEnded = false;
            isUserWon  = vat.CurrentVatCapacity >= vat.MaxVatCapacity;

            // If the vat is full, the player wins
            if (isUserWon || gameElapsed <= TimeSpan.Zero)
            {
                levelEnded = true;

                if (gameDifficultyLevel == DifficultyMode.Hard)
                {
                    FinalScore = ConfigurationManager.ModesConfiguration[gameDifficultyLevel].HighScoreFactor
                                 * (int)gameElapsed.TotalMilliseconds;
                }
                else
                {
                    FinalScore = 0;
                }
            }

            // if true, game is over
            if (gameElapsed <= TimeSpan.Zero || levelEnded)
            {
                isLevelEnd = true;

                if (userInputToExit)
                {
                    ScreenManager.RemoveScreen(this);

                    if (isUserWon) // True - the user won
                    {
                        AudioManager.PlaySound("Victory");
                    }
                    else
                    {
                        AudioManager.PlaySound("Defeat");
                    }

                    MoveToNextScreen(isUserWon);
                }
            }

            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Allows the screen to run logic, such as updating the transition position.
        /// Unlike HandleInput, this method is called regardless of whether the screen
        /// is active, hidden, or in the middle of a transition.
        /// </summary>
        public virtual void Update(GameTime gameTime, bool otherScreenHasFocus,
                                   bool coveredByOtherScreen)
        {
            this.otherScreenHasFocus = otherScreenHasFocus;

            if (isExiting)
            {
                // If the screen is going away to die, it should transition off.
                screenState = ScreenState.TransitionOff;

                if (!UpdateTransition(gameTime, transitionOffTime, 1))
                {
                    // When the transition finishes, remove the screen.
                    ScreenManager.RemoveScreen(this);
                }
            }
            else if (coveredByOtherScreen)
            {
                // If the screen is covered by another, it should transition off.
                if (UpdateTransition(gameTime, transitionOffTime, 1))
                {
                    // Still busy transitioning.
                    screenState = ScreenState.TransitionOff;
                }
                else
                {
                    // Transition finished!
                    screenState = ScreenState.Hidden;
                }
            }
            else
            {
                // Otherwise the screen should transition on and become active.
                if (UpdateTransition(gameTime, transitionOnTime, -1))
                {
                    // Still busy transitioning.
                    screenState = ScreenState.TransitionOn;
                }
                else
                {
                    // Transition finished!
                    screenState = ScreenState.Active;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Checks whether the current game is over, and if so performs the necessary actions.
        /// </summary>
        /// <returns>True if the current game is over and false otherwise.</returns>
        private bool CheckIfCurrentGameFinished()
        {
            levelEnded = false;
            isUserWon  = vat.CurrentVatCapacity >= vat.MaxVatCapacity;

            // If the vat is full, the player wins
            if (isUserWon || gameElapsed <= TimeSpan.Zero)
            {
                levelEnded = true;
            }

            // if true, game is over
            if (gameElapsed <= TimeSpan.Zero || levelEnded)
            {
                isLevelEnd = true;
                if (userTapToExit)
                {
                    ScreenManager.RemoveScreen(this);

                    if (isUserWon) // True - the user won
                    {
                        // If is in high score, gets is name
                        if (CheckIsInHighScore())
                        {
                            Guide.BeginShowKeyboardInput(PlayerIndex.One,
                                                         "Player Name", "What is your name (max 15 characters)?", "Player",
                                                         AfterPlayerEnterName, levelEnded);
                        }

                        AudioManager.PlaySound("Victory");
                    }
                    else
                    {
                        AudioManager.PlaySound("Defeat");
                    }

                    MoveToNextScreen(isUserWon);
                }
            }

            return(false);
        }