Ejemplo n.º 1
0
        private IAreaMap ConvertMap(int level, int[][] map, int width, int height)
        {
            var result = new AreaMap(level, () => new AreaMapCell(new GameEnvironment()), width, height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    result.AddObject(x, y, mapObjectsFactory.CreateFloor());

                    if (map[y][x] == MapBuilder.FilledCell)
                    {
                        var wall = mapObjectsFactory.CreateWall(TorchChance);
                        result.AddObject(x, y, wall);
                    }
                    else if (map[y][x] == MapBuilder.DoorCell)
                    {
                        var door = mapObjectsFactory.CreateDoor();
                        result.AddObject(x, y, door);
                    }
                    else if (map[y][x] == MapBuilder.TrapDoorCell)
                    {
                        var trapDoor = mapObjectsFactory.CreateTrapDoor();
                        result.AddObject(x, y, trapDoor);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        private IAreaMap ConvertMap(int level, int[][] map, int width, int height)
        {
            var result = new AreaMap(level, () => new AreaMapCell(new GameEnvironment()), width, height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    result.AddObject(x, y, mapObjectsFactory.CreateFloor());

                    if (map[y][x] == MapHandler.FilledCell || map[y][x] == MapHandler.IndestructibleCell)
                    {
                        var wall = mapObjectsFactory.CreateWall();
                        result.AddObject(x, y, wall);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        private IAreaMap ConvertToAreaMap(int level, Room[][] roomsMap, int width, int height)
        {
            var map = new AreaMap(level, () => new AreaMapCell(new GameEnvironment()), width, height);

            var currentMapY = 1;

            foreach (var row in roomsMap)
            {
                var currentMapX = 1;

                foreach (var room in row)
                {
                    currentMapX++;
                    if (room.Walls[Direction.East])
                    {
                        map.AddObject(currentMapX, currentMapY, mapObjectsFactory.CreateWall(TorchChance));
                    }
                    currentMapX++;
                }

                currentMapX = 1;
                currentMapY++;

                foreach (var room in row)
                {
                    if (room.Walls[Direction.South])
                    {
                        map.AddObject(currentMapX, currentMapY, mapObjectsFactory.CreateWall(TorchChance));
                    }
                    currentMapX++;
                    map.AddObject(currentMapX, currentMapY, mapObjectsFactory.CreateWall(TorchChance));
                    currentMapX++;
                }

                currentMapY++;
            }

            for (var y = 0; y < map.Height; y++)
            {
                map.AddObject(0, y, mapObjectsFactory.CreateWall(TorchChance));
            }

            for (var x = 0; x < map.Width; x++)
            {
                map.AddObject(x, 0, mapObjectsFactory.CreateWall(TorchChance));
            }

            for (int y = 0; y < map.Height; y++)
            {
                for (int x = 0; x < map.Width; x++)
                {
                    map.AddObject(x, y, mapObjectsFactory.CreateFloor());
                }
            }

            return(map);
        }
Ejemplo n.º 4
0
        public void DestroyableObjectsAreAddedToCache()
        {
            // Arrange
            const string destroyableId = "destr_id";
            var          destroyable   = new Mock <IDestroyableObject>();

            destroyable.SetupGet(d => d.Id).Returns(destroyableId);

            var mapCellsFactory = new Func <IAreaMapCellInternal>(() => new AreaMapCell(new Mock <IEnvironment>().Object));

            var map = new AreaMap(1, mapCellsFactory, 5, 5);

            // Act
            map.AddObject(1, 1, destroyable.Object);
            var cachedDestroyable = map.GetDestroyableObject(destroyableId);

            // Assert
            Assert.AreSame(destroyable.Object, cachedDestroyable);
        }
Ejemplo n.º 5
0
        public void AddObjectTest()
        {
            // Arrange
            const int posX            = 1;
            const int posY            = 2;
            var       mapObject       = new Mock <IMapObject>();
            var       mapCellsFactory = new Func <IAreaMapCellInternal>(() => new AreaMapCell(new Mock <IEnvironment>().Object));
            var       map             = new AreaMap(1, mapCellsFactory, 5, 5);

            // Act
            map.AddObject(posX, posY, mapObject.Object);

            // Assert
            var cell    = (AreaMapCell)map.GetCell(posX, posY);
            var objects = cell.ObjectsCollection.ToArray();

            Assert.AreEqual(1, objects.Length);
            Assert.AreSame(mapObject.Object, objects[0]);
        }
Ejemplo n.º 6
0
        public void ObjectPositionIsCached()
        {
            // Arrange
            const int posX        = 1;
            const int posY        = 2;
            var       destroyable = new Mock <IDestroyableObject>();

            destroyable.SetupGet(d => d.Id).Returns("destr_id");

            var mapCellsFactory = new Func <IAreaMapCellInternal>(() => new AreaMapCell(new Mock <IEnvironment>().Object));

            var map = new AreaMap(1, mapCellsFactory, 5, 5);

            // Act
            map.AddObject(posX, posY, destroyable.Object);
            var position = map.GetObjectPosition <IDestroyableObject>();

            // Assert
            Assert.AreEqual(posX, position.X);
            Assert.AreEqual(posY, position.Y);
        }
Ejemplo n.º 7
0
        public void RemovedObjectsAreRemovedFromPositionCache()
        {
            // Arrange
            const int posX        = 1;
            const int posY        = 2;
            var       destroyable = new Mock <IDestroyableObject>();

            destroyable.SetupGet(d => d.Id).Returns("destr_id");

            var mapCellsFactory = new Func <IAreaMapCellInternal>(() => new AreaMapCell(new Mock <IEnvironment>().Object));

            var map      = new AreaMap(1, mapCellsFactory, 5, 5);
            var position = new Point(posX, posY);

            // Act
            map.AddObject(position, destroyable.Object);
            map.RemoveObject(position, destroyable.Object);
            var searchResult = map.GetObjectPosition <IDestroyableObject>();

            // Assert
            Assert.IsNull(searchResult);
        }