Ejemplo n.º 1
0
        public Map GenerateMap(int size)
        {
            if (size < 0)
            {
                throw new ArgumentException("Cannot create map of negative size");
            }

            if (size % 2 == 1)
            {
                throw new ArgumentException("Cannot create map of odd size");
            }

            var mapSize = new MapSize(size, size);

            var maze       = mazeGenerator.Construct(mapSize);
            var terrainMap = terrainGenerator.Construct(maze);

            var entities = entitiesGenerators
                           .Aggregate(SigmaMap.Empty <TileObject>(maze.Size),
                                      (m, g) => m.Merge(g.Spawn(maze)));

            var tiles = Location.Square(mapSize)
                        .Select(s => new Tile(s, terrainMap[s],
                                              maze[s] == MazeCell.Empty ? entities[s] : new Wall(s)));

            return(new Map(size, size, tiles));
        }
Ejemplo n.º 2
0
        public Map GenerateMap(int size)
        {
            if (size < 0)
            {
                throw new ArgumentException("Cannot create map of negative size");
            }

            if (size % 2 == 1)
            {
                throw new ArgumentException("Cannot create map of odd size");
            }

            var mapSize = new MapSize(size, size);

            var maze       = mazeGenerator.Construct(mapSize);
            var terrainMap = terrainGenerator.Construct(maze);

            var entities = entitiesGenerators
                           .Aggregate(SigmaMap.Empty <List <TileObject> >(maze.Size),
                                      (map, gen) => map.Merge(gen.Spawn(map, maze), (entityList, entity) =>
            {
                if (entityList == null)
                {
                    entityList = new List <TileObject>();
                }
                if (entity != null)
                {
                    entityList.Add(entity);
                }
                return(entityList);
            }));

            var tiles = Location.Square(mapSize)
                        .Select(s => new Tile(s, terrainMap[s],
                                              maze[s] == MazeCell.Empty ? entities[s] : new List <TileObject> {
                new Wall(s)
            }));

            return(new Map(size, size, tiles));
        }