コード例 #1
0
ファイル: Character.cs プロジェクト: hurricanepkt/TDandD
 public void ApplyDamage(AttackResult attack)
 {
     if (attack.Success)
         ApplyDamageToHitPoints(HitPoints - CalculateDamage(attack));
 }
コード例 #2
0
ファイル: Character.cs プロジェクト: hurricanepkt/TDandD
        private static int CalculateDamage(AttackResult attack)
        {
            var damage = 1;

            damage = damage + attack.AttackModifier;

            // This should alway be last (for now)
            if(attack.IsCriticalHit)
                damage = damage * 2;

            if(damage < 1)
                return 1;

            return damage;
        }
コード例 #3
0
        void when_strength_modifier_applies()
        {
            context["when attacking"] = () =>
            {
                context["given Strength Value is 20"] = () =>
                {
                    before = () => bob.Strength.Value = 20;
                    act = () => result = bob.Attack(5, 10);
                    it["attack roll should be higher"] = () => result.Success.should_be_true();
                    it["AttackModifier should be 5"] = () => result.AttackModifier.should_be(5);
                };

                context["given Strength Value is 1"] = () =>
                {
                    before = () => bob.Strength.Value = 1;
                    act = () => result = bob.Attack(12, 10);
                    it["attack roll should be lowered"] = () => bob.Attack(12, 10).Success.should_be_false();
                    it["AttackModifier should be -5"] = () => result.AttackModifier.should_be(-5);
                };

                context["given Strength Value is 10"] = () =>
                {
                    before = () => bob.Strength.Value = 10;
                    it["attack roll should be unmodified"] = () => bob.Attack(10, 10).Success.should_be_true();
                    it["AttackModifier should be zero"] = () => bob.Attack(10, 10).AttackModifier.should_be(0);
                    it["attack roll should be unmodified"] = () => bob.Attack(9, 10).Success.should_be_false();
                };

                context["given attack is a CriticalHit"] = () =>
                {
                    act = () => result = bob.Attack(20, 10);
                    context["given Strength of 12"] = () =>
                    {
                        before = () => bob.Strength.Value = 12;
                        it["AttackModifier should be 2"] = () => result.AttackModifier.should_be(2);
                    };

                    context["given Strength of 8"] = () =>
                    {
                        before = () => bob.Strength.Value = 8;
                        it["AttackModifier should be -2"] = () => result.AttackModifier.should_be(-2);
                    };

                    context["given Strength of 10"] = () =>
                    {
                        before = () => bob.Strength.Value = 10;
                        it["AttackModifier should be 0"] = () => result.AttackModifier.should_be(0);
                    };
                };
            };

            context["when applying damage"] = () =>
            {
                context["given AttackModifier of 1"] = () =>
                {
                    act = () => bob.ApplyDamage(new AttackResult { Success = true, AttackModifier = 1});
                    it["success attack should do 2 damage"] = () => bob.HitPoints.should_be(3);
                };

                context["given AttackModifier of 0"] = () =>
                {
                    act = () => bob.ApplyDamage(new AttackResult { Success = true, AttackModifier = 0 });
                    it["success attack should do 1 damage"] = () => bob.HitPoints.should_be(4);
                };

                context["given AttackModifier of -1"] = () =>
                {
                    act = () => bob.ApplyDamage(new AttackResult { Success = true, AttackModifier = -1 });
                    it["success attack should do 1 damage"] = () => bob.HitPoints.should_be(4);
                };

                context["given AttackModifier of -5"] = () =>
                {
                    act = () => bob.ApplyDamage(new AttackResult { Success = true, AttackModifier = -5 });
                    it["success attack should do 1 damage"] = () => bob.HitPoints.should_be(4);
                };
            };
        }