Exemple #1
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);
        }
Exemple #2
0
        public void CreateBattle()
        {
            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);

            Assert.AreEqual(army1, battle.GetAttacker().GetBaseArmy());
            Assert.AreEqual(army2, battle.GetTarget().GetBaseArmy());
            Assert.AreEqual(BattleState.None, battle.GetBattleState());
            Assert.AreEqual(0, battle.GetRound());
            Assert.IsNull(battle.GetWinner());
            Assert.IsNull(battle.GetCurrentStacks());
            Assert.IsNull(battle.GetCurrentStack());
            Assert.IsNull(battle.GetCurrentArmy());
        }
Exemple #3
0
        public void CreateArmy_OutOfRange()
        {
            Unit angel    = new UnitAngel();
            Unit skeleton = new UnitSkeleton();

            UnitsStack stack1 = new UnitsStack(angel, 10);
            UnitsStack stack2 = new UnitsStack(skeleton, 42);
            UnitsStack stack3 = new UnitsStack(skeleton, 11);
            UnitsStack stack4 = new UnitsStack(angel, 12);
            UnitsStack stack5 = new UnitsStack(angel, 1);
            UnitsStack stack6 = new UnitsStack(skeleton, 133);
            UnitsStack stack7 = new UnitsStack(skeleton, 977);

            List <UnitsStack> stacks = new List <UnitsStack> {
                stack1, stack2, stack3, stack4, stack5, stack6
            };

            Army army1 = new Army(stacks);

            Assert.AreEqual(stacks, army1.GetStacks());

            stacks.Add(stack7);

            Assert.Throws <ArgumentOutOfRangeException>(() => new Army(stacks));
        }
Exemple #4
0
        public void Battle_Stop()
        {
            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);

            Assert.AreEqual(BattleState.None, battle.GetBattleState());
            battle.Stop();
            Assert.AreEqual(BattleState.Ended, battle.GetBattleState());
        }
Exemple #5
0
        public void Battle_Surrender()
        {
            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();
            Assert.AreEqual(BattleState.InGame, battle.GetBattleState());
            battle.Surrender();
            Assert.AreEqual(army2, battle.GetWinner().GetBaseArmy());
            Assert.AreEqual(BattleState.Ended, battle.GetBattleState());

            battle.Start();
            Assert.AreEqual(BattleState.InGame, battle.GetBattleState());
            battle.Wait();
            battle.Surrender();
            Assert.AreEqual(army1, battle.GetWinner().GetBaseArmy());
            Assert.AreEqual(BattleState.Ended, battle.GetBattleState());
        }
Exemple #6
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);
        }
Exemple #7
0
        public void BattleArmy_GetStacks()
        {
            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, 42);

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

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

            army.GetStack(0).SetHitPoints(0);

            IList <BattleUnitsStack> aliveStacks = army.GetAliveStacks();
            IList <BattleUnitsStack> deadStacks  = army.GetDeadStacks();

            Assert.AreEqual(2, aliveStacks.Count);
            Assert.AreEqual(stack2, aliveStacks[0].GetBaseStack());
            Assert.AreEqual(stack3, aliveStacks[1].GetBaseStack());
            Assert.AreEqual(1, deadStacks.Count);
            Assert.AreEqual(stack1, deadStacks[0].GetBaseStack());
        }
Exemple #8
0
        public void Battle_Side()
        {
            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);

            BattleArmy battleArmy1 = battle.GetAttacker();
            BattleArmy battleArmy2 = battle.GetTarget();

            Assert.IsTrue(battleArmy1.IsAttacker());
            Assert.IsFalse(battleArmy1.IsTarget());
            Assert.IsFalse(battleArmy2.IsAttacker());
            Assert.IsTrue(battleArmy2.IsTarget());
        }
Exemple #9
0
        public void Battle_NextTurn()
        {
            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();

            Assert.AreEqual(1, battle.GetRound());
            Assert.AreEqual(3, battle.GetCurrentStacks().Count);
            battle.NextTurn();
            Assert.AreEqual(2, battle.GetCurrentStacks().Count);
            battle.NextTurn();
            Assert.AreEqual(1, battle.GetCurrentStacks().Count);
            battle.NextTurn();
            Assert.AreEqual(2, battle.GetRound());
            Assert.AreEqual(3, battle.GetCurrentStacks().Count);
        }
Exemple #10
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());
        }
        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());
        }
Exemple #12
0
        public void CreateUnitsStack_OutOfRange()
        {
            Unit      unit   = new UnitAngel();
            const int amount = 1_000_000;

            Assert.Throws <ArgumentOutOfRangeException>(() => new UnitsStack(unit, amount));
        }
Exemple #13
0
        public void CreateUnitsStack()
        {
            Unit      unit   = new UnitAngel();
            const int amount = 128;

            UnitsStack stack = new UnitsStack(unit, amount);

            Assert.AreEqual(unit, stack.GetUnit());
            Assert.AreEqual(amount, stack.GetAmount());
        }
        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());
        }
Exemple #15
0
        public void CreateArmy()
        {
            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 army = new Army(stacks);

            Assert.AreEqual(stacks, army.GetStacks());
        }
Exemple #16
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());
        }
Exemple #17
0
        public void CreateUnitAngel()
        {
            const int hitPoints = 180;
            const int attack    = 27;
            const int defence   = 27;

            (int, int)damage = (45, 45);
            const float initiative = 11.0f;

            Unit unit = new UnitAngel();

            Assert.AreEqual(hitPoints, unit.GetHitPoints());
            Assert.AreEqual(attack, unit.GetAttack());
            Assert.AreEqual(defence, unit.GetDefence());
            Assert.AreEqual(damage, unit.GetDamage());
            Assert.AreEqual(initiative, unit.GetInitiative());
        }
Exemple #18
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());
        }
        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());
        }
        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());
        }
Exemple #21
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());
        }
        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());
        }
Exemple #23
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));
        }
        public void BattleUnitsStack_GetHitPoints()
        {
            Unit      unit            = new UnitAngel();
            const int amount          = 128;
            const int newTopHitPoints = 80;
            const int newAmount       = 120;

            int stackHitPoints     = amount * unit.GetHitPoints();
            int newStackHitPoints  = stackHitPoints - 100;
            int newStackHitPoints1 = newStackHitPoints - (amount - newAmount) * unit.GetHitPoints();

            UnitsStack baseStack = new UnitsStack(unit, amount);

            BattleUnitsStack stack = new BattleUnitsStack(baseStack, null);

            Assert.AreEqual(stackHitPoints, stack.GetHitPoints());
            stack.SetTopHitPoints(newTopHitPoints);
            Assert.AreEqual(newStackHitPoints, stack.GetHitPoints());
            stack.SetAmount(newAmount);
            Assert.AreEqual(newStackHitPoints1, stack.GetHitPoints());
        }
Exemple #25
0
        public void Battle_GetStacks()
        {
            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();

            IList <BattleUnitsStack> stacks = battle.GetStacks();

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

            stacks[0].SetHitPoints(0);

            IList <BattleUnitsStack> aliveStacks = battle.GetAliveStacks();
            IList <BattleUnitsStack> deadStacks  = battle.GetDeadStacks();

            Assert.AreEqual(2, aliveStacks.Count);
            Assert.AreEqual(stacks[1], aliveStacks[0]);
            Assert.AreEqual(stacks[2], aliveStacks[1]);
            Assert.AreEqual(1, deadStacks.Count);
            Assert.AreEqual(stacks[0], deadStacks[0]);
        }
        public void BattleUnitsStack_Setters()
        {
            Unit      unit            = new UnitAngel();
            const int amount          = 128;
            const int newAmount       = 100;
            const int newTopHitPoints = 50;
            const int newAttack       = 10;
            const int newDefence      = 12;

            (int, int)newDamage = (15, 30);
            float newInitiative = 1.1F;

            UnitsStack baseStack = new UnitsStack(unit, amount);

            BattleUnitsStack stack = new BattleUnitsStack(baseStack, null);

            Assert.AreEqual(amount, stack.GetAmount());
            stack.SetAmount(newAmount);
            Assert.AreEqual(newAmount, stack.GetAmount());

            Assert.AreEqual(unit.GetHitPoints(), stack.GetTopHitPoints());
            stack.SetTopHitPoints(newTopHitPoints);
            Assert.AreEqual(newTopHitPoints, stack.GetTopHitPoints());

            Assert.AreEqual(unit.GetAttack(), stack.GetAttack());
            stack.SetAttack(newAttack);
            Assert.AreEqual(newAttack, stack.GetAttack());

            Assert.AreEqual(unit.GetDefence(), stack.GetDefence());
            stack.SetDefence(newDefence);
            Assert.AreEqual(newDefence, stack.GetDefence());

            Assert.AreEqual(unit.GetDamage(), stack.GetDamage());
            stack.SetDamage(newDamage);
            Assert.AreEqual(newDamage, stack.GetDamage());

            Assert.AreEqual(unit.GetInitiative(), stack.GetInitiative());
            stack.SetInitiative(newInitiative);
            Assert.AreEqual(newInitiative, stack.GetInitiative());
        }
Exemple #27
0
        public void BattleArmy_RemoveStack()
        {
            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 stack = army.GetStack(0);

            Assert.AreEqual(2, army.GetStacks().Count);
            Assert.IsTrue(army.RemoveStack(stack));
            Assert.AreEqual(1, army.GetStacks().Count);
            Assert.IsFalse(army.RemoveStack(stack));
        }
Exemple #28
0
        public void CreateBattleArmy()
        {
            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);

            Assert.AreEqual(baseArmy, army.GetBaseArmy());
            Assert.IsNull(army.GetBattle());
            Assert.AreEqual(stack1, army.GetBaseArmy().GetStacks()[0]);
            Assert.AreEqual(stack2, army.GetBaseArmy().GetStacks()[1]);
            Assert.AreEqual(stack1, army.GetStack(0).GetBaseStack());
            Assert.AreEqual(stack2, army.GetStack(1).GetBaseStack());
        }
Exemple #29
0
        public void BattleArmy_AddStack()
        {
            Unit angel    = new UnitAngel();
            Unit skeleton = new UnitSkeleton();

            UnitsStack stack1 = new UnitsStack(angel, 10);
            UnitsStack stack2 = new UnitsStack(angel, 5);

            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);
            BattleUnitsStack stack4  = new BattleUnitsStack(new UnitsStack(skeleton, 42), army);
            BattleUnitsStack stack5  = new BattleUnitsStack(new UnitsStack(skeleton, 42), army);
            BattleUnitsStack stack6  = new BattleUnitsStack(new UnitsStack(skeleton, 42), army);
            BattleUnitsStack stack7  = new BattleUnitsStack(new UnitsStack(skeleton, 42), army);
            BattleUnitsStack stack8  = new BattleUnitsStack(new UnitsStack(skeleton, 42), army);
            BattleUnitsStack stack9  = new BattleUnitsStack(new UnitsStack(skeleton, 42), army);
            BattleUnitsStack stack10 = new BattleUnitsStack(new UnitsStack(skeleton, 42), army);

            Assert.AreEqual(2, army.GetStacks().Count);
            army.AddStack(stack3);
            Assert.AreEqual(3, army.GetStacks().Count);
            Assert.AreEqual(stack3, army.GetStack(2));
            army.AddStack(stack4);
            army.AddStack(stack5);
            army.AddStack(stack6);
            army.AddStack(stack7);
            army.AddStack(stack8);
            army.AddStack(stack9);
            Assert.AreEqual(9, army.GetStacks().Count);
            Assert.Throws <ArgumentOutOfRangeException>(() => army.AddStack(stack10));
        }