本文整理汇总了C#中Direction.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# Direction.HasFlag方法的具体用法?C# Direction.HasFlag怎么用?C# Direction.HasFlag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Direction
的用法示例。
在下文中一共展示了Direction.HasFlag方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MovedInDirection
public static Point MovedInDirection(this Point point, Direction direction, int steps = 1)
{
if (direction.HasFlag(Direction.Up))
point.Y -= steps;
if (direction.HasFlag(Direction.Down))
point.Y += steps;
if (direction.HasFlag(Direction.Left))
point.X -= steps;
if (direction.HasFlag(Direction.Right))
point.X += steps;
return point;
}
示例2: Facing
/// <summary>
/// Does the source direction face the 'other' direction
/// </summary>
/// <param name="source"></param>
/// <param name="other"></param>
/// <returns></returns>
public static bool Facing(this Direction source, Direction other)
{
return source.ToDirectionsArray().Any(x =>
{
switch (x)
{
case Direction.None: return false;
case Direction.North: return other.HasFlag(Direction.South);
case Direction.East: return other.HasFlag(Direction.West);
case Direction.South: return other.HasFlag(Direction.North);
case Direction.West: return other.HasFlag(Direction.East);
default: throw new ArgumentOutOfRangeException("x");
}
});
}
示例3: MovedRelativelyInDirection
public static Point MovedRelativelyInDirection(this Point point, Direction sourceDirection, Direction direction,
int steps = 1)
{
if (sourceDirection.HasFlag(Direction.Up))
{
point = point.MovedInDirection(direction, steps);
}
if (sourceDirection.HasFlag(Direction.Down))
{
point = point.MovedInDirection(direction.Flipped(), steps);
}
if (sourceDirection.HasFlag(Direction.Left))
{
point = point.MovedInDirection(direction.RotatedClockWise(), steps);
}
if (sourceDirection.HasFlag(Direction.Right))
{
point = point.MovedInDirection(direction.RotatedCounterClockWise(), steps);
}
return point;
}
示例4: GetOppositeDirection
public static Direction GetOppositeDirection(Direction dir)
{
var ret = Direction.None;
if (dir.HasFlag(Direction.North))
ret = MergeDirections(ret, Direction.South);
if (dir.HasFlag(Direction.South))
ret = MergeDirections(ret, Direction.North);
if (dir.HasFlag(Direction.East))
ret = MergeDirections(ret, Direction.West);
if (dir.HasFlag(Direction.West))
ret = MergeDirections(ret, Direction.East);
if (dir.HasFlag(Direction.Up))
ret = MergeDirections(ret, Direction.Down);
if (dir.HasFlag(Direction.Down))
ret = MergeDirections(ret, Direction.Up);
return ret;
}
示例5: ToIncrementers
private IEnumerable<Incrementer> ToIncrementers(Direction d)
{
List<Incrementer> list = new List<Incrementer>();
if (d.HasFlag(Direction.Up)) list.Add(c => new Coords(c[0], c[1] - 1));
if (d.HasFlag(Direction.Down)) list.Add(c => new Coords(c[0], c[1] + 1));
if (d.HasFlag(Direction.Left)) list.Add(c => new Coords(c[0] - 1, c[1]));
if (d.HasFlag(Direction.Right)) list.Add(c => new Coords(c[0] + 1, c[1]));
if (d.HasFlag(Direction.UpLeft)) list.Add(c => new Coords(c[0] - 1, c[1] - 1));
if (d.HasFlag(Direction.UpRight)) list.Add(c => new Coords(c[0] + 1, c[1] - 1));
if (d.HasFlag(Direction.DownLeft)) list.Add(c => new Coords(c[0] - 1, c[1] + 1));
if (d.HasFlag(Direction.DownRight)) list.Add(c => new Coords(c[0] + 1, c[1] + 1));
return list;
}
示例6: TileExistsInDirection
public bool TileExistsInDirection(Tile start, Direction d)
{
int xChange = 0;
int yChange = 0;
if (start.Type == TileMvt.Adjacent
&& GetTileMvt(d) == TileMvt.Diagonal)
{
return false;
}
if (d.HasFlag(Direction.Up))
{
yChange += -1;
}
if (d.HasFlag(Direction.Down))
{
yChange += 1;
}
if (d.HasFlag(Direction.Left))
{
xChange += -1;
}
if (d.HasFlag(Direction.Right))
{
xChange += 1;
}
int newRow = start.Row + yChange;
int newCol = start.Col + xChange;
if (!PieceExists(newRow, newCol)) return false;
return true;
}
示例7: GetOppositeDirection
public Direction GetOppositeDirection(Direction d)
{
Direction dir = new Direction();
if(d.HasFlag(Direction.Up)) dir |= Direction.Down;
if (d.HasFlag(Direction.Down)) dir |= Direction.Up;
if (d.HasFlag(Direction.Left)) dir |= Direction.Right;
if (d.HasFlag(Direction.Right)) dir |= Direction.Left;
return dir;
}