本文整理汇总了C#中Direction.GetLocation方法的典型用法代码示例。如果您正苦于以下问题:C# Direction.GetLocation方法的具体用法?C# Direction.GetLocation怎么用?C# Direction.GetLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Direction
的用法示例。
在下文中一共展示了Direction.GetLocation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindValidConnections
private Direction FindValidConnections(Direction dir, Point loc)
{
var list = new List<Direction>();
var startDir = dir;
dir = dir.TurnLeft();
for (var i = 0; i < DirectionHelpers.Directions.Count() - 1; i++)
{
var newLoc = dir.GetLocation(loc);
if (newLoc.X >= 0 && newLoc.X < _cells.GetLength(0) && newLoc.Y >= 0 && newLoc.Y < _cells.GetLength(1))
{
var cell = _cells[newLoc.X, newLoc.Y];
if (cell.Type == CellType.None || cell.Openings.Facing(dir))
{
list.Add(dir);
}
}
dir = dir.TurnRight();
}
var connectsToMake = list.Count > 0 ? _random.Next(1, list.Count + 1) : 0;
var validConnections = list.Take(connectsToMake).Concat(new[] { startDir.TurnAround() }).ToArray();
// close the openings in the neighbor cells that we didn't make
foreach (var connectToUndo in list.Skip(connectsToMake))
{
var newLoc = connectToUndo.GetLocation(loc);
var dirToUndo = connectToUndo.TurnAround();
_cells[newLoc.X, newLoc.Y].Openings ^= dirToUndo;
}
return validConnections.ToDirectionFlag();
}