Exemple #1
0
        private void CreateFood()
        {
            var rnd = new Random();

            while (true)
            {
                int foodX = rnd.Next(MapSize);
                int foodY = rnd.Next(MapSize);
                try
                {
                    if (Snake.All(s => s.X != foodX && s.Y != foodY))
                    {
                        Food = new Coords(foodX, foodY);
                        Console.SetCursorPosition(foodX, foodY);
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Write('$');
                        Console.ResetColor();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    File.AppendAllText("Log.txt", ex.ToString());
                }
            }
            WriteScore();
        }