Пример #1
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!");
    }
Пример #2
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);
    }
Пример #3
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!");
    }
Пример #4
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!");
    }
Пример #5
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!");
    }
Пример #6
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!");
    }
Пример #7
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!");
    }
Пример #8
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!");
    }
Пример #9
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!");
    }
Пример #10
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!");
    }