Exemplo n.º 1
0
    public void Test_FighterCanChargeUpToThreeTimesButNotMore()
    {
        FighterStatsClass stats = new FighterStatsClass();
        int normalAttackValue   = stats.GetCurrentAttackDamage(false);

        stats.UseChargeForDamageBoost(true);
        int firstBoostValue = stats.GetCurrentAttackDamage(false);

        stats.UseChargeForDamageBoost(true);
        int secondBoostValue = stats.GetCurrentAttackDamage(false);

        stats.UseChargeForDamageBoost(true);
        int thirdBoostValue = stats.GetCurrentAttackDamage(false);

        stats.UseChargeForDamageBoost(true);
        int forthBoostValue = stats.GetCurrentAttackDamage(false);

        // TODO: Rechnung irgendwie hier rausziehen?
        int expectedDamage = Mathf.FloorToInt(stats.GetDefaultAttackDamage() * (1 + stats.GetMaxAmountOfChargings() * stats.GetChargeDamageBoost()));

        Assert.Less(normalAttackValue, firstBoostValue, "First charge for damage boost didn't increase damage!");
        Assert.Less(firstBoostValue, secondBoostValue, "Second charge for damage boost didn't increase damage!");
        Assert.Less(secondBoostValue, thirdBoostValue, "Third charge for damage boost didn't increase damage!");
        Assert.AreEqual(thirdBoostValue, forthBoostValue, "Forth charge for damage boost increased damage, but three boosts is the maximum!");
        Assert.AreEqual(expectedDamage, thirdBoostValue, "Fighter didn't deal 3x boost damage after trying to boost 4 times");
    }
Exemplo n.º 2
0
    public void Test_FighterSubclassesMustDeclareOwnReactToDodgeFunction()
    {
        FighterStatsClass stats = new FighterStatsClass();

        stats.ShowDodge();

        LogAssert.Expect(LogType.Error, "ShowDodge() must be implemented inside the sub-class!");
    }
Exemplo n.º 3
0
    public void Test_FighterDiesIfHealthDropsToZero()
    {
        FighterStatsClass stats = new FighterStatsClass();
        int killDamage          = stats.GetCurrentHealth();

        stats.ReceiveDamage(killDamage);

        Assert.AreEqual(FighterState.dead, stats.GetCurrentFighterState(), "Fighter didn't die after health dropped to zero!");
    }
Exemplo n.º 4
0
    public void Test_FighterCannotAttackNullPointer()
    {
        FighterStatsClass stats1 = new FighterStatsClass();
        FighterStatsClass stats2 = null;

        stats1.AttackOpponent(stats2, false, true);

        LogAssert.Expect(LogType.Warning, "Fighter tried to attack an opponent that's a nnullpointer. Can't attack non-existant opponents!");
    }
Exemplo n.º 5
0
    public void Test_FighterHealthCannotDropUnderZero()
    {
        const int         heavyDamage = 200;
        FighterStatsClass stats       = new FighterStatsClass();

        stats.ReceiveDamage(heavyDamage);

        Assert.Zero(stats.GetCurrentHealth(), "Fighter health is not 0 after receiving massive damage!");
    }
Exemplo n.º 6
0
    public void Test_FighterIsOnLastBreathWhileHealthBelowThreshhold()
    {
        FighterStatsClass stats = new FighterStatsClass();
        int lastBreathDamage    = Mathf.FloorToInt(stats.GetMaxHealth() - (stats.GetLastBreathThreshold() * stats.GetMaxHealth()));

        stats.ReceiveDamage(lastBreathDamage);

        Assert.AreEqual(FighterState.lastBreath, stats.GetCurrentFighterState(), "Fighter didn't get to last breath after his health dropped below the threshold!");
    }
Exemplo n.º 7
0
    public void Test_FighterCanDealAttackDamage()
    {
        FighterStatsClass stats = new FighterStatsClass();
        int dummyEnemyLife      = 100;

        dummyEnemyLife -= stats.GetCurrentAttackDamage();

        Assert.Less(dummyEnemyLife, 100, "Enemy didn't receive any damage from fighter, no attack damage dealt!");
    }
Exemplo n.º 8
0
    public void Test_FighterHealthCannotExceedMaxHealth()
    {
        FighterStatsClass stats = new FighterStatsClass();
        const int         heal  = 20;

        stats.GetHealedBy(heal);

        Assert.AreEqual(stats.GetMaxHealth(), stats.GetCurrentHealth(), "Fighter health changed after healing with full health!");
        Assert.LessOrEqual(stats.GetCurrentHealth(), stats.GetMaxHealth(), "Fighter health exceeds full health after healing!");
    }
Exemplo n.º 9
0
    public void Test_FighterCannotReceiveNegativeDamage()
    {
        FighterStatsClass stats       = new FighterStatsClass();
        const int         wrongDamage = -30;

        stats.ReceiveDamage(wrongDamage);

        LogAssert.Expect(LogType.Warning, "Fighter cannot receive negative damage. Health will not be modified.");
        Assert.AreEqual(stats.GetMaxHealth(), stats.GetCurrentHealth(), "Fighter health was modified by negative damage!");
    }
Exemplo n.º 10
0
    public void Test_FighterBeginsWithMaximumHealth()
    {
        // Arrange
        FighterStatsClass stats = new FighterStatsClass();

        // Act

        // Assert
        Assert.AreEqual(stats.GetMaxHealth(), stats.GetCurrentHealth(), "Fighter didn't start with maximum health!");
    }
Exemplo n.º 11
0
    public void Test_FighterCannotDieTwice()
    {
        FighterStatsClass stats = new FighterStatsClass();
        int killDamage          = stats.GetCurrentHealth();

        stats.ReceiveDamage(killDamage);
        stats.ReceiveDamage(killDamage);

        LogAssert.Expect(LogType.Warning, "Fighter is already dead and can no longer receive any damage!");
    }
Exemplo n.º 12
0
    public void Test_FighterCannotAttackWithoutWaitingTurnTime()
    {
        FighterStatsClass stats = new FighterStatsClass();
        FighterStatsClass enemy = new FighterStatsClass();

        Assert.IsFalse(stats.CanAct(), "Fighter was able to attack without having to wait their turn time!");

        stats.AttackOpponent(enemy, false);

        LogAssert.Expect(LogType.Warning, "Tried to attack an opponent when not allowed to do that!");
    }
Exemplo n.º 13
0
    public void Test_FighterCanBeDamaged()
    {
        FighterStatsClass stats  = new FighterStatsClass();
        const int         damage = 10;
        int expectedHealth       = stats.GetMaxHealth() - damage;

        stats.ReceiveDamage(damage);

        Assert.AreNotEqual(stats.GetMaxHealth(), stats.GetCurrentHealth(), "Fighter health didn't change after being damaged!");
        Assert.Less(stats.GetCurrentHealth(), stats.GetMaxHealth(), "Fighter health somehow increased after being damaged!");
        Assert.AreEqual(expectedHealth, stats.GetCurrentHealth(), "Fighter health is not at the expected value after being damaged!");
    }
Exemplo n.º 14
0
    public void Test_FighterCanRevoverFromLastBreath()
    {
        FighterStatsClass stats    = new FighterStatsClass();
        int       lastBreathDamage = Mathf.FloorToInt(stats.GetMaxHealth() - (stats.GetLastBreathThreshold() * stats.GetMaxHealth()));
        const int heal             = 10;

        stats.ReceiveDamage(lastBreathDamage);
        Assert.AreEqual(FighterState.lastBreath, stats.GetCurrentFighterState(), "Fighter didn't get to last breath after his health dropped below the threshold!");

        stats.GetHealedBy(heal);
        Assert.AreEqual(FighterState.alive, stats.GetCurrentFighterState(), "Fighter didn't recover from last breath after his health exceeded the threshold!");
    }
Exemplo n.º 15
0
    public void Test_AttackingAnOpponentReturnsTrueAfterLandingAHit()
    {
        FighterStatsClass stats1 = new FighterStatsClass();
        FighterStatsClass stats2 = new FighterStatsClass();

        int  fullHealth    = stats2.GetCurrentHealth();
        bool landedHit     = stats1.AttackOpponent(stats2, false, true);
        int  damagedHealth = stats2.GetCurrentHealth();

        Assert.Less(damagedHealth, fullHealth, "Fighter wasn't able to attack another fighter and damage them!");
        Assert.IsTrue(landedHit, "AttackOpponent() did not return true after landing a hit!");
    }
Exemplo n.º 16
0
    public override bool AttackOpponent(FighterStatsClass opponent, bool CanBeDodged = true, bool ignoreTurnTime = false)
    {
        if (GameCtr != null)
        {
            if (!GameCtr.TakesPartInCurrentBattle(this))
            {
                Debug.LogError("Enemy that is not part of the current battle tried to attack the player!");
            }
        }

        return(base.AttackOpponent(opponent, CanBeDodged, ignoreTurnTime));
    }
Exemplo n.º 17
0
    public void Use(FighterStatsClass user, IGameController gameCtr = null)
    {
        if (usesLeft == 0)
        {
            Debug.LogWarning("Tried to use item when it had 0 uses left. No effect!");
            return;
        }
        if (user == null)
        {
            Debug.LogWarning("Tried to use item without a user. No effect!");
            return;
        }

        switch (type)
        {
        case ItemType.AttackBoost:
            user.AddLastingDamageBoost("Boost Item", 1.2f);
            if (gameCtr != null)
            {
                SoundEffectControl sfx = gameCtr.GetSFXControl();
                if (sfx != null)
                {
                    sfx.Boost();
                }
            }
            break;

        case ItemType.Healing:
            user.GetHealedBy(80);

            if (gameCtr != null)
            {
                SoundEffectControl sfx = gameCtr.GetSFXControl();
                if (sfx != null)
                {
                    sfx.Heal();
                }
            }
            break;

        case ItemType.DealDamage:
            if (gameCtr != null)
            {
                gameCtr.PlayerThrowBomb();
            }
            break;

        default:
            Debug.LogWarning("There was no behavior specified for item of type " + type.ToString());
            break;
        }
        usesLeft--;
    }
Exemplo n.º 18
0
    public void Test_FighterCannotReceiveNegativeHealing()
    {
        FighterStatsClass stats     = new FighterStatsClass();
        const int         damage    = 30;
        const int         wrongHeal = -20;
        int expectedHealth          = stats.GetMaxHealth() - damage;

        stats.ReceiveDamage(damage);
        stats.GetHealedBy(wrongHeal);

        LogAssert.Expect(LogType.Warning, "Fighter cannot be healed by a negative amount. Health will not be modified.");
        Assert.AreEqual(expectedHealth, stats.GetCurrentHealth(), "Fighter health was modified by negative healing!");
    }
Exemplo n.º 19
0
    public void Test_FighterCanAttackAnotherFighter()
    {
        FighterStatsClass stats1 = new FighterStatsClass();
        FighterStatsClass stats2 = new FighterStatsClass();

        int fullHealth = stats2.GetCurrentHealth();

        stats1.AttackOpponent(stats2, false, true);
        int damagedHealth = stats2.GetCurrentHealth();

        Assert.Less(damagedHealth, fullHealth,
                    "Fighter wasn't able to attack another fighter and damage them!");
    }
Exemplo n.º 20
0
    public void Test_FighterCanChargeForHeavyDamage()
    {
        FighterStatsClass stats        = new FighterStatsClass();
        int dummyEnemyLifeNormalDamage = 100;
        int dummyEnemyLifeHeavyDamage  = 100;

        dummyEnemyLifeNormalDamage -= stats.GetCurrentAttackDamage();
        stats.UseChargeForDamageBoost(true);
        dummyEnemyLifeHeavyDamage -= stats.GetCurrentAttackDamage();

        Assert.AreNotEqual(dummyEnemyLifeHeavyDamage, dummyEnemyLifeNormalDamage, "Heavy damage and normal attack damage are equal!");
        Assert.Less(dummyEnemyLifeHeavyDamage, dummyEnemyLifeNormalDamage, "Heavy damage wasn't more that normal attack damage!");
    }
Exemplo n.º 21
0
    public void Test_FighterGetCurrentAttackDamageCanBeDisplayedWithoutReset()
    {
        FighterStatsClass stats = new FighterStatsClass();

        stats.UseChargeForDamageBoost(true);
        int chargedValueDisplayed = stats.GetCurrentAttackDamage(false);
        int chargedValueForAttack = stats.GetCurrentAttackDamage();
        int resettedValue         = stats.GetCurrentAttackDamage(false);


        Assert.AreEqual(chargedValueDisplayed, chargedValueForAttack, "Displaying the attack damage resetted heavy damage even if it shouldn't have done that!");
        Assert.Less(resettedValue, chargedValueForAttack, "Heavy damage wasn't reset after one attack!");
    }
Exemplo n.º 22
0
    public void Test_FighterCanBeHealed()
    {
        FighterStatsClass stats  = new FighterStatsClass();
        const int         damage = 30;
        const int         heal   = 20;
        int damagedHealth        = stats.GetMaxHealth() - damage;
        int expectedHealth       = damagedHealth + heal;

        stats.ReceiveDamage(damage);
        stats.GetHealedBy(heal);

        Assert.AreEqual(expectedHealth, stats.GetCurrentHealth(), "Fighter health is not at the expected value after healing!");
        Assert.AreNotEqual(damagedHealth, stats.GetCurrentHealth(), "Fighter health didn't change after healing!");
    }
Exemplo n.º 23
0
    public void Test_FighterCanReceiveLastingDamageBoost()
    {
        FighterStatsClass stats = new FighterStatsClass();
        int oldDamage           = stats.GetCurrentAttackDamage();

        string source = "Weapon X";
        float  boost  = 0.2f;

        stats.AddLastingDamageBoost(source, boost);

        int newDamage = stats.GetCurrentAttackDamage();

        Assert.Less(oldDamage, newDamage, "Lasting damage boost didn't increase attack damage!");
    }
Exemplo n.º 24
0
    public void Test_FighterCannotDodgeUnavoidableAttack()
    {
        FighterStatsClass stats1 = new FighterStatsClass();
        FighterStatsClass stats2 = new FighterStatsClass();

        stats2.DodgePropability = 1f;

        int fullHealth = stats2.GetCurrentHealth();

        stats1.AttackOpponent(stats2, false, true);
        int afterAttack = stats2.GetCurrentHealth();

        Assert.Less(afterAttack, fullHealth, "Fighter was able to dodge unavoidable attack!");
    }
Exemplo n.º 25
0
    public void Test_FighterChargeHeavyDamageIsRemovedAfterAttack()
    {
        FighterStatsClass stats         = new FighterStatsClass();
        int dummyEnemyLifeNormalDamage1 = 100;
        int dummyEnemyLifeHeavyDamage   = 100;
        int dummyEnemyLifeNormalDamage2 = 100;

        dummyEnemyLifeNormalDamage1 -= stats.GetCurrentAttackDamage();
        stats.UseChargeForDamageBoost(true);
        dummyEnemyLifeHeavyDamage   -= stats.GetCurrentAttackDamage();
        dummyEnemyLifeNormalDamage2 -= stats.GetCurrentAttackDamage();

        Assert.Less(dummyEnemyLifeHeavyDamage, dummyEnemyLifeNormalDamage2, "Heavy damage wasn't more that normal attack damage!");
        Assert.AreEqual(dummyEnemyLifeNormalDamage1, dummyEnemyLifeNormalDamage2, "Heavy damage wasn't reset after one attack!");
    }
Exemplo n.º 26
0
    public void Test_FighterCanDodgeIncomingAttack()
    {
        FighterStatsClass stats1 = new FighterStatsClass();
        FighterStatsClass stats2 = new FighterStatsClass();

        stats2.DodgePropability = 1f;

        int fullHealth = stats2.GetCurrentHealth();

        stats1.AttackOpponent(stats2, true, true);
        int afterAttack = stats2.GetCurrentHealth();

        Assert.AreEqual(fullHealth, afterAttack, "Fighter wasn't able to dodge incoming attack!");
        LogAssert.Expect(LogType.Error, "ShowDodge() must be implemented inside the sub-class!");
    }
Exemplo n.º 27
0
    public void Test_AttackingAnOpponentReturnsFalseAfterOpponentDodged()
    {
        FighterStatsClass stats1 = new FighterStatsClass();
        FighterStatsClass stats2 = new FighterStatsClass();

        stats2.DodgePropability = 1;

        int  fullHealth    = stats2.GetCurrentHealth();
        bool landedHit     = stats1.AttackOpponent(stats2, true, true);
        int  damagedHealth = stats2.GetCurrentHealth();

        LogAssert.Expect(LogType.Error, "ShowDodge() must be implemented inside the sub-class!");
        Assert.AreEqual(damagedHealth, fullHealth, "Attacked opponent did not dodge as expected!");
        Assert.IsFalse(landedHit, "AttackOpponent() did not return false after the opponent dodged!");
    }
Exemplo n.º 28
0
    public void Test_FighterCanRemoveLastingDamageBoost()
    {
        FighterStatsClass stats = new FighterStatsClass();
        int normalDamage        = stats.GetCurrentAttackDamage();

        string sourceA = "Item A";
        float  boostA  = 0.2f;

        stats.AddLastingDamageBoost(sourceA, boostA);

        stats.RemoveLastingDamageBoost(sourceA);
        int damageAfterRemoval = stats.GetCurrentAttackDamage();

        Assert.IsEmpty(stats.lastingDamageBoosts.Keys, "Lasting damage boosts still contain a boost after it was removed!");
        Assert.AreEqual(normalDamage, damageAfterRemoval, "Lasting damage boost couldn't be removed!");
    }
Exemplo n.º 29
0
    public void Test_FighterCannotRemoveNonexistantLastingDamageBoost()
    {
        FighterStatsClass stats = new FighterStatsClass();

        string sourceA = "Item A";
        float  boostA  = 0.2f;

        stats.AddLastingDamageBoost(sourceA, boostA);
        int boostedDamage = stats.GetCurrentAttackDamage();

        stats.RemoveLastingDamageBoost("wrongSource");
        int damageAfterAttemptedRemoval = stats.GetCurrentAttackDamage();

        Assert.AreEqual(boostedDamage, damageAfterAttemptedRemoval, "Attack damage was modified after trying to remove a non-existant lasting damage boost!");
        Assert.IsNotEmpty(stats.lastingDamageBoosts.Keys, "Lasting damage boost of different source was removed when trying to remove one of a non-existant source!");
        LogAssert.Expect(LogType.Warning, "Fighter cannot remove lasting damage boost of a source that never gave him a boost. Attacke damage will not be modified.");
    }
Exemplo n.º 30
0
    public virtual bool AttackOpponent(FighterStatsClass opponent, bool CanBeDodged = true, bool ignoreTurnTime = false)
    {
        if (!CanAct() && !ignoreTurnTime)
        {
            Debug.LogWarning("Tried to attack an opponent when not allowed to do that!");
            return(false);
        }
        if (!ignoreTurnTime)
        {
            currentTurnTime = 0;
        }

        if (opponent == null)
        {
            Debug.LogWarning("Fighter tried to attack an opponent that's a nnullpointer. Can't attack non-existant opponents!");
        }
        else if (opponent.GetCurrentFighterState() == FighterState.dead)
        {
            Debug.LogWarning("Fighter tried to attack an opponent that already died. Can't attack dead opponents!");
        }
        else
        {
            if (CanBeDodged)
            {
                float dodgeRand = 1;
                dodgeRand = Random.value;
                if (dodgeRand >= opponent.GetDodgePropability())
                {
                    opponent.ReceiveDamage(GetCurrentAttackDamage());
                    return(true);
                }
                else
                {
                    opponent.ShowDodge();
                    return(false);
                }
            }
            else
            {
                opponent.ReceiveDamage(GetCurrentAttackDamage());
                return(true);
            }
        }
        return(false);
    }