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();
            AddSortingMethods();

            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
        private AnimalManager manager = null; // MainGUI "har en" AnimalManager
        /// <summary>
        /// Default konstruktor som instansierar ett objekt av AnimalManager samt fyller i alla nödvändiga värden
        /// </summary>
        public MainGUI()
        {
            InitializeComponent();

            manager = new AnimalManager(); // Instansiera AnimalManagern

            InitializeGUI(); // Börjar med att fylla i alla nödvändiga värden
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a random animal with random properties
        /// </summary>
        /// <param name="animalManager"></param>
        public void CreateRandomAnimal(AnimalManager animalManager)
        {
            Animal animal = null;

            string  name   = RandomString(3, 8, true);
            int     age    = random.Next(0, 99);
            Genders gender = RandomEnum <Genders>();

            Categorys category = RandomEnum <Categorys>();
            Species   species  = RandomEnum <Species>(category);

            Console.WriteLine(category);
            Console.WriteLine(species);

            switch (category)
            {
            case Categorys.Insect:
            {
                int  numberOfLegs = random.Next(2, 8);
                bool canFly       = Convert.ToBoolean(random.Next(0, 2));

                switch (species)
                {
                case Species.Ant:
                {
                    bool isQueen = Convert.ToBoolean(random.Next(0, 2));

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

                case Species.Butterfly:
                {
                    Color mainWingColor = RandomColor();

                    animal = new Butterfly(name, age, gender, null, numberOfLegs, canFly, mainWingColor);                    //Creates a butterfly
                }
                break;
                }
            }
            break;

            case Categorys.Mamal:
            {
                int   numberOfTeeth = random.Next(0, 30);
                Color furColor      = RandomColor();

                switch (species)
                {
                case Species.Dog:
                {
                    string breed = RandomString(4, 12, true);

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

                case Species.Monkey:
                {
                    int tailLength = random.Next(0, 200);

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

            animalManager.AddAnimal(animal);
        }
Ejemplo n.º 4
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);
        }