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


C# Point.DirectionsTo方法代码示例

本文整理汇总了C#中System.Point.DirectionsTo方法的典型用法代码示例。如果您正苦于以下问题:C# Point.DirectionsTo方法的具体用法?C# Point.DirectionsTo怎么用?C# Point.DirectionsTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Point的用法示例。


在下文中一共展示了Point.DirectionsTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindShortestPath_Backwards

 private Tuple<bool, List<Point>> FindShortestPath_Backwards(Point start, Point end, Point last, int moves_left)
 {
     Point diff = end - start;
     Point dirs = start.DirectionsTo(end) * new Point(-1, -1);
     Point next_horizontal = start + new Point(dirs.X, 0);
     Point next_vertical = start + new Point(0, dirs.Y);
     bool vertical_is_available = map.NodeIsType<AvailableNode>(next_vertical) && next_vertical != last;
     bool horizontal_is_available = map.NodeIsType<AvailableNode>(next_horizontal) && next_horizontal != last;
     bool extra_moves_available = diff.X + diff.Y < moves_left;
     if (!horizontal_is_available && vertical_is_available)
     {
         return FindShortestPath_Vertical(start, end, last, moves_left);
     }
     else if (!vertical_is_available && horizontal_is_available)
     {
         Tuple<bool, List<Point>> retval = FindShortestPath(next_horizontal, end, start, moves_left - 1);
         if (!retval.Item1)
             return retval;
         retval.Item2.Add(start);
         return retval;
     }
     else if (vertical_is_available && horizontal_is_available)
     {
         Tuple<bool, List<Point>> retval_vertical = FindShortestPath(next_vertical, end, start, moves_left - 1);
         Tuple<bool, List<Point>> retval_horizontal = FindShortestPath(next_horizontal, end, start, moves_left - 1);
         if (!retval_horizontal.Item1 && retval_vertical.Item1)
             return retval_vertical;
         if (!retval_vertical.Item1 && retval_horizontal.Item1)
             return retval_horizontal;
         if (retval_vertical.Item1 && retval_horizontal.Item1)
         {
             if (retval_vertical.Item2.Count < retval_horizontal.Item2.Count)
                 return retval_vertical;
             if (retval_horizontal.Item2.Count < retval_vertical.Item2.Count)
                 return retval_horizontal;
             bool choose_vertical = random.Next(2) == 0;
             if (choose_vertical)
                 return retval_vertical;
             return retval_horizontal;
         }
     }
     return Tuple.Create(false, new List<Point>());
 }
开发者ID:smartboyathome,项目名称:Haxxit,代码行数:43,代码来源:Path.cs

示例2: FindShortestPath_Vertical

 private Tuple<bool, List<Point>> FindShortestPath_Vertical(Point start, Point end, Point last, int moves_left)
 {
     Point diff = end - start;
     Point dirs = start.DirectionsTo(end) * new Point(-1, -1);
     Point next_vertical = start + new Point(0, dirs.Y);
     bool extra_moves_available = diff.X + diff.Y < moves_left;
     Tuple<bool, List<Point>> retval = FindShortestPath(next_vertical, end, start, moves_left - 1);
     if (!retval.Item1 && extra_moves_available)
     {
         return FindShortestPath_Backwards(start, end, last, moves_left);
     }
     else if (!retval.Item1)
     {
         return retval;
     }
     retval.Item2.Add(start);
     return retval;
 }
开发者ID:smartboyathome,项目名称:Haxxit,代码行数:18,代码来源:Path.cs


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