Ejemplo n.º 1
0
        /// <summary>
        /// Constructor - Initializes the animalManager, animalFactory and the mappings. Also resets the displayed controls.
        /// </summary>
        public Form1()
        {
            InitializeComponent();
            animalManager = new AnimalManager();
            animalFactory = new AnimalFactory();


            AddCategoryItems();
            AddGenderItems();

            speciesMapping = new Dictionary <Categorys, Species[]>   //Creates a mapping of how the species are related to the categorys, for use in dropdown lists
            {
                { Categorys.Insect, new Species[] { Species.Ant, Species.Butterfly } },
                { Categorys.Mamal, new Species[] { Species.Dog, Species.Monkey } },
            };

            categoryControlsMapping = new Dictionary <Categorys, Control[]>  //Maps controls to the Categorys
            {
                { Categorys.Insect, new Control[] { Category_noLegs_label, Category_noLegs_input, Categoty_canFly_label, Category_canFly_input } },
                { Categorys.Mamal, new Control[] { Category_noteeth_label, Category_noteeth_input, Category_furColor_label, Category_furColor_input } }
            };
            speciesControlsMapping = new Dictionary <Species, Control[]>     //Maps controls to the Species
            {
                { Species.Ant, new Control[] { Species_isQueen_label, Species_isQueen_input } },
                { Species.Butterfly, new Control[] { Species_wingColor_label, Species_wingColor_input } },
                { Species.Dog, new Control[] { Species_breed_label, Species_breed_input } },
                { Species.Monkey, new Control[] { Species_tailLength_label, Species_tailLength_input } },
            };

            ChangeCategoryView(null);     //Resets the category to not show be shown or selected
            ChangeSpeciesView(null);      //Resets the species to not show be shown or selected
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Tries to create an animal from user inputed data.
        /// </summary>
        /// <param name="form">UI with all input-data needed to create the animal</param>
        /// <param name="loadedImage">The image picked from the folder</param>
        /// <param name="animalManager">The manager where the animal will be stored</param>
        /// <param name="selectedCategory">The category of animals chosen. Used together with <paramref name="selectedSpecies"/> to determine which animal to create</param>
        /// <param name="selectedSpecies">The species of animals chosen. Used together with <paramref name="selectedCategory"/> to determine which animal to create</param>
        public void CreateAnimal(Form1 form, Image loadedImage, AnimalManager animalManager, Categorys selectedCategory, Species selectedSpecies)
        {
            Animal animal = null;

            string  name   = form.Animal_name_input.Text;
            int     age    = Int32.Parse(form.Animal_age_input.Text);
            Genders gender = (Genders)form.Animal_gender_input.SelectedIndex;


            if (selectedCategory == Categorys.Insect)
            {
                int  numberOfLegs = Int32.Parse(form.Category_noLegs_input.Text);
                bool canFly       = form.Category_canFly_input.Checked;


                switch (selectedSpecies)
                {
                case Species.Ant:
                {
                    bool isQueen = form.Species_isQueen_input.Checked;

                    animal = new Ant(name, age, gender, loadedImage, numberOfLegs, canFly, isQueen);             //Creates an ant
                }
                break;

                case Species.Butterfly:
                {
                    Color mainWingColor = form.Species_wingColor_input.BackColor;

                    animal = new Butterfly(name, age, gender, loadedImage, numberOfLegs, canFly, mainWingColor);            //Creates a butterfly
                }
                break;
                }
            }
            else if (selectedCategory == Categorys.Mamal)
            {
                int   numberOfTeeth = Int32.Parse(form.Category_noteeth_input.Text);
                Color furColor      = form.Category_furColor_input.BackColor;


                switch (selectedSpecies)
                {
                case Species.Dog:
                {
                    string breed = form.Species_breed_input.Text;

                    animal = new Dog(name, age, gender, loadedImage, numberOfTeeth, furColor, breed);           //Creates a dog
                }
                break;

                case Species.Monkey:
                {
                    int tailLength = Int32.Parse(form.Species_tailLength_input.Text);

                    animal = new Monkey(name, age, gender, loadedImage, numberOfTeeth, furColor, tailLength);             //Creates a monkey
                }
                break;
                }
            }

            animalManager.AddAnimal(animal);
        }