本文整理汇总了C#中IMap.Where方法的典型用法代码示例。如果您正苦于以下问题:C# IMap.Where方法的具体用法?C# IMap.Where怎么用?C# IMap.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMap
的用法示例。
在下文中一共展示了IMap.Where方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCommand
protected override void ExecuteCommand(IMap map, DungeonParameters parameters)
{
var sparseFactor = parameters.CellSparseFactor;
var expectedNumberOfRemovedCells =
(int)Math.Ceiling(map.Size * (sparseFactor / 100m)) - 1;
var removedCellsCount = 0;
var nonWalls = map.Where(c => !c.IsWall).ToList();
if (!nonWalls.Any())
{
throw new InvalidOperationException("All cells are walls.");
}
while (removedCellsCount < expectedNumberOfRemovedCells)
{
foreach (var cell in nonWalls.Where(c => c.IsDeadEnd).ToList())
{
if (!cell.IsDeadEnd)
continue;
var emptySide = cell.Sides
.Single(s => s.Value != Side.Wall)
.Key;
map.CreateWall(cell, emptySide);
cell.IsCorridor = false;
nonWalls.Remove(cell);
removedCellsCount++;
}
}
}
示例2: ConvertToDungeon
public IDungeon ConvertToDungeon(IMap map)
{
var dungeon = new Dungeon(map.Width * 2 + 1, map.Height * 2 + 1);
for (var x = 0; x < map.Width * 2 + 1; x++)
{
for (var y = 0; y < map.Height * 2 + 1; y++)
{
dungeon[x, y].Type = XType.Wall;
}
}
foreach (var room in map.Rooms)
{
var roomMinPoint = new Point(
room.Bounds.Location.X * 2 + 1,
room.Bounds.Location.Y * 2 + 1);
var roomMaxPoint = new Point(
room.Bounds.Right * 2,
room.Bounds.Bottom * 2);
// Fill tiles with corridor values for each room in dungeon
for (var i = roomMinPoint.X; i < roomMaxPoint.X; i++)
for (var j = roomMinPoint.Y; j < roomMaxPoint.Y; j++)
dungeon[i, j].Type = XType.Empty;
}
// Expand it each corridor cell
foreach (var cell in map.Where(c => c.IsCorridor))
{
var location = new Point(
cell.Location.X * 2 + 1,
cell.Location.Y * 2 + 1);
dungeon[location.X, location.Y].Type = XType.Empty;
switch (map[cell.Location].Sides[Dir.N])
{
case Side.Empty:
dungeon[location.X, location.Y - 1].Type = XType.Empty;
break;
case Side.Door:
dungeon[location.X, location.Y - 1].Type = XType.DoorClosed;
break;
}
switch (map[cell.Location].Sides[Dir.S])
{
case Side.Empty:
dungeon[location.X, location.Y + 1].Type = XType.Empty;
break;
case Side.Door:
dungeon[location.X, location.Y + 1].Type = XType.DoorClosed;
break;
}
switch (map[cell.Location].Sides[Dir.W])
{
case Side.Empty:
dungeon[location.X - 1, location.Y].Type = XType.Empty;
break;
case Side.Door:
dungeon[location.X - 1, location.Y].Type = XType.DoorClosed;
break;
}
switch (map[cell.Location].Sides[Dir.E])
{
case Side.Empty:
dungeon[location.X + 1, location.Y].Type = XType.Empty;
break;
case Side.Door:
dungeon[location.X + 1, location.Y].Type = XType.DoorClosed;
break;
}
}
return dungeon;
}
示例3: FindNeighbors
public void FindNeighbors(IMap map)
{
Point[] coordinates = new Point[8];
Directions[] directionArray = new Directions[8];
int adjustedSize = this.rectangle.Width; // size is distance from center to edge,
// double to ensure we end up outside of this box
directionArray[(int)Directions.East] = Directions.East;
directionArray[(int)Directions.North] = Directions.North;
directionArray[(int)Directions.NorthEast] = Directions.NorthEast;
directionArray[(int)Directions.NorthWest] = Directions.NorthWest;
directionArray[(int)Directions.South] = Directions.South;
directionArray[(int)Directions.SouthEast] = Directions.SouthEast;
directionArray[(int)Directions.SouthWest] = Directions.SouthWest;
directionArray[(int)Directions.West] = Directions.West;
coordinates[(int)Directions.East] = new Point(this.rectangle.Center.X + adjustedSize, this.rectangle.Center.Y);
coordinates[(int)Directions.North] = new Point(this.rectangle.Center.X, this.rectangle.Center.Y - adjustedSize);
coordinates[(int)Directions.NorthEast] = new Point(this.rectangle.Center.X + adjustedSize, this.rectangle.Center.Y - adjustedSize);
coordinates[(int)Directions.NorthWest] = new Point(this.rectangle.Center.X - adjustedSize, this.rectangle.Center.Y - adjustedSize);
coordinates[(int)Directions.South] = new Point(this.rectangle.Center.X, this.rectangle.Center.Y + adjustedSize);
coordinates[(int)Directions.SouthEast] = new Point(this.rectangle.Center.X + adjustedSize, this.rectangle.Center.Y + adjustedSize);
coordinates[(int)Directions.SouthWest] = new Point(this.rectangle.Center.X - adjustedSize, this.rectangle.Center.Y + adjustedSize);
coordinates[(int)Directions.West] = new Point(this.rectangle.Center.X - adjustedSize, this.rectangle.Center.Y);
foreach (Directions d in directionArray)
{
int index = (int)d;
Point point = coordinates[index];
ITile tile = map.Where(x => x.Rectangle.Center == point).SingleOrDefault() ?? new NullTile(point.ToVector());
this.adjacentTiles[index] = tile;
}
this.enabled = true;
}