本文整理汇总了C#中Car.MoveLeft方法的典型用法代码示例。如果您正苦于以下问题:C# Car.MoveLeft方法的具体用法?C# Car.MoveLeft怎么用?C# Car.MoveLeft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car.MoveLeft方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TickAsync
/// <summary>
/// Takes one action (move the car one spot or pick up the passenger).
/// </summary>
/// <param name="car">The car to move</param>
/// <param name="passenger">The passenger to pick up</param>
private static async Task TickAsync(Car car, Passenger passenger)
{
var hasCarMoved = false;
DirectionToMove directionToMove = GetDirectionToMove(car, passenger);
switch (directionToMove)
{
case DirectionToMove.DoNothing:
break;
case DirectionToMove.Left:
car.MoveLeft(passenger);
hasCarMoved = true;
break;
case DirectionToMove.Right:
car.MoveRight(passenger);
hasCarMoved = true;
break;
case DirectionToMove.Up:
car.MoveUp(passenger);
hasCarMoved = true;
break;
case DirectionToMove.Down:
car.MoveDown(passenger);
hasCarMoved = true;
break;
case DirectionToMove.Arrived:
if (!car.HasPassenger)
{
passenger.GetInCar(car);
}
else
{
passenger.GetOutOfCar();
}
break;
default:
throw new ArgumentOutOfRangeException();
}
if (hasCarMoved)
{
Console.WriteLine("\tCar moved, downloading 2PointB Website");
var downloadedBytes = await Task.Run(() => Get2PointBWebsiteInBytesAsync());
}
}
示例2: Main
//.........这里部分代码省略.........
Console.WriteLine("Rules:");
Console.WriteLine();
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Help the froggie cross the busy road and navigate it to a calmer " +
"and safer place – the wonderful \nhome swamp, at the top of the " +
"screen! \nYou guide the frog using the following navigation keys: \"↑\"" +
" for up, \"↓\" - down, \"←\" - left, and \n\"→\" - right, and each "+
"pressing of the respective key of direction causes the frog to hop " +
"once in \nthat direction. \n\nThe game starts at the bottom of the " +
"screen. In general the screen is divided in two: the lower and the " +
"upper halves of it represent a heavy traffic road with various motor" +
" vehicles: cars, trucks, \nbuses, which move at different speeds. " +
"There are also tunnels and bridges, on which the frog can't \njump " +
"and must go around them. So your job is not an easy task! The froggie" +
" should pass through that traffic chaos in attempt to reach the upper" +
" part of the screen. In the middle of the play area is a \"Safe Zone\"" +
" – a place where the little frog can have some rest before continuing " +
"its dangerous \njourney. The frog has only three lives! If it gets hit" +
" by a vehicle, the frog remains with one life less. And when the " +
"froggie is run over by a vehicle three times – the game is over." +
"\n\nEnjoy the game!");
}
else if (choice.Key == ConsoleKey.D5 || choice.Key == ConsoleKey.Escape)
{
Environment.Exit(1);
}
else
{
Menu.DrawMenu();
}
}
while (true)
{
Console.Clear();
FrogFinishes.ConsoleFill(frogsAtTheTop1, frogsAtTheTop2, frogsAtTheTop3);
newFrog.Move();
newFrog.Draw();
// Bridges
firstBridge.FirstBridge();
firstBridge.DrawBridge(12, 59);
secondBridge.SecondBridge();
secondBridge.DrawBridge(36, 60);
// Right cars
firstRightCar.MoveRight(17);
firstRightCar.CheckCrash(newFrog, 42, 6);
firstRightCar.DrawCar(42);
secondRightCar.MoveRight(17);
secondRightCar.DrawCar(36);
secondRightCar.CheckCrash(newFrog, 36, 16);
thirdRightCar.DrawCar(30);
thirdRightCar.CheckCrash(newFrog, 30, 10);
thirdRightCar.MoveRight(28);
fourthRightCar.DrawCar(21);
fourthRightCar.CheckCrash(newFrog, 21, 10);
fourthRightCar.MoveRight(11);
fifthRightCar.DrawCar(15);
fifthRightCar.CheckCrash(newFrog, 15, 16);
fifthRightCar.MoveRight(30);
sixthRightCar.DrawCar(9);
sixthRightCar.CheckCrash(newFrog, 9, 6);
sixthRightCar.MoveRight(6);
//Tunnels
firstTunnel.FirstCarTunnel();
firstTunnel.DrawFirstTunnel(42, 12);
secondTunnel.SecondCarTunnel();
secondTunnel.DrawFirstTunnel(30, 19);
thirdTunnel.SecondCarTunnel();
thirdTunnel.DrawFirstTunnel(15, 19);
// Left cars
firstLeftCar.DrawCar(27);
firstLeftCar.CheckCrash(newFrog, 27, 16);
firstLeftCar.MoveLeft(17);
secondLeftCar.DrawCar(33);
secondLeftCar.MoveLeft(7);
secondLeftCar.CheckCrash(newFrog, 33, 6);
thirdLeftCar.DrawCar(39);
thirdLeftCar.MoveLeft(11);
thirdLeftCar.CheckCrash(newFrog, 39, 10);
fourthLeftCar.DrawCar(18);
fourthLeftCar.CheckCrash(newFrog, 18, 6);
fourthLeftCar.MoveLeft(7);
fifthLeftCar.DrawCar(12);
fifthLeftCar.CheckCrash(newFrog, 12, 10);
fifthLeftCar.MoveLeft(11);
sixthLeftCar.DrawCar(6);
sixthLeftCar.CheckCrash(newFrog, 6, 16);
sixthLeftCar.MoveLeft(17);
DrawStats(1, newFrog.LivesLeft, newFrog.Score);
FrogFinishes.FrogAtSafeZone(newFrog);
// Check if the frog reached the top and print a frog at the top
FrogFinishes.FrogAtTop(newFrog, ref startReach, frogSound, frogsAtTheTop1, frogsAtTheTop2, frogsAtTheTop3);
// Check if the frog has lost all lifes or won the game
FrogFinishes.WinOrLose(newFrog);
Thread.Sleep(newFrog.speed);
}
}