private static Point MostrarComida(Size screenSize, ColaLineal culebra) { var lugarComida = Point.Empty; var cabezaCulebra = (Point)culebra.frenteCola(); var rnd = new Random(); Point point = (Point)culebra.finalCola(); do { var x = rnd.Next(0, screenSize.Width - 1); var y = rnd.Next(0, screenSize.Height - 1); if ((point.X != x || point.Y != y) && Math.Abs(x - cabezaCulebra.X) + Math.Abs(y - cabezaCulebra.Y) > 8) { lugarComida = new Point(x, y); } } while (lugarComida == Point.Empty); Console.BackgroundColor = ConsoleColor.Red; Console.SetCursorPosition(lugarComida.X + 1, lugarComida.Y + 1); Console.Write(" "); return(lugarComida); }
private static bool MoverLaCulebrita(ColaLineal culebra, Point posiciónObjetivo, int longitudCulebra, Size screenSize) { try { var lastPoint = (Point)culebra.finalCola(); if (lastPoint.Equals(posiciónObjetivo)) { return(true); } if (culebra.Equals(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.DarkMagenta; Console.SetCursorPosition(lastPoint.X + 1, lastPoint.Y + 1); Console.WriteLine(" "); culebra.insertar(posiciónObjetivo); Console.BackgroundColor = ConsoleColor.DarkGray; Console.SetCursorPosition(posiciónObjetivo.X + 1, posiciónObjetivo.Y + 1); Console.Write(":"); // Quitar cola if (culebra.el() > (longitudCulebra)) { var removePoint = (Point)culebra.quitar(); Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition(removePoint.X + 1, removePoint.Y + 1); Console.Write(" "); } return(true); } catch (Exception e) { Console.WriteLine("Error=" + e.Message); return(false); } }