示例#1
0
        public void GivenWebDisplayTypeWhenRenderedThenCharacterInfoIsRenderedUsingHtml()
        {
            var game = new EvercraftGame();

            game.Start("Thing 1", "Thing 2");

            var display = new EvercraftGameDisplay(DisplayType.Web);

            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(display.Render(game));

            var characters = htmlDoc.DocumentNode.QuerySelectorAll("[data-character]").ToArray();

            characters.Should().HaveCount(2);

            characters.ElementAt(0).QuerySelector("[data-name]").InnerText.Should().Contain("Thing 1");
            characters.ElementAt(0).QuerySelector("[data-hit-points]").InnerText.Should().Contain("5");
            characters.ElementAt(0).QuerySelector("[data-armor]").InnerText.Should().Contain("10");
            characters.ElementAt(0).QuerySelector("[data-strength]").InnerText.Should().Contain("N/A");
            characters.ElementAt(0).QuerySelector("[data-dexterity]").InnerText.Should().Contain("N/A");
            characters.ElementAt(0).QuerySelector("[data-constitution]").InnerText.Should().Contain("N/A");

            characters.ElementAt(1).QuerySelector("[data-name]").InnerText.Should().Contain("Thing 2");
            characters.ElementAt(1).QuerySelector("[data-hit-points]").InnerText.Should().Contain("5");
            characters.ElementAt(1).QuerySelector("[data-armor]").InnerText.Should().Contain("10");
            characters.ElementAt(1).QuerySelector("[data-strength]").InnerText.Should().Contain("N/A");
            characters.ElementAt(1).QuerySelector("[data-dexterity]").InnerText.Should().Contain("N/A");
            characters.ElementAt(1).QuerySelector("[data-constitution]").InnerText.Should().Contain("N/A");
        }
示例#2
0
        public void GivenConsoleDisplayTypeAndCharactersWithAttributesWhenRenderedThenCharacterAttributesAreRenderedUsingString()
        {
            var game = new EvercraftGame();

            game.Start("Thing 1", "Thing 2");
            game.ApplyStrength(1, game.Chars[0]);
            game.ApplyStrength(2, game.Chars[1]);
            game.ApplyDexterity(3, game.Chars[0]);
            game.ApplyDexterity(4, game.Chars[1]);
            game.ApplyConstitution(5, game.Chars[0]);
            game.ApplyConstitution(6, game.Chars[1]);

            var display = new EvercraftGameDisplay(DisplayType.Console);

            var content = display.Render(game);

            content.Should().Be("Characters\n" +
                                "Thing 1:\n" +
                                "\tHit Points: 5\n" +
                                "\tArmor: 10\n" +
                                "\tStrength: 1\n" +
                                "\tDexterity: 3\n" +
                                "\tConstitution: 5\n" +
                                "Thing 2:\n" +
                                "\tHit Points: 5\n" +
                                "\tArmor: 10\n" +
                                "\tStrength: 2\n" +
                                "\tDexterity: 4\n" +
                                "\tConstitution: 6\n");
        }
示例#3
0
        public void GivenFirstCharacterHasConstitutionWithNegative_5_ThenCharacterIsNotDeadInitially()
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");
            game.ApplyConstitution(1, game.Chars[0]);

            game.IsDead(game.Chars[0]).Should().Be(false);
        }
示例#4
0
        public void GivenGameHasStartedWhenRollIsEqualToArmorThenCharacterTakesDamage()
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");

            game.Attack(10, game.Chars[1]);

            game.Chars[1].HitPts.Should().Be(4);
        }
示例#5
0
        public void GivenGameHasStartedWhenSecondCharacterAttacksTheFirstThenFirstCharacterTakesDamage()
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");

            game.Attack(10, game.Chars[0]);

            game.Chars[0].HitPts.Should().Be(4);
        }
示例#6
0
        public void GivenGameHasStartedWhenRollIsACriticalHitThenCharacterTakesDoubleDamage()
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");

            game.Attack(20, game.Chars[1]);

            game.Chars[1].HitPts.Should().Be(3);
        }
示例#7
0
        public void GivenGameHasStartedWhenCharacterEquipsHeavyArmorThenCharactersArmorIsIncreasedByTwo()
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");

            game.EquipArmor(ArmorType.Iron, 51, game.Chars[0]);

            game.Chars[0].Arm.Should().Be(12);
        }
示例#8
0
        public void GivenGameHasStartedWhenCharacterEquipsIronArmorThenCharactersArmorIsUnchanged()
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");

            game.EquipArmor(ArmorType.Iron, 50, game.Chars[1]);

            game.Chars[1].Arm.Should().Be(10);
        }
示例#9
0
        public void GivenGameHasStartedWhenCharacterEquipsSteelArmorThenCharactersArmorIsIncreasedByOne()
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");

            game.EquipArmor(ArmorType.Steel, 50, game.Chars[1]);

            game.Chars[1].Arm.Should().Be(11);
        }
示例#10
0
        public void GivenGameHasStartedWhenRollIsLessThanArmorThenNoDamageIsDealt()
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");

            game.Attack(9, game.Chars[1]);

            game.Chars[1].HitPts.Should().Be(5);
        }
示例#11
0
        public void GivenSecondCharacterHasStrengthWithPositiveModifierWhenRollIsModifiedToBeLessThanArmorThenSecondCharacterTakesOneDamage(int strength, int modifier)
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");
            game.ApplyStrength(strength, game.Chars[1]);

            game.Attack(9 - modifier, game.Chars[0]);

            game.Chars[0].HitPts.Should().Be(4);
        }
示例#12
0
        public void GivenFirstCharacterHasDexterityWithPositiveModifierWhenRollIsLessThanModifiedArmorThenFirstCharacterTakesNoDamage(int dexterity, int modifier)
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");
            game.ApplyDexterity(dexterity, game.Chars[0]);

            game.Attack(9 + modifier, game.Chars[0]);

            game.Chars[0].HitPts.Should().Be(5);
        }
示例#13
0
        public void GivenSecondCharacterHasDexterityWithPositiveModifierWhenRollIsGreaterThanModifiedArmorThenSecondCharacterTakesDamage(int dexterity, int modifier)
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");
            game.ApplyDexterity(dexterity, game.Chars[1]);

            game.Attack(10 + modifier, game.Chars[1]);

            game.Chars[1].HitPts.Should().Be(4);
        }
示例#14
0
        public void GivenCharacterHasStrengthWithNegativeModifierWhenRollIsModifiedToBeGreaterThanArmorThenCharacterTakesTwoDamage(int strength, int modifier)
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");
            game.ApplyStrength(strength, game.Chars[0]);

            game.Attack(10 - modifier, game.Chars[1]);

            game.Chars[1].HitPts.Should().Be(3);
        }
示例#15
0
        public void GivenSecondCharacterHasConstitutionWithNegative_5_ModifierWhenRollIsGreaterThanArmorThenSecondCharacterDies()
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");
            game.ApplyConstitution(1, game.Chars[1]);

            game.Attack(10, game.Chars[1]);

            game.IsDead(game.Chars[1]).Should().Be(true);
        }
示例#16
0
        public void GivenFirstCharacterHasConstitutionWithPositiveModifierWhenRollIsGreaterThanArmorThenFirstCharacterIsAliveAfterAttacks(int constitution, int attacks)
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");
            game.ApplyConstitution(constitution, game.Chars[0]);

            for (var i = 0; i < attacks; i++)
            {
                game.Attack(10, game.Chars[0]);
            }

            game.IsDead(game.Chars[0]).Should().Be(false);
        }
示例#17
0
        public void GivenCharacterHasOneHitPointLeftWhenRollIsGreaterThanArmorThenCharacterIsDead()
        {
            var game = new EvercraftGame();

            game.Start("Jack", "Bob");
            game.Attack(11, game.Chars[1]);
            game.Attack(11, game.Chars[1]);
            game.Attack(11, game.Chars[1]);
            game.Attack(11, game.Chars[1]);

            game.Attack(11, game.Chars[1]);

            game.Chars[1].HitPts.Should().Be(0);
            game.IsDead(game.Chars[1]).Should().Be(true);
        }
示例#18
0
        public void GivenGameIsNotStartedWhenStartNewGameThenDefaultCharactersAreCreated()
        {
            var game = new EvercraftGame();

            game.Start("Someone", "Other");

            game.Chars.Should().HaveCount(2);

            game.Chars[0].Name.Should().Be("Someone");
            game.Chars[0].HitPts.Should().Be(5);
            game.Chars[0].Arm.Should().Be(10);
            game.Chars[0].Str.Should().Be(null);
            game.Chars[0].Dex.Should().Be(null);
            game.Chars[0].Const.Should().Be(null);

            game.Chars[1].Name.Should().Be("Other");
            game.Chars[1].HitPts.Should().Be(5);
            game.Chars[1].Arm.Should().Be(10);
            game.Chars[1].Str.Should().Be(null);
            game.Chars[1].Dex.Should().Be(null);
            game.Chars[1].Const.Should().Be(null);
        }
示例#19
0
        public void GivenWebDisplayTypeAndCharactersWithAttributesWhenRenderedThenCharacterAttributesAreRenderedUsingHtml()
        {
            var game = new EvercraftGame();

            game.Start("Thing 1", "Thing 2");
            game.ApplyStrength(1, game.Chars[0]);
            game.ApplyStrength(2, game.Chars[1]);
            game.ApplyDexterity(3, game.Chars[0]);
            game.ApplyDexterity(4, game.Chars[1]);
            game.ApplyConstitution(5, game.Chars[0]);
            game.ApplyConstitution(6, game.Chars[1]);

            var display = new EvercraftGameDisplay(DisplayType.Web);

            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(display.Render(game));

            var characters = htmlDoc.DocumentNode.QuerySelectorAll("[data-character]").ToArray();

            characters.Should().HaveCount(2);

            characters.ElementAt(0).QuerySelector("[data-name]").InnerText.Should().Contain("Thing 1");
            characters.ElementAt(0).QuerySelector("[data-hit-points]").InnerText.Should().Contain("5");
            characters.ElementAt(0).QuerySelector("[data-armor]").InnerText.Should().Contain("10");
            characters.ElementAt(0).QuerySelector("[data-strength]").InnerText.Should().Contain("1");
            characters.ElementAt(0).QuerySelector("[data-dexterity]").InnerText.Should().Contain("3");
            characters.ElementAt(0).QuerySelector("[data-constitution]").InnerText.Should().Contain("5");

            characters.ElementAt(1).QuerySelector("[data-name]").InnerText.Should().Contain("Thing 2");
            characters.ElementAt(1).QuerySelector("[data-hit-points]").InnerText.Should().Contain("5");
            characters.ElementAt(1).QuerySelector("[data-armor]").InnerText.Should().Contain("10");
            characters.ElementAt(1).QuerySelector("[data-strength]").InnerText.Should().Contain("2");
            characters.ElementAt(1).QuerySelector("[data-dexterity]").InnerText.Should().Contain("4");
            characters.ElementAt(1).QuerySelector("[data-constitution]").InnerText.Should().Contain("6");
        }
示例#20
0
        public void GivenConsoleDisplayTypeWhenRenderedThenCharacterInfoIsRenderedUsingAString()
        {
            var game = new EvercraftGame();

            game.Start("Thing 1", "Thing 2");

            var display = new EvercraftGameDisplay(DisplayType.Console);

            var content = display.Render(game);

            content.Should().Be("Characters\n" +
                                "Thing 1:\n" +
                                "\tHit Points: 5\n" +
                                "\tArmor: 10\n" +
                                "\tStrength: N/A\n" +
                                "\tDexterity: N/A\n" +
                                "\tConstitution: N/A\n" +
                                "Thing 2:\n" +
                                "\tHit Points: 5\n" +
                                "\tArmor: 10\n" +
                                "\tStrength: N/A\n" +
                                "\tDexterity: N/A\n" +
                                "\tConstitution: N/A\n");
        }