Example #1
0
        /// <summary>
        /// Ends current game. Called when all the cells are filled.
        /// </summary>
        private void GameEnds()
        {
            gameTimer.Stop();

            // Blink all cells and prevent the player from modifying the cells
            for (int row = 0; row < GameLogic.RowLength; row++)
            {
                for (int col = 0; col < GameLogic.ColumnLength; col++)
                {
                    game.Model.BoardNumbers[row][col].SetByGame = true;                     // to block the user input
                    cells[row][col].Blink();
                }
            }

            // Display the score with GameOver dialog
            HighscoreItem score = new HighscoreItem();

            score.Time = new TimeSpan(gameTimeElapsed.Days, gameTimeElapsed.Hours,
                                      gameTimeElapsed.Minutes, gameTimeElapsed.Seconds, 0);
            score.Moves = game.PlayerMoves;


            //TODO: move this to XAML
            GameOver gameOver = new GameOver(score);

            // Main page is divided into 2x3 grid. Make sure the row and column
            // properties are set properly (position 0,0 with span 2,3) to make
            // the dialog visible anywhere on the page.
            gameOver.SetValue(Grid.RowSpanProperty, 3);
            gameOver.SetValue(Grid.ColumnSpanProperty, 2);
            gameOver.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Center);
            gameOver.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            gameOver.SetValue(MarginProperty, new Thickness(10, 0, 0, 0));

            LayoutRoot.Children.Add(gameOver);
            gameState = GameState.GameOver;

            SoundHelper.PlaySound(SoundHelper.SoundType.GameEndSound);
        }