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 = SigmaIndex.Square(mapSize) .Select(s => new Tile(s.X, s.Y, terrainMap[s], maze[s] == MazeCell.Empty ? entities[s] : new Impassable(s))); return(new Map(size, size, tiles)); }
public ArraySigmaMap(MapSize size, Func <SigmaIndex, TCell> cellsFactory) { cells = new TCell[size.Y, size.X]; foreach (var index in SigmaIndex.Square(size)) { cells[index.Y, index.X] = cellsFactory(index); } }
public SparseSigmaMap(MapSize size, Func <SigmaIndex, TCell> cellsFactory, TCell defaultValue = default(TCell)) : this(size, new Dictionary <SigmaIndex, TCell>(), defaultValue) { foreach (var index in SigmaIndex.Square(size)) { var cell = cellsFactory(index); if (cell == null || !cell.Equals(defaultValue)) { cells.Add(index, cell); } } }
public MinDistanceSpawner( Random random, SpawnerConfig config, Func <Vector2i, TileObject> factory) : base(random, config, factory, maze => SigmaIndex.Square(maze.Size) .Where(s => maze[s] == MazeCell.Empty) .Select(s => new { Value = s, Distance = config.EmitterLocation.ManhattanDistance(s) }) .Where(s => s.Distance >= config.StartRadius) .Where(s => s.Distance < config.EndRadius) .Select(s => s.Value) .Where(s => s.IsAboveDiagonal(maze.Size))) { }
public IEnumerator <SigmaIndex> GetEnumerator() { return(SigmaIndex .Square(Size) .Where(s => this[s] != null).GetEnumerator()); }