Advertisement
Guest User

Untitled

a guest
Dec 29th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using ArenaDraftAssistant.Model;
  18.  
  19. namespace ArenaDraftAssistant
  20. {
  21.     /// <summary>
  22.     /// Interaction logic for ManaCostSelectorControl.xaml
  23.     /// </summary>
  24.     public partial class ManaCostSelectorControl : UserControl, INotifyPropertyChanged
  25.     {
  26.         public ManaCostSelectorControl()
  27.         {
  28.             Loaded += delegate
  29.             {
  30.                 CalculateDropProbabilities();
  31.                 OnPropertyChanged(nameof(AvailableMulliganAmounts));
  32.             };
  33.  
  34.             PropertyChanged += (sender, e) =>
  35.             {
  36.                 if (e.PropertyName == nameof(MulliganAmount))
  37.                 {
  38.                     if (DropProbabilitiesForAmount != null)
  39.                     {
  40.                         CalculateDropProbabilities();
  41.                     }
  42.                 }
  43.             };
  44.  
  45.             InitializeComponent();
  46.         }
  47.  
  48.         public static readonly DependencyProperty ManaCostProperty = DependencyProperty.Register(nameof(ManaCost),
  49.             typeof(int), typeof(ManaCostSelectorControl));
  50.  
  51.         public int ManaCost
  52.         {
  53.             get { return (int) GetValue(ManaCostProperty); }
  54.             set { SetValue(ManaCostProperty, value); }
  55.         }
  56.  
  57.         public static readonly DependencyProperty DropProbabilitiesForAmountProperty =
  58.             DependencyProperty.Register(nameof(DropProbabilitiesForAmount),
  59.                 typeof(ObservableCollection<KeyValuePair<int, double>>), typeof(ManaCostSelectorControl));
  60.  
  61.         public ObservableCollection<KeyValuePair<int, double>> DropProbabilitiesForAmount
  62.         {
  63.             get { return (ObservableCollection<KeyValuePair<int, double>>) GetValue(DropProbabilitiesForAmountProperty); }
  64.             set { SetValue(DropProbabilitiesForAmountProperty, value); }
  65.         }
  66.  
  67.         public static readonly DependencyProperty CardsInOpeningHandProperty =
  68.             DependencyProperty.Register(nameof(CardsInOpeningHand), typeof(int), typeof(ManaCostSelectorControl));
  69.  
  70.         public int CardsInOpeningHand
  71.         {
  72.             get { return (int) GetValue(CardsInOpeningHandProperty); }
  73.             set { SetValue(CardsInOpeningHandProperty, value); }
  74.         }
  75.  
  76.         public static readonly DependencyProperty MaxMulliganProperty = DependencyProperty.Register(nameof(MaxMulligan), typeof(int), typeof(ManaCostSelectorControl));
  77.  
  78.         public int MaxMulligan
  79.         {
  80.             get { return (int) GetValue(MaxMulliganProperty); }
  81.             set { SetValue(MaxMulliganProperty, value); }
  82.         }
  83.  
  84.         public static readonly DependencyProperty DefaultMulliganProperty =
  85.             DependencyProperty.Register(nameof(DefaultMulligan), typeof(int), typeof(ManaCostSelectorControl));
  86.  
  87.         public int DefaultMulligan
  88.         {
  89.             get { return (int) GetValue(DefaultMulliganProperty); }
  90.             set { SetValue(DefaultMulliganProperty, value); }
  91.         }
  92.  
  93.         private int _mulliganAmount;
  94.  
  95.         public int MulliganAmount
  96.         {
  97.             get { return _mulliganAmount; }
  98.             set
  99.             {
  100.                 _mulliganAmount = value;
  101.                 OnPropertyChanged(nameof(MulliganAmount));
  102.             }
  103.         }
  104.  
  105.         public ObservableCollection<int> AvailableMulliganAmounts => new ObservableCollection<int>(Enumerable.Range(0, MaxMulligan + 1));
  106.  
  107.         public event PropertyChangedEventHandler PropertyChanged;
  108.  
  109.         protected virtual void OnPropertyChanged(string propertyName)
  110.         {
  111.             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  112.         }
  113.  
  114.         private void CalculateDropProbabilities()
  115.         {
  116.             for (var i = 0; i <= 10; i++)
  117.             {
  118.                 DropProbabilitiesForAmount[i] = new KeyValuePair<int, double>(i, ArenaDraft.ProbabilityOfXDropByTurnX(ManaCost, 3, MulliganAmount, i));
  119.             }
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement