Пример #1
0
        /// <summary>
        /// Вызывает методы стратегии AttackOppositeUnit и UseAbility обеих команд
        /// </summary>
        public void NextStep()
        {
            int whoseStep = Rand.GetRandomNum(0, 2);

            if (whoseStep == 0)
            {
                strategy.AttackOppositeUnit(firstTeam, secondTeam);
                Console.WriteLine("First team");
                strategy.UseAbility(firstTeam, secondTeam);
                Console.WriteLine("second team");
                strategy.UseAbility(secondTeam, firstTeam);
            }
            else if (whoseStep == 1)
            {
                strategy.AttackOppositeUnit(secondTeam, firstTeam);
                Console.WriteLine("second team");
                strategy.UseAbility(secondTeam, firstTeam);
                Console.WriteLine("First team");
                strategy.UseAbility(firstTeam, secondTeam);
            }
            foreach (var i in firstTeam)
            {
                Console.WriteLine(i.Name + " HP: " + i.Health);
            }
            Console.WriteLine("..............");
            foreach (var i in secondTeam)
            {
                Console.WriteLine(i.Name + " HP: " + i.Health);
            }
            Console.WriteLine("--------------------");
            CleaningOfCorpses();
        }
Пример #2
0
        public void CreateArmy(List <IUnit> army, int[] numOfUnitsInArmy)
        {
            for (int i = 0; i < numOfUnitsInArmy[0]; i++)
            {
                army.Add(new ClassesOfUnits.LightInfantry());
            }
            for (int i = 0; i < numOfUnitsInArmy[1]; i++)
            {
                army.Add(new Proxy(new ClassesOfUnits.HeavyInfantry()));
            }
            for (int i = 0; i < numOfUnitsInArmy[2]; i++)
            {
                army.Add(new ClassesOfUnits.Archer());
            }
            for (int i = 0; i < numOfUnitsInArmy[3]; i++)
            {
                army.Add(new ClassesOfUnits.Healer());
            }
            for (int i = 0; i < numOfUnitsInArmy[4]; i++)
            {
                army.Add(new ClassesOfUnits.Wizard());
            }

            int numOfUnits = numOfUnitsInArmy[0] + numOfUnitsInArmy[1] + numOfUnitsInArmy[2] + numOfUnitsInArmy[3] + numOfUnitsInArmy[4];

            IUnit unit;

            for (int i = 0; i < numOfUnits; i++)
            {
                int val = Rand.GetRandomNum(numOfUnits);
                unit      = army[val];
                army[val] = army[i];
                army[i]   = unit;
            }
        }
Пример #3
0
        public void UseAbility(List <IUnit> firstArmy, List <IUnit> secondArmy)
        {
            Console.WriteLine("One To One");

            for (int i = 1; i < firstArmy.Count; i++)
            {
                ISpecialAction unitAction;
                if (firstArmy[i].Health <= 0) //если юнит мёртв
                {
                    continue;
                }

                unitAction = firstArmy[i] as ISpecialAction;

                if ((unitAction) == null) //если у юнита нет спешл экшена
                {
                    continue;
                }
                else
                {
                    if (firstArmy[i].Name.Equals("Archer"))
                    {
                        if (i < unitAction.Range)
                        {
                            int pos;
                            if (secondArmy.Count <= unitAction.Range - i)
                            {
                                pos = Rand.GetRandomNum(secondArmy.Count);
                            }
                            else
                            {
                                pos = Rand.GetRandomNum(unitAction.Range - i);
                            }
                            int damage = unitAction.DoSpecialAction();
                            secondArmy[pos].TakeDamage(damage);

                            Console.WriteLine($"{firstArmy[i].Name} {i} нанёс {secondArmy[pos].Name} {pos} {damage} урона");
                        }
                        else
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i} слишком далеко");
                        }
                    }
                    else if (firstArmy[i].Name.Equals("Healer"))
                    {
                        int        pos;
                        List <int> healingUnits = new List <int>();

                        for (int j = i - unitAction.Range; j <= i + unitAction.Range; j++)
                        {
                            if (j < 0 || j == i)
                            {
                                continue;
                            }
                            if (j >= firstArmy.Count)
                            {
                                break;
                            }
                            if (firstArmy[j] is ICanBeHealed && firstArmy[j].MaxHealth > firstArmy[j].Health)
                            {
                                healingUnits.Add(j);
                            }
                        }
                        if (healingUnits.Count > 0)
                        {
                            int posH = Rand.GetRandomNum(healingUnits.Count);
                            pos = healingUnits[posH];
                            int heal = unitAction.DoSpecialAction();

                            ((ICanBeHealed)firstArmy[pos]).Heal(heal);
                            Console.WriteLine($"{firstArmy[i].Name} {i} вылечил {firstArmy[pos].Name} {pos} на {heal} хп");
                        }
                        else
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i}: Невозможно никого вылечить");
                        }
                    }
                    else if (firstArmy[i].Name.Equals("Wizard"))
                    {
                        int result = unitAction.DoSpecialAction();
                        if (result == -1)
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i}: не смог никого клонировать");
                            continue;
                        }
                        else
                        {
                            int        pos;
                            List <int> clonableUnits = new List <int>();

                            for (int j = i - unitAction.Range; j <= i + unitAction.Range; j++)
                            {
                                if (j < 0 || j == i)
                                {
                                    continue;
                                }
                                if (j >= firstArmy.Count)
                                {
                                    break;
                                }
                                if (firstArmy[j] is IClonable && firstArmy[j].Health > 0)
                                {
                                    clonableUnits.Add(j);
                                }
                            }
                            if (clonableUnits.Count > 0)
                            {
                                foreach (var b in clonableUnits)
                                {
                                    Console.WriteLine(b);
                                }
                                Console.WriteLine(clonableUnits.Count);
                                int posH = Rand.GetRandomNum(clonableUnits.Count);
                                Console.WriteLine(posH + " pos");
                                pos = clonableUnits[posH];

                                firstArmy.Insert(pos, ((IClonable)firstArmy[pos]).Clone());
                                if (pos < i)
                                {
                                    i++;
                                }

                                Console.WriteLine($"{firstArmy[i].Name} {i} клонировал {firstArmy[pos].Name} {pos}");
                            }
                            else
                            {
                                Console.WriteLine($"{firstArmy[i].Name} {i}: невозможно никого клонировать");
                            }
                        }
                    }
                    else if (firstArmy[i].Name.Equals("LightInfantry"))
                    {
                        int result = unitAction.DoSpecialAction();
                        if (result == -1)
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i}: не смог баффнуть тяжёлого пехотинца");
                            continue;
                        }
                        else
                        {
                            int        pos;
                            List <int> buffedUnits = new List <int>();

                            for (int j = i - unitAction.Range; j <= i + unitAction.Range; j++)
                            {
                                if (j < 0 || j == i)
                                {
                                    continue;
                                }
                                if (j >= firstArmy.Count)
                                {
                                    break;
                                }
                                if (firstArmy[j].Name.Equals("HeavyInfantry") && firstArmy[j].Health > 0)
                                {
                                    buffedUnits.Add(j);
                                }
                            }
                            if (buffedUnits.Count > 0)
                            {
                                int posH = Rand.GetRandomNum(buffedUnits.Count);
                                pos = buffedUnits[posH];

                                firstArmy[pos] = new ClassesOfUnits.DecoratedHeavyInfantry(firstArmy[pos]);

                                Console.WriteLine($"{firstArmy[i].Name} {i} баффнул {firstArmy[pos].Name} {pos}");
                            }
                            else
                            {
                                Console.WriteLine($"{firstArmy[i].Name} {i}: невозможно никого баффнуть");
                            }
                        }
                    }
                    //unitAction.DoSpecialAction();
                }
            }
        }
Пример #4
0
        public void UseAbility(List <IUnit> firstArmy, List <IUnit> secondArmy)
        {
            Console.WriteLine("Three To Three");
            for (int i = 3; i < firstArmy.Count; i++) //начинаем с 3 позиции, так как 0, 1, 2 дерутся
            {
                ISpecialAction unitAction;
                if (firstArmy[i].Health <= 0) //если юнит мёртв
                {
                    continue;
                }

                unitAction = firstArmy[i] as ISpecialAction;

                if ((unitAction) == null) //если у юнита нет спешл экшена
                {
                    continue;
                }
                else
                {
                    if (firstArmy[i].Name.Equals("Archer"))
                    {
                        if (i / 3 < unitAction.Range)
                        {
                            int pos;
                            if (secondArmy.Count / 3 <= unitAction.Range - i / 3)
                            {
                                pos = Rand.GetRandomNum(secondArmy.Count);
                            }
                            else
                            {
                                pos = Rand.GetRandomNum(unitAction.Range - (i / 3));
                            }
                            int damage = unitAction.DoSpecialAction();
                            secondArmy[pos].TakeDamage(damage);

                            Console.WriteLine($"{firstArmy[i].Name} {i} нанёс {secondArmy[pos].Name} {pos} {damage} урона");
                        }
                        else
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i} слишком далеко");
                        }
                    }
                    else if (firstArmy[i].Name.Equals("Healer"))
                    {
                        int        pos;
                        List <int> healingUnits = new List <int>();

                        for (int j = i - unitAction.Range * 3; j <= i + unitAction.Range * 3; j++)
                        {
                            if (j < 0 || j == i || i % 3 > (j % 3 + unitAction.Range) || (i % 3 + unitAction.Range) < (j % 3))
                            {
                                Console.WriteLine($"Healer {i}не прошёл проверку в цикле");
                                continue;
                            }
                            if (j >= firstArmy.Count)
                            {
                                break;
                            }
                            if (firstArmy[j] is ICanBeHealed && firstArmy[j].MaxHealth > firstArmy[j].Health)
                            {
                                healingUnits.Add(j);
                            }
                        }
                        if (healingUnits.Count > 0)
                        {
                            int posH = Rand.GetRandomNum(healingUnits.Count);
                            pos = healingUnits[posH];
                            int heal = unitAction.DoSpecialAction();

                            ((ICanBeHealed)firstArmy[pos]).Heal(heal);
                            Console.WriteLine($"{firstArmy[i].Name} {i} вылечил {firstArmy[pos].Name} {pos} на {heal} хп");
                        }
                        else
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i}: Невозможно никого вылечить");
                        }
                    }
                    else if (firstArmy[i].Name.Equals("Wizard"))
                    {
                        int result = unitAction.DoSpecialAction();
                        if (result == -1)
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i}: не смог никого клонировать");
                            continue;
                        }
                        else
                        {
                            int        pos;
                            List <int> clonableUnits = new List <int>();

                            for (int j = i - unitAction.Range * 3; j <= i + unitAction.Range * 3; j++)
                            {
                                if (j < 0 || j == i || i % 3 > (j % 3 + unitAction.Range) || (i % 3 + unitAction.Range) < (j % 3))
                                {
                                    Console.WriteLine($"wizard {i} не прошёл проверку в цикле");
                                    continue;
                                }
                                if (j >= firstArmy.Count)
                                {
                                    break;
                                }
                                if (firstArmy[j] is IClonable && firstArmy[j].Health > 0)
                                {
                                    clonableUnits.Add(j);
                                }
                            }
                            if (clonableUnits.Count > 0)
                            {
                                int posH = Rand.GetRandomNum(clonableUnits.Count);
                                pos = clonableUnits[posH];

                                firstArmy.Insert(pos, ((IClonable)firstArmy[pos]).Clone()); //добавляем в список юнитов клон
                                if (pos < i)
                                {
                                    i++;
                                }

                                Console.WriteLine($"{firstArmy[i].Name} {i} клонировал {firstArmy[pos].Name} {pos}");
                            }
                            else
                            {
                                Console.WriteLine($"{firstArmy[i].Name} {i}: невозможно никого клонировать");
                            }
                        }
                    }
                    else if (firstArmy[i].Name.Equals("LightInfantry"))
                    {
                        int result = unitAction.DoSpecialAction();
                        if (result == -1)
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i}: не смог баффнуть тяжёлого пехотинца");
                            continue;
                        }
                        else
                        {
                            int        pos;
                            List <int> buffedUnits = new List <int>();

                            for (int j = i - unitAction.Range * 3; j <= i + unitAction.Range * 3; j++)
                            {
                                if (j < 0 || j == i || i % 3 > (j % 3 + unitAction.Range) || (i % 3 + unitAction.Range) < (j % 3))
                                {
                                    Console.WriteLine($"LightInfantry {i} не прошёл проверку в цикле");
                                    continue;
                                }
                                if (j >= firstArmy.Count)
                                {
                                    break;
                                }
                                if (firstArmy[j].Name.Equals("HeavyInfantry") && firstArmy[j].Health > 0)
                                {
                                    buffedUnits.Add(j);
                                }
                            }
                            if (buffedUnits.Count > 0)
                            {
                                int posH = Rand.GetRandomNum(buffedUnits.Count);
                                pos = buffedUnits[posH];

                                firstArmy[pos] = new ClassesOfUnits.DecoratedHeavyInfantry(firstArmy[pos]);

                                Console.WriteLine($"{firstArmy[i].Name} {i} бафнул {firstArmy[pos].Name} {pos}");
                            }
                            else
                            {
                                Console.WriteLine($"{firstArmy[i].Name} {i}:некого бафать");
                            }
                        }
                    }
                    //unitAction.DoSpecialAction();
                }
            }
        }
Пример #5
0
        public void UseAbility(List <IUnit> firstArmy, List <IUnit> secondArmy)
        {
            Console.WriteLine("All To All");
            int minorArmyCount;

            if (firstArmy.Count > secondArmy.Count)
            {
                minorArmyCount = secondArmy.Count;
            }
            else
            {
                Console.WriteLine("Армии равны, способности не работают.");
                return;
            }

            for (int i = minorArmyCount; i < firstArmy.Count; i++) //начинаем с конца меньшей армии
            {
                ISpecialAction unitAction;

                if (firstArmy[i].Health <= 0)
                {
                    return;
                }

                unitAction = firstArmy[i] as ISpecialAction;
                if ((unitAction) == null) //если у юнита нет спешл экшена
                {
                    continue;
                }

                if (i >= minorArmyCount + unitAction.Range)
                {
                    continue;
                }


                else
                {
                    if (firstArmy[i].Name.Equals("Archer"))
                    {
                        int pos;
                        int firstNum = i - unitAction.Range;
                        if (firstNum < 0)
                        {
                            pos = Rand.GetRandomNum(minorArmyCount);
                        }
                        else
                        {
                            pos = Rand.GetRandomNum(firstNum, minorArmyCount);
                        }

                        int damage = unitAction.DoSpecialAction();
                        secondArmy[pos].TakeDamage(damage);

                        Console.WriteLine($"{firstArmy[i].Name} {i} нанёс {secondArmy[pos].Name} {pos} {damage} урона");
                    }
                    else if (firstArmy[i].Name.Equals("Healer"))
                    {
                        List <int> healingUnits = new List <int>();
                        for (int j = i - unitAction.Range; j <= i + unitAction.Range; j++)
                        {
                            if (j < 0 || j == i)
                            {
                                continue;
                            }
                            if (j >= firstArmy.Count)
                            {
                                break;
                            }

                            if (firstArmy[j] is ICanBeHealed)
                            {
                                healingUnits.Add(j);
                            }
                        }

                        int posH;
                        if (healingUnits.Count > 0)
                        {
                            posH = Rand.GetRandomNum(healingUnits.Count);
                        }
                        else
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i} некого хилить");
                            continue;
                        }
                        int pos = healingUnits[posH];

                        ((ICanBeHealed)firstArmy[pos]).Heal(unitAction.DoSpecialAction()); //хилим
                        Console.WriteLine($"{firstArmy[i].Name} {i} похилил {firstArmy[pos].Name} {pos}");
                    }
                    else if (firstArmy[i].Name.Equals("Wizard"))
                    {
                        int result = unitAction.DoSpecialAction();
                        if (result == -1)
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i} не смог никого копировать");
                            continue;
                        }
                        List <int> clonableUnits = new List <int>();
                        for (int j = i - unitAction.Range; j <= i + unitAction.Range; j++)
                        {
                            if (j < 0 || j == i)
                            {
                                continue;
                            }
                            if (j >= firstArmy.Count)
                            {
                                break;
                            }

                            if (firstArmy[j] is IClonable)
                            {
                                clonableUnits.Add(j);
                            }
                        }

                        int posH;
                        if (clonableUnits.Count > 0)
                        {
                            posH = Rand.GetRandomNum(clonableUnits.Count);
                        }
                        else
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i} некого копировать");
                            continue;
                        }
                        int pos = clonableUnits[posH];

                        firstArmy.Insert(pos, ((IClonable)firstArmy[pos]).Clone()); //клонируем

                        if (pos < i)
                        {
                            i++;
                        }

                        Console.WriteLine($"{firstArmy[i].Name} {i} клонировал {firstArmy[pos].Name} {pos}");
                    }
                    else if (firstArmy[i].Name.Equals("LightInfantry"))
                    {
                        int result = unitAction.DoSpecialAction();
                        if (result == -1)
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i}: не смог баффнуть тяжёлого пехотинца");
                            continue;
                        }

                        List <int> buffedUnits = new List <int>();
                        for (int j = i - unitAction.Range; j <= i + unitAction.Range; j++)
                        {
                            if (j < 0 || j == i)
                            {
                                continue;
                            }
                            if (j >= firstArmy.Count)
                            {
                                break;
                            }

                            if (firstArmy[j].Name.Equals("HeavyInfantry") && firstArmy[j].Health > 0)
                            {
                                buffedUnits.Add(j);
                            }
                        }

                        int posH;
                        if (buffedUnits.Count > 0)
                        {
                            posH = Rand.GetRandomNum(buffedUnits.Count);
                        }
                        else
                        {
                            Console.WriteLine($"{firstArmy[i].Name} {i}: некого бафать");
                            continue;
                        }
                        int pos = buffedUnits[posH];

                        firstArmy[pos] = new ClassesOfUnits.DecoratedHeavyInfantry(firstArmy[pos]);
                        Console.WriteLine($"{firstArmy[i].Name} {i} баффнул {firstArmy[pos].Name} {pos}");
                    }
                }
            }
        }