public override void OpenSecret(Unit target) { if (target.HealthLevel - 2 <= 0) { target.PlayDieSound(); target.SmallImage.Source = new BitmapImage(); (target.SmallImage.Parent as Border).Background = null; target.CurrentPosition = new Point(-1, -1); target.IsAlive = false; } else { target.HealthLevel -= 2; } }
public void Attack(Unit targetUnit, out bool successAttack) { successAttack = false; //Check if the aggresssor could reach the target if (this.IsCorrectMove(targetUnit.CurrentPosition) && this.IsClearWay(targetUnit.CurrentPosition)) { successAttack = true; targetUnit.HealthLevel -= this.AttackLevel; this.PlayAttackSound(); if (targetUnit.IsCorrectMove(this.CurrentPosition)) { this.HealthLevel -= targetUnit.CounterAttackLevel; } if (this.HealthLevel <= 0 && targetUnit.HealthLevel <= 0) { this.PlayDieSound(); targetUnit.PlayDieSound(); targetUnit.SmallImage.Source = new BitmapImage(); (targetUnit.SmallImage.Parent as Border).Background = null; targetUnit.CurrentPosition = new Point(-1, -1); this.SmallImage.Source = new BitmapImage(); (targetUnit.SmallImage.Parent as Border).Background = null; this.CurrentPosition = new Point(-1, -1); this.IsAlive = false; targetUnit.IsAlive = false; return; } if (targetUnit.HealthLevel <= 0) { targetUnit.PlayDieSound(); targetUnit.IsAlive = false; //Level up the selected unit and at the same time up its attack and health this.Level++; this.MaxAttackLevel++; this.AttackLevel++; this.MaxHealthLevel++; this.HealthLevel++; targetUnit.SmallImage.Source = new BitmapImage(); (targetUnit.SmallImage.Parent as Border).Background = null; this.CurrentPosition = targetUnit.CurrentPosition; targetUnit.CurrentPosition = new Point(-1, -1); Grid.SetRow(this.SmallImage.Parent as Border, (int)this.CurrentPosition.Y); Grid.SetColumn(this.SmallImage.Parent as Border, (int)this.CurrentPosition.X); } if (this.HealthLevel <= 0) { this.PlayDieSound(); this.IsAlive = false; //Level up the selected unit and at the same time up its attack and health targetUnit.Level++; targetUnit.MaxAttackLevel++; targetUnit.AttackLevel++; targetUnit.MaxHealthLevel++; targetUnit.HealthLevel++; this.SmallImage.Source = new BitmapImage(); (this.SmallImage.Parent as Border).Background = null; this.CurrentPosition = new Point(-1, -1); } } }