private bool isCrush(ref OncomingCar oncomCar, ref ControlledCar controlCar) { int onCarLeft = oncomCar.getLeft(); int onCarTop = oncomCar.getTop(); int contCarLeft = controlCar.getLeft(); int contCarTop = controlCar.getTop(); int leftDifference = onCarLeft - contCarLeft; if (leftDifference < 0) { leftDifference = -(leftDifference); } int topDifference = onCarTop - contCarTop; if (topDifference < 0) { topDifference = -(topDifference); } int carWidth = controlCar.getWidth(); int carLength = controlCar.getLength(); if (leftDifference < carWidth && topDifference <= carLength) { Debug.WriteLine("Cars were crushed"); road.setFinish(); return(true); } return(false); }
private void controlledCarRoutine() { ConsoleKeyInfo key = new ConsoleKeyInfo(); int carLeft, carTop, bottomLimit, leftLimit, rightLimit; while (!Console.KeyAvailable && key.Key != ConsoleKey.Escape) { key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.UpArrow: //Console.WriteLine("UpArrow was pressed"); carTop = controledCar.getTop(); if (--carTop <= 0) { carTop = 0; } controledCar.setTop(carTop); controledCar.wipeBehind(); break; case ConsoleKey.DownArrow: //Console.WriteLine("DownArrow was pressed"); bottomLimit = wndHeight - controledCar.getLength() - 1; carTop = controledCar.getTop(); if (++carTop >= bottomLimit) { carTop = bottomLimit; } controledCar.setTop(carTop); controledCar.wipeBefore(); break; case ConsoleKey.LeftArrow: //Console.WriteLine("LeftArrow was pressed"); leftLimit = road.leftSide + 1; carLeft = controledCar.getLeft(); if (--carLeft <= leftLimit) { carLeft = leftLimit; } controledCar.setLeft(carLeft); controledCar.wipeRight(); break; case ConsoleKey.RightArrow: //Console.WriteLine("RightArrow was pressed"); rightLimit = road.rightSide - controledCar.getWidth(); carLeft = controledCar.getLeft(); if (++carLeft >= rightLimit) { carLeft = rightLimit; } controledCar.setLeft(carLeft); controledCar.wipeLeft(); break; case ConsoleKey.Escape: break; } controledCar.draw(); } }