Beispiel #1
0
        static Animal[] genZoo()
        { //Создание массива животных
            Animal[] Zoo;
            Random   gen;

            gen = new Random();
            Zoo = new Animal[10];
            for (int i = 0; i < 10; i++)
            {
                //0 –Таракан, 1 – Кенгуру, 2 - Гепард
                int AnimalType = gen.Next(0, 3);
                switch (AnimalType)
                {
                case 0:     //Таракан
                    Zoo[i] = new Cockroach(gen.Next(0, 5), gen.Next(3, 8));
                    break;

                case 1:     //Кенгуру
                    Zoo[i] = new Kangaroo(gen.Next(0, 30), gen.Next(1, 5));
                    break;

                case 2:     //Гепард
                    Zoo[i] = new Chetar(gen.Next(0, 30),
                                        gen.Next(70, 120), gen.Next(3, 8));
                    break;
                }
            }
            return(Zoo);
        }
Beispiel #2
0
        static void Main()
        {
            do
            {
                Console.Clear();

                int n = InputVar <int>("size of array (1 - 100)", x => (x > 0) && (x <= 100));

                Animal[] animals = new Animal[n];
                for (int i = 0; i < n; ++i)
                {
                    int type = rnd.Next(3);
                    switch (type)
                    {
                    case 0:
                        animals[i] = new Cockroach((uint)rnd.Next(100), (uint)rnd.Next(100));
                        break;

                    case 1:
                        animals[i] = new Kangaroo((uint)rnd.Next(100), (uint)rnd.Next(100));
                        break;

                    case 2:
                        animals[i] = new Cheetah((uint)rnd.Next(100), (uint)rnd.Next(100), (uint)rnd.Next(100));
                        break;
                    }
                }

                Console.WriteLine("Animals:");
                for (int i = 0; i < n; ++i)
                {
                    Console.WriteLine("\t" + animals[i]);
                }


                Console.WriteLine("Press Esc to exit. Press any other key to continue.");
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
        }