Esempio n. 1
0
        public void ExecuteTurn_WhenDoesNotHaveObjectsInCurrentRoundAndGroupRandomReturns0AndFirstGroupIsEmpty_ShouldReturnObjectFromSecondGroup(
            [Frozen] IBattleRandom battleRandom,
            BattleOrder battleOrder)
        {
            // 999 controls order to be defense
            // 0 is the to always return first obj and first group
            battleRandom.Next(Arg.Any <int>()).Returns(999, 0);

            ICombatObject outCombatObject;
            ICombatGroup  outCombatGroup;

            BattleManager.BattleSide foundInGroup;

            var attackerObject = CreateCombatObject(round: 1);
            var attackerGroup  = CreateGroup(attackerObject);
            var attackerList   = CreateList(upkeepNotParticipated: 1, combatGroups: attackerGroup);

            var defenderGroup1  = CreateGroup();
            var defenderObject2 = CreateCombatObject(round: 1);
            var defenderGroup2  = CreateGroup(defenderObject2);
            var defenderList    = CreateList(upkeepNotParticipated: 999, combatGroups: new [] { defenderGroup1, defenderGroup2 });

            var result = battleOrder.NextObject(0, attackerList, defenderList, out outCombatObject, out outCombatGroup, out foundInGroup);

            result.Should().Be(false);
            outCombatObject.Should().Be(defenderObject2);
            ((object)outCombatGroup).Should().Be(defenderGroup2);
            foundInGroup.Should().Be(BattleManager.BattleSide.Defense);
        }
Esempio n. 2
0
        public void NextObject_WhenCalled_CorrectAttackerIsReturned(int randomness, int attackerUpkeep, int defenderUpkeep, BattleManager.BattleSide side)
        {
            var random = Substitute.For <IBattleRandom>();

            random.Next(Arg.Any <int>()).Returns(randomness);
            BattleOrder battleOrder = new BattleOrder(random);

            ICombatObject outCombatObject;
            ICombatGroup  outCombatGroup;

            BattleManager.BattleSide foundInGroup;

            var attackerObject = CreateCombatObject(0);
            var attackerGroup  = CreateGroup(attackerObject);
            var attackerList   = CreateList(attackerUpkeep, attackerGroup);

            var defenderObject = CreateCombatObject(0);
            var defenderGroup  = CreateGroup(defenderObject);
            var defenderList   = CreateList(defenderUpkeep, defenderGroup);

            var result = battleOrder.NextObject(0, attackerList, defenderList, out outCombatObject, out outCombatGroup, out foundInGroup);

            result.Should().Be(true);
            outCombatObject.Should().Be(side == BattleManager.BattleSide.Attack ? attackerObject : defenderObject);
            foundInGroup.Should().Be(side);
            random.Received(1).Next(defenderUpkeep + attackerUpkeep);
        }
Esempio n. 3
0
        public void ExecuteTurn_WhenDoesNotHaveObjectsInCurrentRoundAndGroupRandomReturns0AndObjectRandomReturns1_ShouldReturnSecondObjectFromFirstGroup(
            [Frozen] IBattleRandom battleRandom,
            BattleOrder battleOrder)
        {
            // 999 controls order to be defense
            // 0 is the first group idx
            // 1 is the second combat obj idx
            // 1 is the random obj after we've found no objects are in the current round
            // 0 is going to be when looking into the attacker list (for group and obj) after it didnt find a defense
            battleRandom.Next(Arg.Any <int>()).Returns(999, 0, 1, 1, 0);

            ICombatObject outCombatObject;
            ICombatGroup  outCombatGroup;

            BattleManager.BattleSide foundInGroup;

            var attackerObject = CreateCombatObject(round: 1);
            var attackerGroup  = CreateGroup(attackerObject);
            var attackerList   = CreateList(upkeepNotParticipated: 1, combatGroups: attackerGroup);

            var defenderObject1 = CreateCombatObject(round: 1);
            var defenderObject2 = CreateCombatObject(round: 1);
            var defenderGroup   = CreateGroup(defenderObject1, defenderObject2);
            var defenderList    = CreateList(upkeepNotParticipated: 999, combatGroups: defenderGroup);

            var result = battleOrder.NextObject(0, attackerList, defenderList, out outCombatObject, out outCombatGroup, out foundInGroup);

            result.Should().Be(false);
            outCombatObject.Should().Be(defenderObject2);
            ((object)outCombatGroup).Should().Be(defenderGroup);
            foundInGroup.Should().Be(BattleManager.BattleSide.Defense);
        }
Esempio n. 4
0
        public void ExecuteTurn_WhenGroupRandomReturns1AndGroupHasNoObjectsLeft_ShouldReturnFirstObjectFromFirstGroup(
            [Frozen] IBattleRandom battleRandom,
            BattleOrder battleOrder)
        {
            // 999 controls order to be defense
            // 1 is the second group idx
            // 0 is the first combat obj idx
            battleRandom.Next(Arg.Any <int>()).Returns(999, 1, 0);

            ICombatObject outCombatObject;
            ICombatGroup  outCombatGroup;

            BattleManager.BattleSide foundInGroup;

            var attackerObject = CreateCombatObject(round: 0);
            var attackerGroup  = CreateGroup(attackerObject);
            var attackerList   = CreateList(upkeepNotParticipated: 1, combatGroups: attackerGroup);

            var defenderObject1 = CreateCombatObject(round: 0);
            var defenderGroup1  = CreateGroup(defenderObject1);
            var defenderObject2 = CreateCombatObject(round: 1);
            var defenderGroup2  = CreateGroup(defenderObject2);
            var defenderList    = CreateList(upkeepNotParticipated: 999, combatGroups: new [] { defenderGroup1, defenderGroup2 });

            var result = battleOrder.NextObject(0, attackerList, defenderList, out outCombatObject, out outCombatGroup, out foundInGroup);

            result.Should().Be(true);
            outCombatObject.Should().Be(defenderObject1);
            ((object)outCombatGroup).Should().Be(defenderGroup1);
            foundInGroup.Should().Be(BattleManager.BattleSide.Defense);
        }
Esempio n. 5
0
        public void NextObject_WhenNextObjectShouldBeDefenderAndNoDefendersAreLeftInTheRound_ShouldChooseAttacker(BattleOrder battleOrder)
        {
            ICombatObject outCombatObject;
            ICombatGroup  outCombatGroup;

            BattleManager.BattleSide foundInGroup;
            var expectedObject = CreateCombatObject(0);
            var result         = battleOrder.NextObject(0,
                                                        CreateList(1, CreateGroup(CreateCombatObject(1), expectedObject, CreateCombatObject(0))),
                                                        CreateList(1, CreateGroup(CreateCombatObject(1))),
                                                        out outCombatObject,
                                                        out outCombatGroup,
                                                        out foundInGroup);

            result.Should().Be(true);
            outCombatObject.Should().Be(expectedObject);
            foundInGroup.Should().Be(BattleManager.BattleSide.Attack);
        }
Esempio n. 6
0
        public void ExecuteTurn_WhenGroupsAreEmpty_ShouldReturnTrueAndNullObjAndNullGroup(
            BattleOrder battleOrder)
        {
            ICombatObject outCombatObject;
            ICombatGroup  outCombatGroup;

            BattleManager.BattleSide foundInGroup;

            var attackerList = CreateList(upkeepNotParticipated: 0, combatGroups: CreateGroup());

            var defenderList = CreateList(upkeepNotParticipated: 0, combatGroups: CreateGroup());

            var result = battleOrder.NextObject(0, attackerList, defenderList, out outCombatObject, out outCombatGroup, out foundInGroup);

            result.Should().Be(true);
            outCombatObject.Should().BeNull();
            ((object)outCombatGroup).Should().BeNull();
        }
Esempio n. 7
0
        public void NextObject_WhenNextObjectShouldBeAttackerAndNotAttackersLeft_ShouldChooseDefense(BattleOrder battleOrder)
        {
            ICombatObject outCombatObject;
            ICombatGroup  outCombatGroup;

            BattleManager.BattleSide foundInGroup;
            var expectedObject = CreateCombatObject(0);
            var expectedGroup  = CreateGroup(CreateCombatObject(1), expectedObject, CreateCombatObject(0));

            battleOrder.NextObject(0,
                                   CreateList(1, CreateGroup(CreateCombatObject(1))),
                                   CreateList(1, expectedGroup),
                                   out outCombatObject,
                                   out outCombatGroup,
                                   out foundInGroup).Should().Be(true);
            outCombatObject.Should().Be(expectedObject);
            foundInGroup.Should().Be(BattleManager.BattleSide.Defense);
        }
Esempio n. 8
0
        public void TestNoMoreAttacker(BattleOrder battleOrder)
        {
            ICombatObject outCombatObject;
            ICombatGroup  outCombatGroup;

            BattleManager.BattleSide foundInGroup;
            var attackerObject = CreateCombatObject(1);
            var attackerList   = CreateList(0, CreateGroup(attackerObject));

            attackerList.UpkeepNotParticipatedInRound(1).Returns(1);
            var defenderList = CreateList(0, CreateGroup(CreateCombatObject(1)));

            defenderList.UpkeepNotParticipatedInRound(1).Returns(0);

            battleOrder.NextObject(0,
                                   attackerList,
                                   defenderList,
                                   out outCombatObject,
                                   out outCombatGroup,
                                   out foundInGroup).Should().Be(false);
            foundInGroup.Should().Be(BattleManager.BattleSide.Attack);
            outCombatObject.Should().Be(attackerObject);
        }
Esempio n. 9
0
        public void NextObject_WhenNextObjectIsWaitingToJoinBattleIsTrue_ShouldNotChooseThatObject(BattleOrder battleOrder)
        {
            ICombatObject outCombatObject;
            ICombatGroup  outCombatGroup;

            BattleManager.BattleSide foundInGroup;
            var expectedObject = CreateCombatObject(0);

            var isStillWaitingToJoinbattleCombatObject = CreateCombatObject(0);

            isStillWaitingToJoinbattleCombatObject.IsWaitingToJoinBattle.Returns(true);

            var result = battleOrder.NextObject(0,
                                                CreateList(1, CreateGroup(isStillWaitingToJoinbattleCombatObject, expectedObject)),
                                                CreateList(1, CreateGroup(CreateCombatObject(1))),
                                                out outCombatObject,
                                                out outCombatGroup,
                                                out foundInGroup);

            result.Should().Be(true);
            outCombatObject.Should().Be(expectedObject);
            foundInGroup.Should().Be(BattleManager.BattleSide.Attack);
        }