Ejemplo n.º 1
0
        public void Battle_Attack()
        {
            Unit angel    = new UnitAngel();
            Unit skeleton = new UnitSkeleton();

            UnitsStack stack1 = new UnitsStack(angel, 10);
            UnitsStack stack2 = new UnitsStack(skeleton, 42);
            UnitsStack stack3 = new UnitsStack(angel, 3);

            List <UnitsStack> stacks1 = new List <UnitsStack> {
                stack1, stack2
            };
            List <UnitsStack> stacks2 = new List <UnitsStack> {
                stack3
            };

            Army army1 = new Army(stacks1);
            Army army2 = new Army(stacks2);

            Battle battle = new Battle(army1, army2);

            battle.Start();

            BattleUnitsStack target1 = battle.GetCurrentStacks()[1];
            BattleUnitsStack target2 = battle.GetCurrentStacks()[2];

            Assert.AreEqual(3, battle.GetCurrentStacks().Count);
            Assert.Throws <InvalidOperationException>(() => battle.Attack(target2));
            battle.Attack(target1);
            Assert.AreEqual(1, target1.GetAmount());
            Assert.AreEqual(90, target1.GetTopHitPoints());
            Assert.AreEqual(2, battle.GetCurrentStacks().Count);
        }
Ejemplo n.º 2
0
        public void BattleUnitsStack_SetHitPoints()
        {
            Unit      unit               = new UnitAngel();
            const int amount             = 128;
            const int newStackHitPoints  = 368;
            const int newStackHitPoints1 = -100;
            const int newAmount          = 3;
            const int newTopHitPoints    = 8;

            int stackHitPoints     = amount * unit.GetHitPoints();
            int newStackHitPoints2 = stackHitPoints + 100;

            UnitsStack baseStack = new UnitsStack(unit, amount);

            BattleUnitsStack stack = new BattleUnitsStack(baseStack, null);

            Assert.AreEqual(stackHitPoints, stack.GetHitPoints());
            Assert.AreEqual(amount, stack.GetAmount());
            Assert.AreEqual(unit.GetHitPoints(), stack.GetTopHitPoints());
            stack.SetHitPoints(newStackHitPoints);
            Assert.AreEqual(newStackHitPoints, stack.GetHitPoints());
            Assert.AreEqual(newAmount, stack.GetAmount());
            Assert.AreEqual(newTopHitPoints, stack.GetTopHitPoints());
            stack.SetHitPoints(newStackHitPoints1);
            Assert.AreEqual(0, stack.GetHitPoints());
            Assert.AreEqual(0, stack.GetAmount());
            Assert.AreEqual(0, stack.GetTopHitPoints());
            stack.SetHitPoints(newStackHitPoints2);
            Assert.AreEqual(stackHitPoints, stack.GetHitPoints());
            Assert.AreEqual(amount, stack.GetAmount());
            Assert.AreEqual(unit.GetHitPoints(), stack.GetTopHitPoints());
        }
Ejemplo n.º 3
0
        public void Battle_Defend()
        {
            Unit angel    = new UnitAngel();
            Unit skeleton = new UnitSkeleton();

            UnitsStack stack1 = new UnitsStack(angel, 10);
            UnitsStack stack2 = new UnitsStack(skeleton, 42);
            UnitsStack stack3 = new UnitsStack(angel, 2);

            List <UnitsStack> stacks1 = new List <UnitsStack> {
                stack1, stack2
            };
            List <UnitsStack> stacks2 = new List <UnitsStack> {
                stack3
            };

            Army army1 = new Army(stacks1);
            Army army2 = new Army(stacks2);

            Battle battle = new Battle(army1, army2);

            battle.Start();

            BattleUnitsStack currentStack = battle.GetCurrentStack();

            Assert.AreEqual(3, battle.GetCurrentStacks().Count);
            battle.Defend();
            Assert.IsTrue(currentStack.ContainsMod(typeof(BattleUnitsStackModDefend)));
            Assert.AreEqual(35, currentStack.GetDefence());
            Assert.AreEqual(2, battle.GetCurrentStacks().Count);
        }
Ejemplo n.º 4
0
        public void Battle_NextRound()
        {
            Unit angel    = new UnitAngel();
            Unit skeleton = new UnitSkeleton();

            UnitsStack stack1 = new UnitsStack(angel, 10);
            UnitsStack stack2 = new UnitsStack(skeleton, 42);
            UnitsStack stack3 = new UnitsStack(angel, 2);

            List <UnitsStack> stacks1 = new List <UnitsStack> {
                stack1, stack2
            };
            List <UnitsStack> stacks2 = new List <UnitsStack> {
                stack3
            };

            Army army1 = new Army(stacks1);
            Army army2 = new Army(stacks2);

            Battle battle = new Battle(army1, army2);

            battle.Start();

            BattleUnitsStack battleStack1 = battle.GetStacks()[0];
            BattleUnitsStack battleStack3 = battle.GetStacks()[2];

            battleStack1.SetWaiting(true);

            Assert.AreEqual(1, battle.GetRound());
            Assert.IsTrue(battleStack1.IsWaiting());
            battle.NextRound();
            Assert.AreEqual(2, battle.GetRound());
            Assert.IsFalse(battleStack1.IsWaiting());
        }
Ejemplo n.º 5
0
 public AfterAnswerEventArgs(BattleUnitsStack source, BattleUnitsStack target, ushort hitPoints, bool isAnswered)
 {
     Source     = source;
     Target     = target;
     HitPoints  = hitPoints;
     IsAnswered = isAnswered;
 }
Ejemplo n.º 6
0
 public BeforeAnswerEventArgs(BattleUnitsStack source, BattleUnitsStack target, ushort hitPoints)
 {
     Source     = source;
     Target     = target;
     HitPoints  = hitPoints;
     IsAnswered = true;
 }
Ejemplo n.º 7
0
 public void Apply(BattleUnitsStack caster, BattleUnitsStack[] targets, int Time)
 {
     foreach (var t in targets)
     {
         t.AddEffect(new ReduceInitiative(Time, 2, 0.5f * caster.Count));
         t.AddEffect(new ReduceResistance(Time, 2, caster.Count * 1));
     }
 }
Ejemplo n.º 8
0
        public BattleUnitsStackMod(BattleUnitsStackModType type, int rounds, BattleUnitsStack stack)
        {
            _type   = type;
            _rounds = rounds;
            _stack  = stack;

            _roundsLeft = rounds;
        }
Ejemplo n.º 9
0
        public static void ShowArmies(BattleArmy a, BattleArmy b, Battle battle, BattleUnitsStack curstack)
        {
            Console.WriteLine("-------------------------------------------");

            for (int i = 0; i < 9; i++)
            {
                BattleUnitsStack ast    = null;
                BattleUnitsStack bst    = null;
                string           astack = "---";
                if (a.StackCount > i)
                {
                    ast    = a.Stacks[i];
                    astack = ast.CurrentUnit.Name + " C:" + ast.Count + " HP:" + ast.HitPoint.ToString() + "/" + ast.CurrentUnit.HitPoint.ToString() + " R:" +
                             ast.CurrentUnit.Resistance;
                }
                string bstack = "---";
                if (b.StackCount > i)
                {
                    bst    = b.Stacks[i];
                    bstack = bst.CurrentUnit.Name + " C:" + bst.Count + " HP:" + bst.HitPoint.ToString() + "/" + bst.CurrentUnit.HitPoint.ToString() + " R:" +
                             bst.CurrentUnit.Resistance;
                }
                if (ast != null && ast == curstack)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                }
                Console.Write("{0}) {1,-50} ", i, astack);
                Console.ForegroundColor = ConsoleColor.White;

                if (bst != null && bst == curstack)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                }
                Console.Write("{0}) {1}\n", i + 9, bstack);
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("{0,-5} {1,-40} {2,-5} {3}", "Ini", "active", "Ini", "waiting");
            for (int i = 0; i < 9; i++)
            {
                string astack = "---";
                double ai     = -0;
                if (battle.ActiveQueue.Count > i)
                {
                    ai     = battle.ActiveQueue[i].CurrentUnit.Initiative;
                    astack = battle.ActiveQueue[i].CurrentUnit.Name;
                }
                string bstack = "---";
                double bi     = -0;
                if (battle.WaitingQueue.Count > i)
                {
                    bi     = battle.WaitingQueue[i].CurrentUnit.Initiative;
                    bstack = battle.WaitingQueue[i].CurrentUnit.Name;
                }
                Console.WriteLine("{0:0.00} {1,-40} {2:0.00} {3}", ai, astack, bi, bstack);
            }
            Console.WriteLine("-------------------------------------------");
        }
Ejemplo n.º 10
0
        public UnitsStackComponent(BattleUnitsStack stack, Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            _stack = stack;

            _unitComponent = new UnitComponent(stack.GetBaseUnit().GetName(), game);

            AddChild(_unitComponent);
            UpdatePositionAndSize();
        }
Ejemplo n.º 11
0
 public bool Attack(BattleUnitsStack bus1, BattleUnitsStack bus2)
 {
     if (!bus1.Attack(bus2))
     {
         return(false);
     }
     ClearArmyies();
     ClearMap();
     return(true);
 }
Ejemplo n.º 12
0
 public void Apply(BattleUnitsStack caster, BattleUnitsStack[] targets, int Time)
 {
     try
     {
         caster.Army.AddStack(new BattleUnitsStack(unit, count * caster.Count, caster.Army));
     } catch (Exception e)
     {
         Console.WriteLine("You can't have more then 9 stacks");
     }
 }
Ejemplo n.º 13
0
        public bool Attack(BattleUnitsStack bus)
        {
            if (b.canAttack(bus))
            {
                b.Attack(bus);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 14
0
        public static void SelectStack(BattleUnitsStack stack)
        {
            if (_selectedCommand == null)
            {
                return;
            }

            _selectedCommand.SetTarget(stack);
            Execute(_selectedCommand);
            _selectedCommand = null;
        }
Ejemplo n.º 15
0
        public void addUnit(BattleUnitsStack bus, int indx)
        {
            int i = bus.getcPos().getX;
            int j = bus.getcPos().getY;

            var busClone = Instantiate(BUSPrefab, indx == 1 ? army1.transform : army2.transform);

            busClone.GetComponent <RectTransform>().localPosition = getPos(i, j);
            (indx == 1 ? army1 : army2).GetComponent <uBattleArmy>().Add(bus, bus.getcPos());
            map.GetComponent <uMap>().addUnit(bus.getcPos(), indx);
        }
Ejemplo n.º 16
0
 public void Delete(BattleUnitsStack b)
 {
     for (int i = 0; i < a.Length(); i++)
     {
         if (a.getcArmy()[i] == b)
         {
             a.Remove(i);
             Destroy(transform.GetChild(i).gameObject);
             return;
         }
     }
 }
Ejemplo n.º 17
0
    public void RefreshSpells(BattleUnitsStack b)
    {
        for (int i = 0; i < transform.childCount; i++)
        {
            transform.GetChild(i).gameObject.SetActive(false);
        }

        for (int i = 0; i < b.getSpellCount(); i++)
        {
            transform.GetChild(i).gameObject.SetActive(true);
            transform.GetChild(i).GetChild(0).GetComponent <TextMeshProUGUI>().text = b.getSpell(i).getSpellName();
            transform.GetChild(i).GetChild(1).GetComponent <TextMeshProUGUI>().text = "" + b.getSpell(i).getManaCost();
        }
    }
Ejemplo n.º 18
0
        public void BattleUnitsStack_Resurrect()
        {
            Unit      unit               = new UnitAngel();
            const int amount             = 128;
            const int resurrectHitPoints = 188;

            UnitsStack baseStack = new UnitsStack(unit, amount);

            BattleUnitsStack stack = new BattleUnitsStack(baseStack, null);

            stack.SetHitPoints(0);
            stack.Resurrect(resurrectHitPoints);
            Assert.AreEqual(resurrectHitPoints, stack.GetHitPoints());
            stack.Resurrect(resurrectHitPoints);
            Assert.AreEqual(resurrectHitPoints * 2, stack.GetHitPoints());
        }
Ejemplo n.º 19
0
        public void fill(BattleUnitsStack a1)
        {
            b = a1;

            if (b.getTypeShort() == UnitType.DRUID)
            {
                transform.GetChild(0).GetComponent <Image>().sprite = Resources.Load <Sprite>("Units/Druid");
            }
            if (b.getTypeShort() == UnitType.ELF)
            {
                transform.GetChild(0).GetComponent <Image>().sprite = Resources.Load <Sprite>("Units/Elf");
            }
            if (b.getTypeShort() == UnitType.DRAGON)
            {
                transform.GetChild(0).GetComponent <Image>().sprite = Resources.Load <Sprite>("Units/Dragon");
            }
            if (b.getTypeShort() == UnitType.ANGEL)
            {
                transform.GetChild(0).GetComponent <Image>().sprite = Resources.Load <Sprite>("Units/Angel");
            }
            if (b.getTypeShort() == UnitType.HYDRA)
            {
                transform.GetChild(0).GetComponent <Image>().sprite = Resources.Load <Sprite>("Units/Hydra");
            }
            if (b.getTypeShort() == UnitType.SHAMAN)
            {
                transform.GetChild(0).GetComponent <Image>().sprite = Resources.Load <Sprite>("Units/Shaman");
            }
            if (b.getTypeShort() == UnitType.LICH)
            {
                transform.GetChild(0).GetComponent <Image>().sprite = Resources.Load <Sprite>("Units/Lich");
            }
            if (b.getTypeShort() == UnitType.TROLL)
            {
                transform.GetChild(0).GetComponent <Image>().sprite = Resources.Load <Sprite>("Units/Troll");
            }
            if (b.getTypeShort() == UnitType.GRIFON)
            {
                transform.GetChild(0).GetComponent <Image>().sprite = Resources.Load <Sprite>("Units/Grifon");
            }
            if (b.getTypeShort() == UnitType.BEAR)
            {
                transform.GetChild(0).GetComponent <Image>().sprite = Resources.Load <Sprite>("Units/Bear");
            }

            transform.GetChild(1).transform.GetComponent <Text>().text = "" + b.getcCount();
        }
Ejemplo n.º 20
0
        public void Battle_TryToStop()
        {
            Unit angel    = new UnitAngel();
            Unit skeleton = new UnitSkeleton();

            UnitsStack stack1 = new UnitsStack(angel, 10);
            UnitsStack stack2 = new UnitsStack(skeleton, 42);
            UnitsStack stack3 = new UnitsStack(angel, 2);

            List <UnitsStack> stacks1 = new List <UnitsStack> {
                stack1, stack2
            };
            List <UnitsStack> stacks2 = new List <UnitsStack> {
                stack3
            };

            Army army1 = new Army(stacks1);
            Army army2 = new Army(stacks2);

            Battle           battle       = new Battle(army1, army2);
            BattleUnitsStack battleStack1 = battle.GetStacks()[0];
            BattleUnitsStack battleStack2 = battle.GetStacks()[1];
            BattleUnitsStack battleStack3 = battle.GetStacks()[2];

            battle.Start();
            battleStack3.SetHitPoints(0);
            battle.TryToStop();
            Assert.AreEqual(BattleState.Ended, battle.GetBattleState());
            Assert.AreEqual(army1, battle.GetWinner().GetBaseArmy());

            battle.Start();
            battleStack1.SetHitPoints(0);
            battleStack2.SetHitPoints(0);
            battleStack3.RestoreFromBaseStack();
            battle.TryToStop();
            Assert.AreEqual(BattleState.Ended, battle.GetBattleState());
            Assert.AreEqual(army2, battle.GetWinner().GetBaseArmy());

            battle.Start();
            battleStack1.SetHitPoints(0);
            battleStack2.SetHitPoints(0);
            battleStack3.SetHitPoints(0);
            battle.TryToStop();
            Assert.AreEqual(BattleState.Ended, battle.GetBattleState());
            Assert.AreEqual(army2, battle.GetWinner().GetBaseArmy());
        }
Ejemplo n.º 21
0
        public void Battle_TestBattle()
        {
            Unit angel    = new UnitAngel();
            Unit skeleton = new UnitSkeleton();

            UnitsStack stack1 = new UnitsStack(angel, 10);
            UnitsStack stack2 = new UnitsStack(skeleton, 42);
            UnitsStack stack3 = new UnitsStack(angel, 3);

            List <UnitsStack> stacks1 = new List <UnitsStack> {
                stack1, stack2
            };
            List <UnitsStack> stacks2 = new List <UnitsStack> {
                stack3
            };

            Army army1 = new Army(stacks1);
            Army army2 = new Army(stacks2);

            Battle battle = new Battle(army1, army2);

            battle.Start();

            BattleUnitsStack target1 = battle.GetStacks()[0];
            BattleUnitsStack target2 = battle.GetStacks()[1];
            BattleUnitsStack target3 = battle.GetStacks()[2];

            battle.Attack(target3);
            Assert.AreEqual(1755, target1.GetHitPoints());
            Assert.AreEqual(90, target3.GetHitPoints());
            battle.Attack(target2);
            Assert.AreEqual(90, target3.GetHitPoints());
            Assert.AreEqual(109, target2.GetHitPoints());
            battle.Attack(target3);
            Assert.AreEqual(109, target2.GetHitPoints());
            Assert.AreEqual(80, target3.GetHitPoints());
            Assert.AreEqual(2, battle.GetRound());

            Assert.AreEqual(BattleState.InGame, battle.GetBattleState());
            Assert.IsNull(battle.GetWinner());
            Assert.IsTrue(target3.IsAlive());
            battle.Attack(target3);
            Assert.IsTrue(target3.IsDead());
            Assert.AreEqual(army1, battle.GetWinner().GetBaseArmy());
            Assert.AreEqual(BattleState.Ended, battle.GetBattleState());
        }
Ejemplo n.º 22
0
        public void BattleUnitsStack_Damage()
        {
            Unit      unit            = new UnitAngel();
            const int amount          = 128;
            const int damageHitPoints = 55;

            int stackHitPoints = amount * unit.GetHitPoints();

            UnitsStack baseStack = new UnitsStack(unit, amount);

            BattleUnitsStack stack = new BattleUnitsStack(baseStack, null);

            stack.Damage(damageHitPoints);
            Assert.AreEqual(stackHitPoints - damageHitPoints, stack.GetHitPoints());
            stack.Damage(damageHitPoints);
            Assert.AreEqual(stackHitPoints - damageHitPoints * 2, stack.GetHitPoints());
        }
Ejemplo n.º 23
0
    public void NextTern(BattleUnitsStack b)
    {
        int c = 0;

        for (int i = 0; i < transform.childCount; i++)
        {
            transform.GetChild(i).gameObject.SetActive(false);
        }

        for (int i = 0; i < b.getType().getSpellCount(); i++)
        {
            Transform spell = transform.GetChild(i);
            spell.gameObject.SetActive(true);
            spell.GetChild(0).GetComponent <TextMeshProUGUI>().text = b.getType().getSpellName(i);
            spell.GetChild(1).GetComponent <TextMeshProUGUI>().text = "" + b.getType().getSpellCost(i);
        }
    }
Ejemplo n.º 24
0
        public void BattleUnitsStack_Heal()
        {
            Unit      unit            = new UnitAngel();
            const int amount          = 128;
            const int newTopHitPoints = 50;
            const int healHitPoints   = 100;

            UnitsStack baseStack = new UnitsStack(unit, amount);

            BattleUnitsStack stack = new BattleUnitsStack(baseStack, null);

            Assert.AreEqual(unit.GetHitPoints(), stack.GetTopHitPoints());
            stack.SetTopHitPoints(newTopHitPoints);
            Assert.AreEqual(newTopHitPoints, stack.GetTopHitPoints());
            stack.Heal(healHitPoints);
            Assert.AreEqual(newTopHitPoints + healHitPoints, stack.GetTopHitPoints());
        }
Ejemplo n.º 25
0
 public override void Effect(SkillContext Context)
 {
     if (curOnOff == true)
     {
         BattleUnitsStack Attacking = Context.curTargetStack;
         BattleUnitsStack Defending = Context.curStack;
         if (!Attacking.isDead() && !Defending.isDead())
         {
             Random rand = new Random();
             int    minDamage;
             int    maxDamage;
             int    fullDamage;
             int    AllHP = Defending.pCharacter.HitPoints * (Defending.curQuantity - 1) + Defending.curLastHP;
             if (Attacking.curAttack >= Defending.curDefence)
             {
                 minDamage  = Attacking.curQuantity * (int)(Attacking.curDamage.min * (1 + 0.05 * (Attacking.curAttack - Defending.curDefence)));
                 maxDamage  = Attacking.curQuantity * (int)(Attacking.curDamage.max * (1 + 0.05 * (Attacking.curAttack - Defending.curDefence)));
                 fullDamage = rand.Next(minDamage, maxDamage + 1);
                 Console.WriteLine($"-------------------Recharge: {Attacking.pCharacter.Type} -> {Defending.pCharacter.Type} {fullDamage}");
                 AllHP -= fullDamage;
                 if (AllHP < 0)
                 {
                     AllHP = 0;
                 }
                 Defending.curLastHP   = AllHP % Defending.pCharacter.HitPoints;
                 Defending.curQuantity = AllHP / Defending.pCharacter.HitPoints;
             }
             else
             {
                 minDamage  = Attacking.curQuantity * (int)(Attacking.curDamage.min / (1 + 0.05 * (Defending.curDefence - Attacking.curAttack)));
                 maxDamage  = Attacking.curQuantity * (int)(Attacking.curDamage.max / (1 + 0.05 * (Defending.curDefence - Attacking.curAttack)));
                 fullDamage = rand.Next(minDamage, maxDamage + 1);
                 Console.WriteLine($"-------------------Recharge: {Attacking.pCharacter.Type} -> {Defending.pCharacter.Type} {fullDamage}");
                 AllHP -= fullDamage;
                 if (AllHP < 0)
                 {
                     AllHP = 0;
                 }
                 Defending.curLastHP   = AllHP % Defending.pCharacter.HitPoints;
                 Defending.curQuantity = AllHP / Defending.pCharacter.HitPoints;
             }
         }
     }
 }
Ejemplo n.º 26
0
        public void Battle_Wait()
        {
            Unit angel    = new UnitAngel();
            Unit skeleton = new UnitSkeleton();

            UnitsStack stack1 = new UnitsStack(angel, 10);
            UnitsStack stack2 = new UnitsStack(skeleton, 42);
            UnitsStack stack3 = new UnitsStack(angel, 2);

            List <UnitsStack> stacks1 = new List <UnitsStack> {
                stack1, stack2
            };
            List <UnitsStack> stacks2 = new List <UnitsStack> {
                stack3
            };

            Army army1 = new Army(stacks1);
            Army army2 = new Army(stacks2);

            Battle battle = new Battle(army1, army2);

            battle.Start();

            BattleUnitsStack mainStack = battle.GetStacks()[0];

            IList <BattleUnitsStack> currentStacks = battle.GetCurrentStacks();

            Assert.AreEqual(stack1, currentStacks[0].GetBaseStack());
            Assert.AreEqual(stack3, currentStacks[1].GetBaseStack());
            Assert.AreEqual(stack2, currentStacks[2].GetBaseStack());

            battle.Wait();
            Assert.IsTrue(mainStack.IsWaiting());

            IList <BattleUnitsStack> currentStacks1 = battle.GetCurrentStacks();

            Assert.AreEqual(stack3, currentStacks1[0].GetBaseStack());
            Assert.AreEqual(stack2, currentStacks1[1].GetBaseStack());
            Assert.AreEqual(stack1, currentStacks1[2].GetBaseStack());

            battle.NextRound();
            Assert.IsFalse(mainStack.IsWaiting());
        }
Ejemplo n.º 27
0
        public void CreateBattleUnitsStack()
        {
            Unit      unit   = new UnitAngel();
            const int amount = 128;

            UnitsStack baseStack = new UnitsStack(unit, amount);

            BattleUnitsStack stack = new BattleUnitsStack(baseStack, null);

            Assert.AreEqual(baseStack, stack.GetBaseStack());
            Assert.AreEqual(unit, stack.GetBaseUnit());
            Assert.IsNull(stack.GetArmy());
            Assert.AreEqual(amount, stack.GetAmount());
            Assert.AreEqual(unit.GetHitPoints(), stack.GetTopHitPoints());
            Assert.AreEqual(unit.GetAttack(), stack.GetAttack());
            Assert.AreEqual(unit.GetDefence(), stack.GetDefence());
            Assert.AreEqual(unit.GetDamage(), stack.GetDamage());
            Assert.AreEqual(unit.GetInitiative(), stack.GetInitiative());
        }
Ejemplo n.º 28
0
 public void Apply(BattleUnitsStack caster, BattleUnitsStack[] targets, int Time)
 {
     foreach (var t in targets)
     {
         if (targets.Length > 3)
         {
             throw new Exception("Invalid number of targets ");
         }
         if (t.UnitOrigin.Type == UnitType.Vehicle)
         {
             t.ApplyDamage(caster.Count * 1000);
             t.AddEffect(new ReduceInitiative(Time, 1, 0.5f));
         }
         else
         {
             t.ApplyDamage(100);
         }
     }
 }
Ejemplo n.º 29
0
        public void BattleArmy_ContainsStack()
        {
            Unit angel    = new UnitAngel();
            Unit skeleton = new UnitSkeleton();

            UnitsStack stack1 = new UnitsStack(angel, 10);
            UnitsStack stack2 = new UnitsStack(skeleton, 42);

            List <UnitsStack> stacks = new List <UnitsStack> {
                stack1, stack2
            };

            Army       baseArmy = new Army(stacks);
            BattleArmy army     = new BattleArmy(baseArmy, null);

            BattleUnitsStack stack3 = new BattleUnitsStack(new UnitsStack(skeleton, 42), army);

            army.AddStack(stack3);
            Assert.IsTrue(army.ContainsStack(stack3));
        }
Ejemplo n.º 30
0
        private bool Cast(BattleUnitsStack caster)
        {
            var abilities = caster.Unit.Abilities.Where(ab => BattleUnitsStack.GetIsActive(ab)).ToList();

            if (abilities.Count == 0)
            {
                Console.WriteLine("У юнита нет активных способностей");
                return(false);
            }

            Console.Write("Выберите способность\n\nСпособности: ");
            Console.WriteLine(String.Join(", ", abilities));
            Console.WriteLine();
            var t = Console.ReadLine();

            success = Enum.TryParse <Abilities>(t, out var ability);
            if (!success || !caster.Unit.Abilities.Contains(ability))
            {
                Console.WriteLine("\nУ стека нет такой способности");
                return(false);
            }

            Console.WriteLine("\nВведите название стека, на который хотите применить способность");
            t = Console.ReadLine();
            if (t == null || !stacks.ContainsKey(t))
            {
                Console.WriteLine("\nСтека с таким названием не существует");
                return(false);
            }

            try
            {
                caster.Cast(ability, stacks[t]);
                return(true);
            }
            catch (MyException e)
            {
                Console.WriteLine("\n" + e.Message);
                return(false);
            }
        }