コード例 #1
0
        private void BTClone_Click(object sender, EventArgs e)
        {
            int    weight;
            string name;

            TBOutput.Clear();
            foreach (IAnimal animal in Part3.animals)
            {
                TBOutput.Text += "Клон ";
                object newAnimal = animal.Clone();

                if (newAnimal is Animal)
                {
                    Animal animal_ = animal as Animal;
                    weight = animal_.Weight;
                    name   = animal_.Name;

                    ShowInfo(weight, name);
                }
                if (newAnimal is Bird)
                {
                    Bird bird = newAnimal as Bird;

                    weight = bird.Weight;
                    name   = bird.Name;
                    bool flying   = bird.Flying;
                    bool domestic = bird.Domestic;

                    ShowInfo(weight, name, flying, domestic);
                    continue;
                }
                if (newAnimal is Mammal)
                {
                    Mammal mammal = newAnimal as Mammal;

                    weight = mammal.Weight;
                    name   = mammal.Name;
                    int incubationPeriod = mammal.IncubationPeriod;
                    int lifeExpectancy   = mammal.LifeExpectancy;

                    ShowInfo(weight, name, incubationPeriod, lifeExpectancy);
                    continue;
                }
                if (newAnimal is Artiodactyl)
                {
                    Artiodactyl artiodactyl = newAnimal as Artiodactyl;

                    weight = artiodactyl.Weight;
                    name   = artiodactyl.Name;
                    int    incubationPeriod = artiodactyl.IncubationPeriod;
                    int    lifeExpectancy   = artiodactyl.LifeExpectancy;
                    bool   hasHorns         = artiodactyl.HasHorns;
                    string habitat          = artiodactyl.Habitat;

                    ShowInfo(weight, name, incubationPeriod, lifeExpectancy, hasHorns, habitat);
                    continue;
                }
            }
        }
コード例 #2
0
        private void кПарнокопытнымToolStripMenuItem_Click(object sender, EventArgs e)
        {
            birds = null;
            Artiodactyl form = new Artiodactyl();

            form.ShowDialog();
            Close();
        }
コード例 #3
0
        private void InsertArtiodactylToArray(string name, int weight, int incubationPeriod, int lifeExpectancy, bool hasHorns, string habitat)
        {
            Artiodactyl artiodactyl = new Artiodactyl(weight, name, incubationPeriod, lifeExpectancy, hasHorns, habitat);

            animals[i] = artiodactyl;

            if (i + 1 == size)
            {
                string content = "Массив заполнен";
                string header  = "info";
                MessageBox.Show(content, header, MessageBoxButtons.OK, MessageBoxIcon.Information);
                DisableButtons();
            }
            i++;
        }
コード例 #4
0
        private void Identify(IAnimal animal)
        {
            int    weight = animal.Weight;
            string name   = animal.Name;

            if (animal is Animal)
            {
                ShowInfo(weight, name);
                return;
            }
            if (animal is Mammal)
            {
                Mammal mammal           = animal as Mammal;
                int    incubationPeriod = mammal.IncubationPeriod;
                int    lifeExpectancy   = mammal.LifeExpectancy;

                ShowInfo(weight, name, incubationPeriod, lifeExpectancy);
                return;
            }
            if (animal is Artiodactyl)
            {
                Artiodactyl artiodactyl = animal as Artiodactyl;

                int    incubationPeriod = artiodactyl.IncubationPeriod;
                int    lifeExpectancy   = artiodactyl.LifeExpectancy;
                bool   hasHorns         = artiodactyl.HasHorns;
                string habitat          = artiodactyl.Habitat;

                ShowInfo(weight, name, incubationPeriod, lifeExpectancy, hasHorns, habitat);
                return;
            }
            if (animal is Bird)
            {
                Bird bird = animal as Bird;

                bool flying   = bird.Flying;
                bool domestic = bird.Domestic;

                ShowInfo(weight, name, flying, domestic);
                return;
            }
        }