Beispiel #1
0
        public void Turn_CheckCombatLogEntries()
        {
            // arrange
            List<Combatant> combatants = new List<Combatant>();
            Combatant combatant1Copy = CopyCombatant(combatant1);
            Combatant combatant2Copy = CopyCombatant(combatant2);
            combatants.Add(combatant1Copy);
            combatants.Add(combatant2Copy);

            Battle battleClass = new Battle();

            // act
            battleClass.Turn(ref combatants);

            // assert

            // print the combatlog to test output
            for (int i = 0; i < battleClass.GetCombatLog().Count; i++)
            {
                System.Diagnostics.Trace.WriteLine(String.Format("LogEntry: {0} DefenderDamage: {1} AttackerDamage: {2}", battleClass.GetCombatLog()[i].Text, battleClass.GetCombatLog()[i].DefenderDamage, battleClass.GetCombatLog()[i].AttackerDamage));
            }

            // If a combatant died before he had a chance to do something, the combatlog will have one less entry
            // Due to the random nature of the turnorder, one can not be sure which combatant attacks first.
            if (combatants[0].Health <= 0 || combatants[1].Health <= 0)
            {
                if (battleClass.GetCombatLog().Count == 1 || battleClass.GetCombatLog().Count == 2)
                {
                    Assert.IsTrue(true);
                    return;
                }
            }
            else
            {
                Assert.AreEqual(2, battleClass.GetCombatLog().Count, "The turn method does not fill the combatlog with information correctly");
                return;
            }
            Assert.Fail("The turn method does not fill the combatlog with information correctly");
        }
Beispiel #2
0
        public void InitBattle_TestBattleOutputCombatLog()
        {
            // NOTICE: This test only tests the output of a battle
            // For each individual part of the battle, check the other tests!

            // arrange
            List<Combatant> combatants = new List<Combatant>();
            Combatant combatant1Copy = CopyCombatant(combatant1);
            Combatant combatant2Copy = CopyCombatant(combatant2);

            // to prevent the battlesystem to search the database for the combatants
            combatant1Copy.UserID = null;
            combatant2Copy.UserID = null;
            combatant1Copy.CombatantID = 0;
            combatant2Copy.CombatantID = 0;

            combatants.Add(combatant1Copy);
            combatants.Add(combatant2Copy);

            Battle battleClass = new Battle();

            // act
            try
            {
                battleClass.InitBattle(combatants);
                List<CombatLog> combatLog = battleClass.GetCombatLog();

                // print the combatlog to test output
                for (int i = 0; i < combatLog.Count; i++)
                {
                    System.Diagnostics.Trace.WriteLine(String.Format("LogEntry: {0} DefenderDamage: {1} AttackerDamage: {2}", combatLog[i].Text, combatLog[i].DefenderDamage, combatLog[i].AttackerDamage));
                }
            }
            catch (Exception ex)
            {
                // assert
                Assert.Fail("Something prohibited the battle from finishing. ErrorMsg: {0}", ex.Message);
                return;
            }
            Assert.IsTrue(true);
        }