コード例 #1
0
        static void Main(string[] args)
        {
            GraphObject[] array = new GraphObject[20];
            Random        rnd   = new Random();

            for (int i = 0; i < array.Length; i++)
            {
                int obj   = rnd.Next(0, 3);
                int color = rnd.Next(0, 3);
                switch (obj)
                {
                case 0: array[i] = new Point(); break;

                case 1: array[i] = new Rectangle(rnd.Next(2, 8), rnd.Next(2, 8)); break;

                case 2: array[i] = new Square(rnd.Next(2, 8)); break;
                }
                switch (color)
                {
                case 0: array[i].Color = ConsoleColor.Red; break;

                case 1: array[i].Color = ConsoleColor.Green; break;

                case 2: array[i].Color = ConsoleColor.Blue; break;
                }
            }
            foreach (GraphObject g in array)
            {
                g.DrawInConsole();
            }
            Console.ReadKey();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            GraphObject[] array = new GraphObject[20];
            Random rnd = new Random();
            for (int i = 0; i < array.Length; i++)
            {
                int obj = rnd.Next(0, 3);
                int color = rnd.Next(0, 3);
                switch (obj)
                {
                    case 0: array[i] = new Point(); break;
                    case 1: array[i] = new Rectangle(rnd.Next(2, 8), rnd.Next(2, 8)); break;
                    case 2: array[i] = new Square(rnd.Next(2, 8)); break;
                }
                switch (color)
                {
                    case 0: array[i].Color = ConsoleColor.Red; break;

                    case 1: array[i].Color = ConsoleColor.Green; break;

                    case 2: array[i].Color = ConsoleColor.Blue; break;
                }
            }
            foreach (GraphObject g in array)
            {
                g.DrawInConsole();
            }
            Console.ReadKey();
        }