Esempio n. 1
0
        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 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;
            }
        }