本文整理匯總了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;
}