本文整理汇总了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>());
}
示例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;
}