Exemplo n.º 1
0
        //Queue<Point>
        private static Point MostrarComida(Size screenSize, BiCola culebra)
        {
            var lugarComida = Point.Empty;

            var cabezaCulebra = (Point)culebra.finalBicola();
            var coor          = cabezaCulebra.X;

            var rnd = new Random();

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

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

            return(lugarComida);
        }
Exemplo n.º 2
0
        //Queue>Point
        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.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.Blue;
            Console.SetCursorPosition(lastPoint.X + 1, lastPoint.Y + 1);
            Console.WriteLine(" ");

            culebra.Insertar(posiciónObjetivo);

            Console.BackgroundColor = ConsoleColor.White;
            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);
        }