本文整理匯總了C#中System.Point.Walk方法的典型用法代碼示例。如果您正苦於以下問題:C# Point.Walk方法的具體用法?C# Point.Walk怎麽用?C# Point.Walk使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Point
的用法示例。
在下文中一共展示了Point.Walk方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Solve_Part1
internal static void Solve_Part1()
{
Console.WriteLine("Solving Day 01, Part 1...");
var directions = System.IO.File.ReadAllText("01.txt").Split(',');
var pt = new Point();
foreach (var direction in directions)
{
if (string.IsNullOrWhiteSpace(direction))
continue;
pt.Walk(
direction.Trim().Substring(0, 1),
int.Parse(direction.Trim().Substring(1)),
false);
}
Console.WriteLine($"You are at {pt}; which is {Math.Abs(pt.X) + Math.Abs(pt.Y)} blocks away...");
// correct:
// 279
return;
}
示例2: Solve_Part2
internal static void Solve_Part2()
{
Console.WriteLine("Solving Day 01, Part 2...");
var directions = System.IO.File.ReadAllText("01.txt").Split(',');
var pt = new Point();
var hist = new List<string>();
foreach (var direction in directions)
{
if (string.IsNullOrWhiteSpace(direction))
continue;
var beenThere = pt.Walk(
direction.Trim().Substring(0, 1),
int.Parse(direction.Trim().Substring(1)),
true);
if (beenThere)
break;
}
// wrong:
// 297 (high)
// correct:
// 163
return;
}