protected override ICreaturesInBattle GetByIdentifier(CreatureIdentifier identifier)
        {
            if (identifier == null)
            {
                throw new ArgumentNullException("identifier");
            }

            if (identifier.ArmyNumber == 1)
            {
                return this.firstArmyCreatures
                    .FirstOrDefault(x => x.Creature.GetType().Name == identifier.CreatureType);
            }

            if (identifier.ArmyNumber == 2)
            {
                return this.secondArmyCreatures
                    .FirstOrDefault(x => x.Creature.GetType().Name == identifier.CreatureType);
            }

            if (identifier.ArmyNumber == 3)
            {
                return this.thirdArmyCreatures
                    .FirstOrDefault(x => x.Creature.GetType().Name == identifier.CreatureType);
            }

            throw new ArgumentException(
                string.Format(CultureInfo.InvariantCulture, "Invalid ArmyNumber: {0}", identifier.ArmyNumber));
        }
        protected override void AddCreaturesByIdentifier(CreatureIdentifier creatureIdentifier, ICreaturesInBattle creaturesInBattle)
        {
            if (creatureIdentifier == null)
            {
                throw new ArgumentNullException("creatureIdentifier");
            }

            if (creaturesInBattle == null)
            {
                throw new ArgumentNullException("creaturesInBattle");
            }

            if (creatureIdentifier.ArmyNumber >= 3)
            {
                int armyNumber = creatureIdentifier.ArmyNumber;
                if (armies.Capacity < armyNumber)
                {
                    armies.AddRange(new ICollection<ICreaturesInBattle>[armyNumber - armies.Capacity + 1]);
                }

                if (armies[armyNumber] == null)
                {
                    armies[armyNumber] = new List<ICreaturesInBattle>();
                }

                this.armies[armyNumber].Add(creaturesInBattle);
                //this.thirthArmyCreatures.Add(creaturesInBattle);
            }
            else
            {
                base.AddCreaturesByIdentifier(creatureIdentifier, creaturesInBattle);
            }
        }
        protected override void AddCreaturesByIdentifier(CreatureIdentifier creatureIdentifier, ICreaturesInBattle creaturesInBattle)
        {
            if (creatureIdentifier == null)
            {
                throw new ArgumentNullException("creatureIdentifier");
            }

            if (creaturesInBattle == null)
            {
                throw new ArgumentNullException("creaturesInBattle");
            }

            if (creatureIdentifier.ArmyNumber == 1)
            {
                this.firstArmyCreatures.Add(creaturesInBattle);
            }
            else if (creatureIdentifier.ArmyNumber == 2)
            {
                this.secondArmyCreatures.Add(creaturesInBattle);
            }
            else if (creatureIdentifier.ArmyNumber == 3)
            {
                this.thirdArmyCreatures.Add(creaturesInBattle);
            }
            else
            {
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                    "Invalid ArmyNumber: {0}",
                    creatureIdentifier.ArmyNumber));
            }
        }
 protected override ICreaturesInBattle GetByIdentifier(CreatureIdentifier identifier)
 {
     if (identifier.ArmyNumber == 3)
     {
         return this.thirdArmyCreatures.FirstOrDefault(x => x.Creature.GetType().Name == identifier.CreatureType);
     }
     return base.GetByIdentifier(identifier);
 }
        protected override void AddCreaturesByIdentifier(CreatureIdentifier creatureIdentifier, ICreaturesInBattle creaturesInBattle)
        {
            if (creatureIdentifier.ArmyNumber == 3)
            {
                this.thirdArmyCreatues.Add(creaturesInBattle);
            }

            base.AddCreaturesByIdentifier(creatureIdentifier, creaturesInBattle);
        }
 protected override ICreaturesInBattle GetByIdentifier(CreatureIdentifier identifier)
 {
     if (identifier.ArmyNumber == 1)
     {
         return this.FirstArmyCreatures.FirstOrDefault(x => x.Creature.GetType().Name == identifier.CreatureType);
     }
     else
     {
         return this.SecondArmyCreatures.FirstOrDefault(x => x.Creature.GetType().Name == identifier.CreatureType);
     }
 }
 protected override void AddCreaturesByIdentifier(CreatureIdentifier creatureIdentifier, ICreaturesInBattle creaturesInBattle)
 {
     if (creatureIdentifier.ArmyNumber == 1)
     {
         this.FirstArmyCreatures.Add(creaturesInBattle);
     }
     else if (creatureIdentifier.ArmyNumber == 2)
     {
         this.SecondArmyCreatures.Add(creaturesInBattle);
     }
 }
        protected override ICreaturesInBattle GetByIdentifier(CreatureIdentifier identifier)
        {
            if (identifier == null)
            {
                throw new ArgumentNullException("identifier");
            }

            if (identifier.ArmyNumber == 3)
            {
                return this.thirdArmyCreatures.FirstOrDefault(x => x.Creature.GetType().Name == identifier.CreatureType);
            }
            return base.GetByIdentifier(identifier);
        }
Example #9
0
        public void Attack(CreatureIdentifier attackerIdentifier, CreatureIdentifier defenderIdentifier)
        {
            var attackerCreature = this.GetByIdentifier(attackerIdentifier);
            if (attackerCreature == null)
            {
                throw new ArgumentException(
                    string.Format(CultureInfo.InvariantCulture, "Attacker not found: {0}", attackerIdentifier));
            }

            var defenderCreature = this.GetByIdentifier(defenderIdentifier);
            if (defenderCreature == null)
            {
                throw new ArgumentException(
                    string.Format(CultureInfo.InvariantCulture, "Defender not found: {0}", defenderIdentifier));
            }

            attackerCreature.StartNewTurn();
            defenderCreature.StartNewTurn();

            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "Attacker before", attackerCreature));
            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "Defender before", defenderCreature));

            // Call ApplyWhenAttacking on attacker
            foreach (var speciallity in attackerCreature.Creature.Specialties)
            {
                speciallity.ApplyWhenAttacking(attackerCreature, defenderCreature);
            }

            // Call ApplyWhenDefending on defender
            foreach (var speciallity in defenderCreature.Creature.Specialties)
            {
                speciallity.ApplyWhenDefending(defenderCreature, attackerCreature);
            }

            // Call ChangeDamage on attacker
            attackerCreature.DealDamage(defenderCreature);

            // Call ApplyAfterDefending on defender
            foreach (var speciallity in defenderCreature.Creature.Specialties)
            {
                speciallity.ApplyAfterDefending(defenderCreature);
            }

            if (attackerIdentifier.ArmyNumber == defenderIdentifier.ArmyNumber)
            {
                throw new ArgumentException();
            }

            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "Attacker after", attackerCreature));
            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "Defender after", defenderCreature));
        }
Example #10
0
        public void Attack(CreatureIdentifier attackerIdentifier, CreatureIdentifier defenderIdentifier)
        {
            var attackerCreature = this.GetByIdentifier(attackerIdentifier);

            if (attackerCreature == null)
            {
                throw new ArgumentException(
                          string.Format(CultureInfo.InvariantCulture, "Attacker not found: {0}", attackerIdentifier));
            }

            var defenderCreature = this.GetByIdentifier(defenderIdentifier);

            if (defenderCreature == null)
            {
                throw new ArgumentException(
                          string.Format(CultureInfo.InvariantCulture, "Defender not found: {0}", defenderIdentifier));
            }

            attackerCreature.StartNewTurn();
            defenderCreature.StartNewTurn();

            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "Attacker before", attackerCreature));
            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "Defender before", defenderCreature));

            // Call ApplyWhenAttacking on attacker
            foreach (var speciallity in attackerCreature.Creature.Specialties)
            {
                speciallity.ApplyWhenAttacking(attackerCreature, defenderCreature);
            }

            // Call ApplyWhenDefending on defender
            foreach (var speciallity in defenderCreature.Creature.Specialties)
            {
                speciallity.ApplyWhenDefending(defenderCreature, attackerCreature);
            }

            // Call ChangeDamage on attacker
            attackerCreature.DealDamage(defenderCreature);

            // Call ApplyAfterDefending on defender
            foreach (var speciallity in defenderCreature.Creature.Specialties)
            {
                speciallity.ApplyAfterDefending(defenderCreature);
            }

            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "Attacker after", attackerCreature));
            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "Defender after", defenderCreature));
        }
Example #11
0
        public void AddCreatures(CreatureIdentifier creatureIdentifier, int count)
        {
            if (creatureIdentifier == null)
            {
                throw new ArgumentNullException("creatureIdentifier");
            }

            var creature = this.creaturesFactory.CreateCreature(creatureIdentifier.CreatureType);
            var creaturesInBattle = new CreaturesInBattle(creature, count);
            this.AddCreaturesByIdentifier(creatureIdentifier, creaturesInBattle);

            this.logger.WriteLine(
                string.Format(
                    CultureInfo.InvariantCulture,
                    LogFormat,
                    string.Format(CultureInfo.InvariantCulture, "Creature added to army {0}", creatureIdentifier.ArmyNumber),
                    creature));
        }
 protected override void AddCreaturesByIdentifier(CreatureIdentifier creatureIdentifier, ICreaturesInBattle creaturesInBattle)
 {
     try
     {
         base.AddCreaturesByIdentifier(creatureIdentifier, creaturesInBattle);
     }
     catch (ArgumentOutOfRangeException e)
     {
         if (creatureIdentifier.ArmyNumber == 3)
         {
             this.thirdArmyCreatures.Add(creaturesInBattle);
         }
         else
         {
             throw new ArgumentException(e.Message);
         }
     }
 }
Example #13
0
        public void AddCreatures(CreatureIdentifier creatureIdentifier, int count)
        {
            if (creatureIdentifier == null)
            {
                throw new ArgumentNullException("creatureIdentifier");
            }

            var creature          = this.creaturesFactory.CreateCreature(creatureIdentifier.CreatureType);
            var creaturesInBattle = new CreaturesInBattle(creature, count);

            this.AddCreaturesByIdentifier(creatureIdentifier, creaturesInBattle);

            this.logger.WriteLine(
                string.Format(
                    CultureInfo.InvariantCulture,
                    LogFormat,
                    string.Format(CultureInfo.InvariantCulture, "Creature added to army {0}", creatureIdentifier.ArmyNumber),
                    creature));
        }
Example #14
0
        public void Skip(CreatureIdentifier creatureIdentifier)
        {
            var creature = this.GetByIdentifier(creatureIdentifier);

            if (creature == null)
            {
                throw new ArgumentException(
                          string.Format(CultureInfo.InvariantCulture, "Skip creature not found: {0}", creatureIdentifier));
            }

            creature.StartNewTurn();

            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "Before skip", creature));

            creature.Skip();
            creature.StartNewTurn();

            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "After skip", creature));
        }
        protected override void AddCreaturesByIdentifier(CreatureIdentifier creatureIdentifier, ICreaturesInBattle creaturesInBattle)
        {
            if (creatureIdentifier == null)
            {
                throw new ArgumentNullException("creatureIdentifier");
            }

            if (creaturesInBattle == null)
            {
                throw new ArgumentNullException("creaturesInBattle");
            }

            if (creatureIdentifier.ArmyNumber == 3)
            {
                this.thirdArmyCreatures.Add(creaturesInBattle);
                return;
            }

            base.AddCreaturesByIdentifier(creatureIdentifier, creaturesInBattle);
        }
Example #16
0
        protected virtual ICreaturesInBattle GetByIdentifier(CreatureIdentifier identifier)
        {
            if (identifier == null)
            {
                throw new ArgumentNullException("identifier");
            }

            if (identifier.ArmyNumber == 1)
            {
                return(this.firstArmyCreatures.FirstOrDefault(x => x.Creature.GetType().Name == identifier.CreatureType));
            }

            if (identifier.ArmyNumber == 2)
            {
                return(this.secondArmyCreatures.FirstOrDefault(x => x.Creature.GetType().Name == identifier.CreatureType));
            }

            throw new ArgumentException(
                      string.Format(CultureInfo.InvariantCulture, "Invalid ArmyNumber: {0}", identifier.ArmyNumber));
        }
        protected override ICreaturesInBattle GetByIdentifier(CreatureIdentifier identifier)
        {
            ICreaturesInBattle result = null;

            try
            {
                result = base.GetByIdentifier(identifier);
            }
            catch (ArgumentException ae)
            {
                if (identifier.ArmyNumber == 3)
                {
                    result = this.thirdArmyCreatures.FirstOrDefault(x => x.Creature.GetType().Name == identifier.CreatureType);
                }
                else
                {
                    throw new ArgumentException(ae.Message);
                }
            }

            return result;
        }
Example #18
0
        public void Skip(CreatureIdentifier creatureIdentifier)
        {
            var creature = this.GetByIdentifier(creatureIdentifier);
            if (creature == null)
            {
                throw new ArgumentException(
                    string.Format(CultureInfo.InvariantCulture, "Skip creature not found: {0}", creatureIdentifier));
            }

            creature.StartNewTurn();

            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "Before skip", creature));

            creature.Skip();
            creature.StartNewTurn();

            this.logger.WriteLine(string.Format(CultureInfo.InvariantCulture, LogFormat, "After skip", creature));
        }