C# Christmas Tree

Bug

Through thorns to stars
Администратор
Bug

Bug

Through thorns to stars
Администратор
Сообщения
1,451
Реакции
2,824


C#:
using System;

namespace ChristmasTree
{
    internal class Program
    {
        static Random rnd = new Random(DateTime.Now.Second);
        private static string[] toys = { "$", "*", "%" };
        static void Main(string[] args)
        {
            PaintChristmasTree(50, "Happy New Year 2022!!!");
            Console.ReadKey();
        }

        static void PaintChristmasTree(int height, string message)
        {
            for (int i = 0; i < height; i++)
            {
                for (int n = 0; n < height -i; n++)
                    Console.Write(" ");

                for (int j = 0; j < 2 * i + 1; j++)
                {
                    switch (rnd.Next(height + height / 2) < height)
                    {
                        case true:
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.Write("1");
                            break;
                        case false:
                            int color = rnd.Next(4);
                            switch (color)
                            {
                                case 1:
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    break;
                                case 2:
                                    Console.ForegroundColor = ConsoleColor.Yellow;
                                    break;
                                case 3:
                                    Console.ForegroundColor = ConsoleColor.Cyan;
                                    break;
                            }
                            Console.Write(GetToy());
                            break;
                    }
                }

                Console.WriteLine();
            }

            Console.WriteLine();
            for (int j = 0; j < height*2 / 2 - message.Length / 2; j++)
                Console.Write(" ");

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(message);
        }

        static string GetToy()
        {
            return toys[rnd.Next(toys.Length)];
        }
    }
}
 

Сверху Снизу