当前位置: 首页>>代码示例>>C#>>正文


C# Direction.HasFlag方法代码示例

本文整理汇总了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;
 }
开发者ID:BotBitsExt,项目名称:BotBitsExt.Movement,代码行数:12,代码来源:PointExtensions.cs

示例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");
         }
     });
 }
开发者ID:deccer,项目名称:ValhallaClone,代码行数:21,代码来源:Direction.cs

示例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;
 }
开发者ID:BotBitsExt,项目名称:BotBitsExt.Movement,代码行数:21,代码来源:PointExtensions.cs

示例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;
        }
开发者ID:HaKDMoDz,项目名称:Psy,代码行数:24,代码来源:Direction.cs

示例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;
 }
开发者ID:hgabor,项目名称:boardgame,代码行数:13,代码来源:Pattern.cs

示例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;
        }
开发者ID:melware,项目名称:fanorona,代码行数:35,代码来源:Board.cs

示例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;
        }
开发者ID:melware,项目名称:fanorona,代码行数:10,代码来源:Board.cs


注:本文中的Direction.HasFlag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。