public override bool Defend(Knight enemy)
        {
            if (_lastingTimeTurnsLeft > 0) // while spell is not expired
            {
                enemy.LifeBar -= enemy.Damage / 2;
                var result = base.Defend(enemy);
                _lastingTimeTurnsLeft--;

                Console.WriteLine("\t>>> DamageReturnSpell has been casted on {0} ({1} turns left)", this, _lastingTimeTurnsLeft);
                Console.WriteLine("\t\t{0} gets 50% damage back, lifebar={1} now.", enemy, enemy.LifeBar);
                return result;
            }
            return base.Defend(enemy);
        }
 public Battle(Knight kn1, Knight kn2)
 {
     Kn1 = kn1;
     Kn2 = kn2;
 }
 /// <summary>
 /// Deffend ourselves
 /// </summary>
 /// <param name="enemy">other knight, the enemy</param>
 /// <returns>true only when knight is still aliv</returns>
 public virtual bool Defend(Knight enemy)
 {
     Console.WriteLine("{0} defends!", this);
     LifeBar -= enemy.Damage; // get a damage
     LifeBar = LifeBar < 0 ? 0 : LifeBar; // minimum lifebar value is zero.
     return LifeBar > 0; // return if knight is still alive
 }
 /// <summary>
 /// Attack other knight
 /// </summary>
 /// <param name="enemy">other knight, the enemy</param>
 /// <returns>true only when enemy is defeated</returns>
 public virtual bool Attack(Knight enemy)
 {
     Console.WriteLine("{0} attacks!", this);
     var isDefeated = !enemy.Defend(this);
     return isDefeated;
 }
        public override bool Defend(Knight enemy)
        {
            if (_lastingTimeTurnsLeft > 0) // while spell is not expired
            {
                bool result = true; // by default knight is still alive

                var takeChanceToDodge = _r.Next(10); // range is 0..9
                if (takeChanceToDodge < 7) // 70% chance to dodge
                {
                    //var nonDodgedDamage = enemy.Damage;
                    //enemy.Damage = 0; // set enemy.Damage to zero just to have a consistent call to Defend method
                    //result = base.Defend(enemy);
                    //enemy.Damage = nonDodgedDamage; // restore normal damage for an enemy
                    Console.WriteLine("{0} dodges!", this);
                }
                else
                {
                    result = base.Defend(enemy);
                }

                _lastingTimeTurnsLeft--;

                Console.WriteLine("\t>>> DexteritySpell has been casted on {0} ({1} turns left)", this, _lastingTimeTurnsLeft);
                return result;
            }
            return base.Defend(enemy);
        }
 public DexteritySpell(Knight toCastSpellOn)
     : base(toCastSpellOn)
 {
     _lastingTimeTurnsLeft = 3;
     _r = new Random(DateTime.Now.Millisecond);
 }
 public DamageReturnSpell(Knight toCastSpellOn, int lastingTimeTurnsLeft)
     : base(toCastSpellOn)
 {
     _lastingTimeTurnsLeft = lastingTimeTurnsLeft;
 }
        public override bool Attack(Knight enemy)
        {
            if (_lastingTimeTurnsLeft > 0) // while spell is not expired
            {
                var fullStengthDamage = _spelledKnight.Damage;
                _spelledKnight.Damage = _spelledKnight.Damage/2; // being weak
                var result = base.Attack(enemy); // attack being weak  with halved damage
                _lastingTimeTurnsLeft--;

                Console.WriteLine("\t>>> WeaknessSpell has been casted on {0} ({1} turns left)", this, _lastingTimeTurnsLeft);
                Console.WriteLine("\t\t{0}.Damage={1} now.", this, Damage);

                _spelledKnight.Damage = fullStengthDamage; // restore normal damage for the knight
                return result;
            }
            return base.Attack(enemy);
        }
 public DamageReturnSpell(Knight toCastSpellOn)
     : this(toCastSpellOn, 1)
 {
 }
 public WeaknessSpell(Knight toCastSpellOn)
     : base(toCastSpellOn)
 {
     _lastingTimeTurnsLeft = 1;
 }
 public override bool Defend(Knight enemy)
 {
     return _spelledKnight.Defend(enemy);
 }
 public override bool Attack(Knight enemy)
 {
     return _spelledKnight.Attack(enemy);
 }
 protected SpellDecorator(Knight toCastSpellOn)
 {
     _spelledKnight = toCastSpellOn;
 }
 public DoubleDamageSpell(Knight toCastSpellOn)
     : base(toCastSpellOn)
 {
     _lastingTimeTurnsLeft = 1;
 }