示例#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);
        }
示例#3
0
        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);
        }