示例#1
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");
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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");
        }