示例#1
0
        public void Start()
        {
            var upSpeed = App.Random.Next(25000, 60000) / 10000.0;

            this.timer          = new DispatcherTimer(DispatcherPriority.Render, App.Current.Dispatcher);
            this.timer.Interval = TimeSpan.FromTicks(10000000 / 60); // 60 loop per sec
            this.timer.Tick    += (_, __) =>
            {
                this.right += 10;
                this.UI.SetValue(Canvas.RightProperty, this.right);

                this.bottom += upSpeed;
                this.UI.SetValue(Canvas.BottomProperty, this.bottom);
                upSpeed -= 0.1;

                var myPoint = this.GetPoint();
                var myRect  = new Rect(myPoint.X, myPoint.Y, this.UI.ActualWidth, this.UI.ActualHeight);
                var match   = this.field.Walls.Cast <WithHitPoints>()
                              .Concat(new WithHitPoints[] { this.field.Castle })
                              .Where(x => x != null)
                              .FirstOrDefault(x =>
                {
                    var point = x.GetPoint();
                    return(myRect.IntersectsWith(new Rect(point.X, point.Y, x.UI.ActualWidth, x.UI.ActualHeight)));
                });
                if (match != null)
                {
                    this.timer.Stop();
                    match.MakeDamage(this.Power);
                    this.UI = new UnitViews.Explosion();
                    this.UI.SetValue(Canvas.RightProperty, this.right);
                    this.UI.SetValue(Canvas.BottomProperty, this.bottom);
                    if (this.UIChanged != null)
                    {
                        this.UIChanged(this, EventArgs.Empty);
                    }
                    DispatcherAsync.Delay(TimeSpan.FromSeconds(0.5), () =>
                    {
                        if (this.Disappeared != null)
                        {
                            this.Disappeared(this, EventArgs.Empty);
                        }
                    });
                }
                else if (this.right > (this.UI.Parent as FrameworkElement).ActualWidth)
                {
                    this.timer.Stop();
                    if (this.Disappeared != null)
                    {
                        this.Disappeared(this, EventArgs.Empty);
                    }
                }
            };
            this.timer.Start();
        }
示例#2
0
        protected override void HpZero()
        {
            var index = Array.IndexOf(this.field.Walls, this);

            this.field.SetWall(null, index);

            DispatcherAsync.Delay(TimeSpan.FromSeconds(0.5), () =>
            {
                var x = index / 3 * 3;
                var y = index % 3;

                for (var i = y; i < 2; i++)
                {
                    var w = this.field.Walls[x + i + 1];
                    this.field.SetWall(null, x + i + 1);
                    this.field.SetWall(w, x + i);
                }
                this.field.SetWall(null, x + 2);
            });
        }