Example #1
0
        private static bool MoverLaCulebritaColaLineal(ColaLineal culebra, Point posiciónObjetivo,
                                                       int longitudCulebra, Size screenSize)
        {
            var lastPoint = (Point)culebra.finalCola();
            int pausa     = 0;

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

            if (culebra.ToString().Any(x => x.Equals(posiciónObjetivo)))
            {
                return(false);
            }
            //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);
            int pausa1 = 0;

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

            // Quitar cola
            if (culebra.tamaño() > longitudCulebra)
            {
                var removePoint = (Point)culebra.quitar();
                Console.BackgroundColor = ConsoleColor.Black;
                Console.SetCursorPosition(removePoint.X + 1, removePoint.Y + 1);
                Console.Write(" ");
            }
            return(true);
        }
        private bool MoverLaCulebrita(ColaLineal culebra, Point posiciónObjetivo,
                                      int longitudCulebra, Size screenSize)
        {
            var lastPoint = (Point)culebra.finalCola();

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

            if (culebra.choque(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.numdeelementos() > longitudCulebra)
            {
                var removePoint = (Point)culebra.quitar();
                Console.BackgroundColor = ConsoleColor.Black;
                Console.SetCursorPosition(removePoint.X + 1, removePoint.Y + 1);
                Console.Write(" ");
            }
            return(true);
        }