public override bool Attack(Tower Enemy) { int movePerStepX = this.RANGE / 10 ; if (Math.Abs(Enemy.POSITION - this.POSITION) <= this.RANGE) { bool isShooted = false; //如果已開槍,則在未打到目標前 isShooted == true if (bullet == null && counter == this.APS-15) { grid.Children.Add(BulletShow()); //把子彈放進Grid } if (counter >= this.APS-15) isShooted = true; if ((++counter % this.APS) == 0) //控制攻速 { counter = 0; Enemy.GetHurt(this.ATK); grid.Children.Remove(bullet); bullet = null; } else { if (bullet != null && isShooted) { if (isEnemy) { bullet.Margin = new System.Windows.Thickness(0, 0, bullet.Margin.Right - movePerStepX, bullet.Margin.Bottom ); } else { bullet.Margin = new System.Windows.Thickness(0, 0, bullet.Margin.Right + movePerStepX, bullet.Margin.Bottom ); } } } if (!isAttack) //判斷是否需要換gif圖 { if (imgSourceAttack == null) imgSourceAttack = imgSourceMove.Replace("Move", "Attack"); //MessageBox.Show(imgSourceAttack); var _image = new BitmapImage(); _image.BeginInit(); _image.UriSource = new Uri(imgSourceAttack, UriKind.Absolute); _image.EndInit(); ImageBehavior.SetAnimatedSource(Image, _image); Image.Width = Image.ActualWidth + 15; spImg.Width = Image.Width; isAttack = true; } return true; } else { // if (bullet != null) grid.Children.Remove(bullet); bullet = null; return false; } }
public virtual bool Attack(Tower Enemy) { if (Math.Abs(Enemy.POSITION - this.POSITION) <= this.RANGE) { if ((++counter % APS) == 0) { Enemy.GetHurt(ATK); counter = 0; } if (!isAttack) //判斷是否需要換gif圖 { if (imgSourceAttack == null) imgSourceAttack = imgSourceMove.Replace("Move", "Attack"); //MessageBox.Show(imgSourceAttack); if (_imageAttack == null) { _imageAttack = new BitmapImage(); _imageAttack.BeginInit(); _imageAttack.UriSource = new Uri(imgSourceAttack, UriKind.Absolute); _imageAttack.EndInit(); } // Image.Source = _imageAttack; ImageBehavior.SetAnimatedSource(Image, _imageAttack); Image.Width = Image.ActualWidth + 15; spImg.Width = Image.Width; isAttack = true; } return true; } return false; }