示例#1
0
        private static Point MostrarComida(Size screenSize, ColaConLista culebra)
        {
            var lugarComida   = Point.Empty;
            var cabezaCulebra = (Point)culebra.finalCola();
            var rnd           = new Random();

            var Px = cabezaCulebra.X;
            var Py = cabezaCulebra.Y;

            {
                var x = rnd.Next(0, screenSize.Width - 1);
                var y = rnd.Next(0, screenSize.Height - 1);
                if (culebra.ToString().Any(p => Px != x || Py != y) &&
                    Math.Abs(x - cabezaCulebra.X) + Math.Abs(y - cabezaCulebra.Y) > 8)
                {
                    lugarComida = new Point(x, y);
                    Console.Beep(659, 125);
                }
            } while (lugarComida == Point.Empty)
            {
                ;
            }

            Console.BackgroundColor = ConsoleColor.Blue;
            Console.SetCursorPosition(lugarComida.X + 1, lugarComida.Y + 1);
            Console.Write(" ");

            return(lugarComida);
        }
示例#2
0
        private bool MoverLaCulebrita(ColaConLista culebra, Point posiciónObjetivo,
                                      int longitudCulebra, Size screenSize)
        {
            var lastPoint = (Point)culebra.finalCola();//sustituir

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

            if (culebra.choque((posiciónObjetivo)))
            {
                return(false);                                   //sustituir
            }
            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);//sustituir

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

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