예제 #1
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            // Stop the timer
            timer.Stop();

            if (!gameIsInProgress && gameBoard.IsLost)
            {
                gameBoard = null;
            }

            // Set the sharing mode of the graphics device to turn off XNA rendering
            SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(false);

            base.OnNavigatedFrom(e);
        }
예제 #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Set the sharing mode of the graphics device to turn on XNA rendering
            SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true);

            //If there is a gesture, kill it so it doesn't break the functionality for the rest of the code
            if (TouchPanel.IsGestureAvailable)
            {
                TouchPanel.ReadGesture();
            }

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(SharedGraphicsDeviceManager.Current.GraphicsDevice);

            if (!gameIsInProgress)
            {
                gameIsInProgress = true;
                gameState = GameState.Game;

                previousHighScore = HighScoreManager.GetHighScore();
                HighScoreNumber.Text = previousHighScore.ToString();

                popSoundEffect = contentManager.Load<SoundEffect>("Sounds/popSound");

                gameBoard = new GameBoard();

                //Load the content for the textures of the 6 different types of balls
                Texture2D blue = contentManager.Load<Texture2D>("BallSprites/blue");
                Texture2D green = contentManager.Load<Texture2D>("BallSprites/green");
                Texture2D purple = contentManager.Load<Texture2D>("BallSprites/purple");
                Texture2D red = contentManager.Load<Texture2D>("BallSprites/red");
                Texture2D teal = contentManager.Load<Texture2D>("BallSprites/teal");
                Texture2D yellow = contentManager.Load<Texture2D>("BallSprites/yellow");

                gameBoard.AddBallTexture("blue", blue);
                gameBoard.AddBallTexture("green", green);
                gameBoard.AddBallTexture("purple", purple);
                gameBoard.AddBallTexture("red", red);
                gameBoard.AddBallTexture("teal", teal);
                gameBoard.AddBallTexture("yellow", yellow);

                gameBoard.Initialize();
            }

            // Start the timer
            timer.Start();
            base.OnNavigatedTo(e);
        }