public override void Start(Game Game, IValuta Price) { Button.Click += delegate(object sender, RoutedEventArgs e) { if (IsPressed == false) { if (CheckList != null && CheckList.Count > 0) { foreach (var x in CheckList) { if (x.Check() == false) { return; } } } cts = new CancellationTokenSource(); Token = cts.Token; Button.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart) delegate { Button.Background = (Brush)App.Current.TryFindResource("TButtonGradientBrush"); }); // = ); IsPressed = !IsPressed; AsyncStart(Game, Token, Price); } else { cts.Cancel(); Button.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart) delegate { Button.Background = (Brush)App.Current.TryFindResource("FButtonGradientBrush"); }); // = ); IsPressed = !IsPressed; } }; }
protected async void AsyncStart(Game Game, CancellationToken token, IValuta Price) { if (token.IsCancellationRequested) { return; } await Task.Run(() => FuncStart(Game, token, Price)); }
public virtual void Start(Game Game, IValuta Price) { Button.Click += delegate(object sender, RoutedEventArgs e) { if (IsPressed == false) { if (CheckList != null && CheckList.Count > 0) { foreach (var x in CheckList) { if (x.Check() == false) { return; } } } foreach (var x in Abilities) { x.DoEffect(); } cts = new CancellationTokenSource(); Token = cts.Token; Button.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart) delegate { Button.Background = (Brush)App.Current.TryFindResource("TButtonGradientBrush"); }); // = ); IsPressed = !IsPressed; AsyncStart(Game, Token, Price); } else { cts.Cancel(); Button.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart) delegate { Button.Background = (Brush)App.Current.TryFindResource("FButtonGradientBrush"); }); // = ); foreach (var x in Abilities) { if (x is PositiveAbility) { NegativeAbility xx = new NegativeAbility(((Ability)x).MainStat, ((Ability)x).TempStat); xx.DoEffect(); } else if (x is NegativeAbility) { PositiveAbility xx = new PositiveAbility(((Ability)x).MainStat, ((Ability)x).TempStat); xx.DoEffect(); } } Button.Background = (Brush)App.Current.TryFindResource("FButtonGradientBrush"); IsPressed = !IsPressed; } }; }
protected virtual void FuncStart(Game Game, CancellationToken token, IValuta Price) { TimeStat daystmp = new TimeStat(Game.User.Times); daystmp.AddDate(Time); TimeStat daybuf = new TimeStat(Game.User.Times); daybuf.AddDays(1); while (true) { if (token.IsCancellationRequested) { cts.Dispose(); return; } if (Game.User.Times == daybuf) { foreach (var x in Abilities) { x.DoEffect(); } daybuf = daybuf = new TimeStat(Game.User.Times); daybuf.AddDays(1); } if (Game.User.Times == daystmp) { if (CheckList != null && CheckList.Count > 0) { foreach (var x in CheckList) { if (x.Check() == false) { cts.Cancel(); cts.Dispose(); IsPressed = !IsPressed; return; } } } NegativeAbility a = new NegativeAbility(Game.User.Valutes, Price); a.DoEffect(); daystmp = new TimeStat(Game.User.Times); daystmp.AddDate(Time); } } }
public BottlePrice(IValuta price) { Price = price; }