コード例 #1
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();
                }
            }
        }
コード例 #2
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();
                }
            }
        }
コード例 #3
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}");
                    }
                }
            }
        }