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); }
public Program() { wndWidth = 50; wndHeight = 40; score = 0; deltaSpeed = 12; Console.SetWindowSize(wndWidth, wndHeight); Console.SetBufferSize(wndWidth, wndHeight); Console.OutputEncoding = Encoding.UTF8; Console.CursorVisible = false; road = new Road(); road.leftSide = 2; controledCar = new ControlledCar(); oncomingCar = new OncomingCar(); controledCar.setLeft(road.rightSide - controledCar.getWidth()); controledCar.setTop(Console.WindowHeight - controledCar.getLength() - 1); }