Example #1
0
        public void Entity_CanMoveTowards_IsCorrect()
        {
            var entity = EntityManager.Create <BaseEntity>(new Point(0, 0), _grid);
            var cell   = _grid.GetCell(0, 1);

            cell.CellProperties.Walkable = false;
            _grid.SetCell(cell, true);

            Assert.IsFalse(entity.CanMoveTowards(new Point(0, 1)));
            Assert.IsTrue(entity.CanMoveTowards(new Point(1, 0)));
        }
        public void SetUp()
        {
            _fovWindow = new FovWindowMock();
            _grid      = BaseGrid.Create(_mapSize, _mapSize);
            GridManager.InitializeCustomGrid(_grid);

            for (int x = 0; x < _mapSize; x++)
            {
                for (int y = 0; y < _mapSize; y++)
                {
                    if (x >= 1 && y >= 1 && x < _mapSize - 1 && y < _mapSize - 1)
                    {
                        var cell = _grid.GetCell(x, y);
                        cell.CellProperties.IsExplored = true;
                        _grid.SetCell(cell);
                        continue;
                    }

                    // Add walls around the map borders
                    AddWallToGrid(x, y);
                }
            }

            // Add lamp at pos 10x10y
            AddLampToGrid(10, 10);

            // Create entity on the grid
            _entity = EntityManager.Create <BaseEntity>(new Point(1, 1), _grid);
            _entity.FieldOfViewRadius = Constants.Player.FieldOfViewRadius;
        }
        private void AddLampToGrid(int posX, int posY)
        {
            // Add a lamp
            var bottomRightCorner = _grid.GetCell(posX, posY);

            bottomRightCorner.Glyph = '.';
            bottomRightCorner.CellProperties.NormalForeground = Color.BlanchedAlmond;
            bottomRightCorner.CellProperties.Name             = "Lamp";
            bottomRightCorner.CellProperties.BlocksFov        = false;
            bottomRightCorner.CellProperties.Walkable         = true;
            bottomRightCorner.LightProperties.EmitsLight      = true;
            bottomRightCorner.LightProperties.LightRadius     = 5;
            bottomRightCorner.LightProperties.LightColor      = Color.BlanchedAlmond;
            bottomRightCorner.LightProperties.Brightness      = 0.5f;
            bottomRightCorner.CellProperties.IsExplored       = true;
            _grid.SetCell(bottomRightCorner);
        }
Example #4
0
        public void CanModifyCell()
        {
            var cell      = _grid.GetCell(0, 0);
            var prevValue = cell.CellProperties.Walkable;

            cell.CellProperties.Walkable = !cell.CellProperties.Walkable;
            _grid.SetCell(cell);

            Assert.AreEqual(!prevValue, _grid.GetCell(0, 0).CellProperties.Walkable);
        }
Example #5
0
        public void DeathEffect_Entity_IsKilledOnMovement()
        {
            Assert.IsTrue(_entity.Health > 0);

            // Set death effect on the cell
            var cell = _grid.GetCell(1, 0);

            cell.EffectProperties.AddMovementEffect((entity) =>
            {
                entity.TakeDamage(entity.Health);
            });
            _grid.SetCell(cell);

            Assert.IsTrue(_grid.GetCell(1, 0).EffectProperties.EntityMovementEffects.Count == 1);
            Assert.IsTrue(_entity.Position == new Point(0, 0));
            _entity.MoveTowards(new Point(1, 0));
            Assert.IsTrue(_entity.Position == new Point(1, 0));
            Assert.IsTrue(_entity.Health == 0);

            Assert.IsFalse(EntityManager.EntityExistsAt(_entity.Position));
        }