예제 #1
0
        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);
        }
예제 #2
0
        private bool moveDownOncomingCar(ref OncomingCar oncomingCar)
        {
            //на край дороги выезжать не будем, поэтому leftSide + 1
            int col = new Random().Next(road.leftSide + 1, road.rightSide - oncomingCar.getWidth() + 1);

            oncomingCar.setLeftTop(col, 0 - controledCar.getLength()); //машинка за верхнем краем окна.

            for (; oncomingCar.getTop() < wndHeight;)
            {
                oncomingCar.moveDown();

                if (isCrush(ref oncomingCar, ref controledCar))
                {
                    return(false);
                }
            }

            Debug.WriteLine("moveDownOncomingCar() - loop is finished.");
            return(true);
        }