Exemple #1
0
        /// <summary>
        /// Called when manipulation of the cell is completed.
        /// It's fired when user takes the finger off the screen,
        /// even if the fingers have drifted away from the control.
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="r">Event arguments</param>
        private void UserControl_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            // Start the fade out animation which returns the cell's color back to original.
            fadeOutAnimation.Begin();

            if (!IsPlayerSettable)
            {
                SoundHelper.PlaySound(SoundHelper.SoundType.CellSelectedSound);
            }
            else
            {
                SoundHelper.PlaySound(SoundHelper.SoundType.NumberChosenSound);
            }
        }
Exemple #2
0
        /// <summary>
        /// Called when the player is not touching the button anymore
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="r">Event arguments</param>
        private void Button_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            // Invert the colors of touched text block and its backgroud
            fadeOutAnimation.Begin();
            SoundHelper.PlaySound(SoundHelper.SoundType.NumberChosenSound);

            // Get the value of the text block player pressed and pass it to
            // the game logic. The cell will be cleared if the value is zero.
            int val = 0;

            Int32.TryParse((sender as Button).Content.ToString(), out val);

            if (OnSelectedNumber != null)
            {
                OnSelectedNumber(val);
            }
        }
        /// <summary>
        /// Action triggered when user selected a number
        /// </summary>
        private void OnNumberChoosen(Cell sender, int number)
        {
            var conflictingCells = game.SetNumberByPlayer((int)sender.GetValue(Grid.RowProperty),
                                                          (int)sender.GetValue(Grid.ColumnProperty),
                                                          number);

            foreach (var point in conflictingCells)
            {
                cells[point.X][point.Y].Blink();
            }

            SoundHelper.PlaySound(SoundHelper.SoundType.CellSelectedSound);

            if (gameState != GameState.NotStarted && game.EmptyCells == 0)
            {
                GameEnds();
            }
        }
        /// <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);
        }