Пример #1
0
        public BattleResult RunBattle(List <Group> groups, Settings settings)
        {
            BattleResult results = new BattleResult();

            List <Group> attackerGroup = groups.Where(r => r.Attacker).ToList();
            List <Group> defenderGroup = groups.Where(r => !r.Attacker).ToList();

            addBattleEntity(results, groups);

            StartRounds(attackerGroup, defenderGroup);

            addBattleEntity(results, groups, false);

            return(results);
        }
Пример #2
0
        public BattleResult addBattleEntity(BattleResult battleResult, List <Group> groups, bool before = true)
        {
            var attackerBeforeGroup = groups.FirstOrDefault(r => r.Attacker);
            var defenderBeforeGroup = groups.FirstOrDefault(r => !r.Attacker);

            //EntityType[] entityTypes = new EntityType();

            /*
             * EntityType[] vals = (EntityType[])Enum.GetValues(typeof(EntityType)).Clone();
             *
             * Parallel.ForEach(vals, (entityType) => {
             *  var quantityAttacker = attackerBeforeGroup.Entities.Count(r => r.EntityType == entityType);
             *  var quantityDefender = defenderBeforeGroup.Entities.Count(r => r.EntityType == entityType);
             *
             *  if (before)
             *  {
             *      battleResult.AttackerResults.Add(new EntityResult() { EntityType = entityType, QuantityBefore = quantityAttacker });
             *      battleResult.DefenderResults.Add(new EntityResult() { EntityType = entityType, QuantityBefore = quantityDefender });
             *  }
             *  else
             *  {
             *      battleResult.AttackerResults.FirstOrDefault(r => r.EntityType == entityType).QuantityAfter = quantityAttacker;
             *      battleResult.DefenderResults.FirstOrDefault(r => r.EntityType == entityType).QuantityAfter = quantityDefender;
             *  }
             * });
             */

            foreach (EntityType entityType in Enum.GetValues(typeof(EntityType)))
            {
                var quantityAttacker = attackerBeforeGroup.Entities.Count(r => r.EntityType == entityType);
                var quantityDefender = defenderBeforeGroup.Entities.Count(r => r.EntityType == entityType);

                if (quantityAttacker > 0)
                {
                    if (before)
                    {
                        battleResult.AttackerResults.Add(new EntityResult()
                        {
                            EntityType = entityType, QuantityBefore = quantityAttacker
                        });
                    }
                    else
                    {
                        battleResult.AttackerResults.FirstOrDefault(r => r.EntityType == entityType).QuantityAfter = quantityDefender;
                    }
                }

                if (quantityDefender > 0)
                {
                    if (before)
                    {
                        battleResult.DefenderResults.Add(new EntityResult()
                        {
                            EntityType = entityType, QuantityBefore = quantityAttacker
                        });
                    }
                    else
                    {
                        battleResult.DefenderResults.FirstOrDefault(r => r.EntityType == entityType).QuantityAfter = quantityDefender;
                    }
                }
            }

            return(battleResult);
        }