Exemple #1
0
        public void AddCharacter_ThrowsArgumentExceptionIfThereIsNoPlaceForCharacter()
        {
            // arrange
            var character  = Mock.Of <Character>();
            var character2 = Mock.Of <Character>();
            var scene      = new Scene();

            scene.InitializeLandscape(new Vector3(1, 1, 1));
            scene.AddCharacter(character);

            // act

            // assert
            Assert.Throws <ArgumentException>(() => scene.AddCharacter(character2));
        }
Exemple #2
0
        public void Step_CallsCharactersStep()
        {
            // arrange
            var scene = new Scene();

            scene.InitializeLandscape(new Vector3(3, 1, 1));

            var characters = new[]
            {
                new Mock <Character>(),
                new Mock <Character>(),
                new Mock <Character>(),
            };

            var i = 0;

            foreach (var character in characters)
            {
                character.SetupGet(c => c.Position).Returns(new Vector3(i++, 0, 0));
                scene.AddCharacter(character.Object);
            }

            // act
            scene.Step();

            // assert
            foreach (var character in characters)
            {
                character.Verify(c => c.Step(), Times.Once);
            }
        }
Exemple #3
0
        private static Scene Generate()
        {
            var floor = new Decoration {
                Appearance = new ColoredCharacter('_', ConsoleColor.DarkGray), Name = "Пол"
            };

            var scene = new Scene();

            scene.InitializeLandscape(new Vector3(128, 128, 1));

            for (var x = 0; x < scene.Decorations.GetLength(0); x++)
            {
                for (var y = 0; y < scene.Decorations.GetLength(1); y++)
                {
                    scene.Decorations[x, y, 0] = floor;
                }
            }

            scene.AddCharacter(Player.Current);
            scene.AddCharacter(new Character
            {
                Appearance         = new ColoredCharacter('e', ConsoleColor.Red),
                DeadBodyAppearance = new ColoredCharacter('$', ConsoleColor.DarkYellow),
                Behaviour          = new NeedsBehaviour
                {
                    Needs = new Need[]
                    {
                        new BloodNeed {
                            SearchRange = 5,
                        },
                    },
                },
                Damage    = 10,
                Health    = 25,
                Position  = new Vector3(2, 2, 0),
                Name      = "Зомби",
                Inventory = new Inventory {
                    PassiveItems = { new Item {
                                         Name = "Ключ от дома Ария"
                                     } }
                },
            });

            return(scene);
        }
Exemple #4
0
        public void IsPlaceFree_ReturnsFalseIfThereIsCharacter()
        {
            // arrange
            var scene = new Scene();

            scene.InitializeLandscape(new Vector3(1, 1, 1));
            scene.AddCharacter(new Character());

            // act
            var result = scene.IsPlaceFree(new Vector3());

            // assert
            Assert.IsFalse(result);
        }
Exemple #5
0
        public void TryMove_ReturnsFalseIfThereIsNoPlace()
        {
            // arrange
            var character = new Character();
            var scene     = new Scene();

            scene.InitializeLandscape(new Vector3(1, 1, 1));
            scene.AddCharacter(character);

            // act
            var result = character.TryMove(new Vector3(1, 2, 3));

            // assert
            Assert.IsFalse(result);
        }
Exemple #6
0
        public void AddCharacter_PutsCharacterOnTheSceneByItsPosition()
        {
            // arrange
            var character = Mock.Of <Character>();
            var scene     = new Scene();

            scene.InitializeLandscape(new Vector3(1, 1, 1));

            // act
            scene.AddCharacter(character);

            // assert
            Assert.AreEqual(character, scene.GetCharacterAt(new Vector3()));
            Assert.AreEqual(scene, character.Scene);
        }
Exemple #7
0
        public void TryMove_ReturnsTrueAndMovesCharacterIfItIsPossible()
        {
            // arrange
            var character = new Character();
            var scene     = new Scene();

            scene.InitializeLandscape(new Vector3(4, 4, 4));
            scene.AddCharacter(character);

            // act
            var result = character.TryMove(new Vector3(1, 2, 3));

            // assert
            Assert.IsTrue(result);
            Assert.AreEqual(character, scene.GetCharacterAt(new Vector3(1, 2, 3)));
        }