public ISpell GenerateAttack() { if (spellIndex == 0) { FireBreath mageSpell = new FireBreath {Damage = this.Unit.AttackPoints}; if (this.Unit.EnergyPoints < mageSpell.EnergyCost) { throw new NotEnoughEnergyException( $"{this.Unit.Name} does not have enough energy to cast {mageSpell.GetType().Name}"); } this.Unit.EnergyPoints -= mageSpell.EnergyCost; spellIndex = 1; return mageSpell; } else { Blizzard mageSpell = new Blizzard {Damage = this.Unit.AttackPoints*2}; if (this.Unit.EnergyPoints < mageSpell.EnergyCost) { throw new NotEnoughEnergyException( $"{this.Unit.Name} does not have enough energy to cast {mageSpell.GetType().Name}"); } this.Unit.EnergyPoints -= mageSpell.EnergyCost; spellIndex = 0; return mageSpell; } }
public override ISpell GenerateAttack() { Spell spell; if (!fireBreathUsed) { spell = new FireBreath(this.Unit); if (this.Unit.EnergyPoints - spell.EnergyCost < 0) { throw new NotEnoughEnergyException(string.Format(GlobalMessages.NotEnoughEnergy, this.Unit.Name, spell.GetType().Name)); } fireBreathUsed = true; } else { spell = new Blizzard(this.Unit); if (this.Unit.EnergyPoints - spell.EnergyCost < 0) { throw new NotEnoughEnergyException(string.Format(GlobalMessages.NotEnoughEnergy, this.Unit.Name, spell.GetType().Name)); } fireBreathUsed = false; } this.Unit.EnergyPoints -= spell.EnergyCost; return spell; }
public override ISpell GenerateAttack() { ISpell attack; if (this.spellCount % 2 == 0) { attack = new FireBreath(this.Unit.AttackPoints); } else { attack = new Blizzard(this.Unit.AttackPoints * 2); } if (this.Unit.EnergyPoints < attack.EnergyCost) { throw new NotEnoughEnergyException(string.Format( GlobalMessages.NotEnoughEnergy, this.Unit.Name, attack.GetType().Name)); } this.spellCount++; this.Unit.EnergyPoints -= attack.EnergyCost; return attack; }
public override ISpell GenerateAttack() { if (!this.HasCastedFBreath) { ISpell fireBreath = new FireBreath(this.Unit.AttackPoints); if (this.Unit.EnergyPoints < fireBreath.EnergyCost) { throw new NotEnoughEnergyException(this.Unit.Name + " does not have enough energy to cast Fire Breath"); } else { this.Unit.EnergyPoints -= fireBreath.EnergyCost; this.HasCastedFBreath = true; return fireBreath; } } ISpell blizzard = new Blizzard(this.Unit.AttackPoints * 2); if (this.Unit.EnergyPoints < blizzard.EnergyCost) { throw new NotEnoughEnergyException(this.Unit.Name + " does not have enough energy to cast Blizzard"); } else { this.Unit.EnergyPoints -= blizzard.EnergyCost; this.HasCastedFBreath = false; return blizzard; } }
public override ISpell GenerateAttack() { ISpell spell; int damage = this.Unit.AttackPoints; string nextSpellString = this.SpellFinder ? "FireBreath" : "Blizzard"; var fireBreath = new FireBreath(damage); var blizzard = new Blizzard(damage * 2); if (this.Unit.EnergyPoints > fireBreath.EnergyCost) { if (this.SpellFinder) { this.SpellFinder = false; spell = fireBreath; this.Unit.EnergyPoints -= spell.EnergyCost; } else { this.SpellFinder = true; spell = blizzard; this.Unit.EnergyPoints -= spell.EnergyCost; } } else { throw new NotEnoughEnergyException(string.Format(GlobalMessages.NotEnoughEnergy, this.Unit.Name, nextSpellString)); } return spell; }
public ISpell FireBreath() { int damage = this.Unit.AttackPoints; ISpell spell = new FireBreath(damage); if (this.Unit.EnergyPoints < spell.EnergyCost) { throw new NotEnoughEnergyException(this.Unit.Name + " does not have enough energy to cast FireBreath"); } else { this.Unit.EnergyPoints -= spell.EnergyCost; this._flag = 1; return spell; } }
public override ISpell GenerateAttack() { ISpell attack; if (this.attacksCounter % 2 == 0) { attack = new FireBreath(this.Unit.AttackPoints); } else { attack = new Blizzard(this.Unit.AttackPoints * 2); } this.ValidateEnergy(attack); this.attacksCounter++; this.Unit.EnergyPoints -= attack.EnergyCost; return attack; }
public override ISpell GenerateAttack() { ISpell spell = null; if (this.lastSuccessfullSpell == null || this.lastSuccessfullSpell is Blizzard) { spell = new FireBreath(this.Unit.AttackPoints); } else { spell = new Blizzard(this.Unit.AttackPoints * 2); } if (this.Unit.EnergyPoints >= spell.EnergyCost) { this.lastSuccessfullSpell = spell; this.Unit.EnergyPoints -= spell.EnergyCost; return spell; } throw new NotEnoughEnergyException(string.Format(Messages.NotEnoughEnergyException, this.Unit.Name, spell.GetType().Name)); }
public override ISpell GenerateAttack() { Spell spell = null; if (this.spellCounter%2==0) { spell = new FireBreath(this.Unit.AttackPoints); } else { spell = new Blizzard(this.Unit.AttackPoints*2); } if (spell.EnergyCost>this.Unit.EnergyPoints) { throw new NotEnoughEnergyException(string.Format("{0} does not have enough energy to cast {1}", this.Unit.Name, spell.GetType().Name)); } this.spellCounter++; this.Unit.EnergyPoints = Unit.EnergyPoints - spell.EnergyCost; return spell; }
public override ISpell GenerateAttack() { /////. Casts Fire Breath and Blizzard, alternating each time he successfully casts a spell /////(i.e. first Fire Breath, next time Blizzard, then Fire Breath again, etc.). ///// Fire Breath damage: Equals the mage's attack points. ///// Blizzard damage: Equals the mage's attack points * 2 ISpell spell; if (this.attackCount % 2 == 0) { spell = new FireBreath(this.Unit.AttackPoints); } else { spell = new Blizzard(this.Unit.AttackPoints * 2); } this.ValidateEnergyPoints(this.Unit, spell); this.attackCount++; this.Unit.EnergyPoints -= spell.EnergyCost; return spell; }
public override ISpell GenerateAttack() { ISpell spell = null; int damage = 0; if (IsFireBreath) { damage = this.Unit.AttackPoints; spell = new FireBreath(damage); this.IsThereEnoughEnergy(spell); this.IsFireBreath = !this.IsFireBreath; } else { damage = this.Unit.AttackPoints*2; spell = new Blizzard(damage); this.IsThereEnoughEnergy(spell); this.IsFireBreath = !this.IsFireBreath; } this.RemoveEnergyOnCast(spell); return spell; }