Пример #1
0
        private static bool MoverLaCulebrita(BiCola culebra, Point posiciónObjetivo,
                                             int longitudCulebra, Size screenSize)

        {
            //Casteamos el metodo finalBicola con Point para Establecer las coordenadas
            //En lugar de .Last usamos el metodo finalBicola
            var lastPoint = (Point)culebra.finalBicola();

            if (lastPoint.Equals(posiciónObjetivo))
            {
                return(true);                                   //Comparamos los valores
            }
            if (culebra.Any(posiciónObjetivo))
            {
                return(false);
            }


            if (posiciónObjetivo.X < 0 || posiciónObjetivo.X >= screenSize.Width ||
                posiciónObjetivo.Y < 0 || posiciónObjetivo.Y >= screenSize.Height)
            {
                return(false);
            }

            Console.BackgroundColor = ConsoleColor.Green;                //Color del cuerpo de la culebra
            Console.SetCursorPosition(lastPoint.X + 1, lastPoint.Y + 1); //Movemos el cursor a estas coordenadas de la pantalla
            Console.WriteLine(" ");

            //Usamos el metodo de insertar en lugar de Enqueue
            culebra.insertar(posiciónObjetivo);

            Console.BackgroundColor = ConsoleColor.Red;                                //Color de la cabecita
            Console.SetCursorPosition(posiciónObjetivo.X + 1, posiciónObjetivo.Y + 1); //Movemos el cursor a estas coordenadas de la pantalla
            Console.Write(" ");

            // Quitar cola
            //Usamos el metodo de numElementosBicola de la clase Bicola en lugar de Count
            if (culebra.numElementosBicola() > longitudCulebra)
            {
                //Usamos el metodo de quitar de la clase Bicola en Lugar de Dequeue
                var removePoint = (Point)culebra.quitar();
                Console.BackgroundColor = ConsoleColor.Black;                    //Color del recorrido de la culebra
                Console.SetCursorPosition(removePoint.X + 1, removePoint.Y + 1); //Movemos el cursor a estas coordenadas de la pantalla
                Console.Write(" ");
            }
            return(true);
        }
Пример #2
0
        private static bool MoverLaCulebrita(BiCola culebra, Point posiciónObjetivo,
                                             int longitudCulebra, Size screenSize)

        {
            var lastPoint = (Point)culebra.finalBicola();

            if (lastPoint.Equals(posiciónObjetivo))
            {
                return(true);
            }

            if (culebra.Any(posiciónObjetivo))
            {
                return(false);
            }


            if (posiciónObjetivo.X < 0 || posiciónObjetivo.X >= screenSize.Width ||
                posiciónObjetivo.Y < 0 || posiciónObjetivo.Y >= screenSize.Height)
            {
                return(false);
            }

            Console.BackgroundColor = ConsoleColor.Green;
            Console.SetCursorPosition(lastPoint.X + 1, lastPoint.Y + 1);
            Console.WriteLine(" ");

            culebra.insertar(posiciónObjetivo);

            Console.BackgroundColor = ConsoleColor.Red;
            Console.SetCursorPosition(posiciónObjetivo.X + 1, posiciónObjetivo.Y + 1);
            Console.Write(" ");

            // Quitar cola
            if (culebra.numElementosBicola() > longitudCulebra)
            {
                var removePoint = (Point)culebra.quitar();
                Console.BackgroundColor = ConsoleColor.Black;
                Console.SetCursorPosition(removePoint.X + 1, removePoint.Y + 1);
                Console.Write(" ");
            }
            return(true);
        }