Пример #1
0
        private void SortTextBlock_MouseUp(object sender, MouseButtonEventArgs e)
        {
            TextBlock textBlock = sender as TextBlock;
            SortingAlgorithm <int> sortingAlgorithm = SortingAlgorithm <int> .FromName(textBlock.Text);

            BeginSort(sortingAlgorithm);
        }
Пример #2
0
 private void BeginSort(SortingAlgorithm <int> algorithm)
 {
     if (_Active)
     {
         _ActiveAlgorithm.Cancel();
     }
     _Active                    = true;
     _ActiveAlgorithm           = algorithm;
     _StopButton.Visibility     = System.Windows.Visibility.Visible;
     _PlayButton.Visibility     = System.Windows.Visibility.Collapsed;
     _ScrambleButton.IsEnabled  = false;
     _BarCountBox.IsEnabled     = false;
     _ActiveAlgorithm.Complete += (s2, e2) =>
     {
         EndSort();
         _Sorted = true;
     };
     RandomizeBars();
     _AlgorithmName = algorithm.Name;
     _AlgorithmNameTextBlock.Text = _AlgorithmName;
     _SwapCount = 0;
     _SwapCountTextBlock.Text    = "0";
     _CompareCount               = 0;
     _CompareCountTextBlock.Text = "0";
     //_WaveOut.Play();
     _ActiveAlgorithm.ActiveRangeChange += (s, e) =>
     {
         UpdateActiveRange(e.Items);
     };
     _ActiveAlgorithm.ItemsSwapped += (s, e) =>
     {
         _SwapCount++;
         this.Dispatcher.BeginInvoke(new Action(() => { _SwapCountTextBlock.Text = _SwapCount.ToString(); }));
         UpdateRectangleHeight(e.Item1Index, e.Item1);
         UpdateRectangleHeight(e.Item2Index, e.Item2);
         if (_PlayOnSwap)
         {
             PlaySound(e.Item1 - 1);
             PlaySound(e.Item2 - 1);
         }
     };
     _ActiveAlgorithm.ItemsCompared += (s, e) =>
     {
         _CompareCount++;
         this.Dispatcher.BeginInvoke(new Action(() => { _CompareCountTextBlock.Text = _CompareCount.ToString(); }));
         UpdateIndicator(0, e.Item1Index);
         UpdateIndicator(1, e.Item2Index);
         if (_PlayOnCompare)
         {
             PlaySound(e.Item1 - 1);
             PlaySound(e.Item2 - 1);
         }
     };
     _ActiveAlgorithm.ItemUpdated += (s, e) =>
     {
         UpdateRectangleHeight(e.ItemIndex, e.Item);
     };
     foreach (Polygon indicator in _Indicators)
     {
         indicator.Visibility = System.Windows.Visibility.Visible;
     }
     _ActiveAlgorithm.Sort(_Bars);
 }