public List <Animal> Get()
    {
        List <Animal> animals = new AnimalList();

        animals.Add(new FlyingAnimal());
        animals.Add(new SwimmingAnimal());
        return(animals);
    }
        Animal(AnimalType type, string name, User user, int petRate = 5, int hungryRate = 5)
        {
            Guard.Against.Null(type, nameof(type));
            Guard.Against.NullOrEmpty(name, nameof(type));
            Guard.Against.Null(user, nameof(user));

            Guard.Against.OutOfRange(petRate, nameof(petRate), 1, 10);
            Guard.Against.OutOfRange(hungryRate, nameof(hungryRate), 1, 10);

            Id         = Guid.NewGuid();
            Name       = name;
            AnimalType = type;
            CreatedAt  = DateTimeOffset.Now;
            LastFed    = DateTimeOffset.Now;
            LastPetted = DateTimeOffset.Now;
            HungryRate = hungryRate;
            PetRate    = petRate;
            User       = user;

            _currentHappiness   = 50;
            _previousHungriness = 50;

            AnimalList.Add(this);

            user.AddAnimalToUser(this);
        }
Esempio n. 3
0
 public void Breed()
 {
     if (FreePlaces > 0)
     {
         AnimalList.Add(new Animals());
         FreePlaces--;
     }
 }
Esempio n. 4
0
 public int Breed()
 {
     if (FreePlaces > 0)
     {
         AnimalList.Add(new Animal());
         FreePlaces--;
     }
     return(AnimalList.Count);
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            AnimalList <Animal> list = new AnimalList <Animal>();

            list.Add(new Cat("Fluffy")
            {
                NumberOfLegs = 4
            });
            list.Add(new Dog("Ruffles")
            {
                NumberOfLegs = 3, BirthDate = DateTime.Now - TimeSpan.FromDays(942)
            });

            //BinarySerialization(list);

            //DataContractSerialization(list);

            //DataContractJsonSerialization(list);

            //NewtonsoftJsonSerialization(list);
        }
        public bool AddAnimalToWagon(Animal animal)
        {
            if (CheckWagonCapacity(animal) && AddHerbivore(animal) && SafeToAddCarnivore(animal) &&
                CheckCarnivoreSize(animal))
            {
                AnimalList.Add(animal);
                Capacity += (int)animal.Size;
                return(true);
            }

            return(false);
        }
        public static void AddAnimal(object species, string name, object gender, int age, decimal weight, bool reserved, decimal price)
        {
            switch ((Species)species)
            {
            case Species.Cat:
                AnimalList.Add(new Cat((Species)species, name, age, (Gender)gender, weight, price, reserved, false));
                break;

            case Species.Dog:
                AnimalList.Add(new Dog((Species)species, name, age, (Gender)gender, weight, price, reserved, false));
                break;
            }
        }
        //Methods

        /// <summary>
        /// LoadSampleData- Loads sample data for debug purposes.
        /// </summary>
        private void LoadSampleData()
        {
            AnimalList.Add(new AnimalRecord
            {
                Name        = "Ben",
                AnimalType  = "Cat",
                Price       = 20.00,
                Id          = 1,
                Description = "asdfsldfsdjflsjdlfjsdjflsjdflsjdlfjsdlf",
                Picture     = $"/Images/ShellViewBackgroundImage.png"
            });

            AnimalList.Add(new AnimalRecord
            {
                Name        = "Jinn",
                AnimalType  = "Dog",
                Price       = 25.00,
                Id          = 2,
                Description = "bsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfdf"
            });
        }
        /// <summary>
        /// LoadDBData- Loads in the data from the database and table given in the login
        /// </summary>
        private void LoadDBData()
        {
            List <string>[] results = Connection.SelectAll();

            double price;
            int    id;

            for (int i = 0; i < results[3].Count; i++) //for the number of entries with listed id which is Pkey.
            {
                double.TryParse(results[2][i], out price);
                int.TryParse(results[3][i], out id);

                AnimalList.Add(new AnimalRecord
                {
                    Name        = results[0][i],
                    AnimalType  = results[1][i],
                    Price       = price,
                    Id          = id,
                    Description = results[4][i],
                    Picture     = results[5][i]
                });
            }
        }
Esempio n. 10
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                AnimalList animals       = new AnimalList();
                string[]   animalStrings = (value as string).Split(new char[] { '#', '$' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string animalString in animalStrings)
                {
                    string[]   animalInfo = animalString.Split(':');
                    AnimalInfo animal     = new AnimalInfo();
                    animal.Name   = animalInfo[0];
                    animal.Number = Int32.Parse(animalInfo[1]);
                    animals.Add(animal);
                }

                return(animals);
            }
            else
            {
                throw new ArgumentException("In ConvertFrom: can not convert to List<AnimalInfo>.");
            }
        }
Esempio n. 11
0
 public void add(Animal newone)
 {
     AnimalList.Add(newone);
     Grid.add(newone);
 }
Esempio n. 12
0
        private void btn_addAnimal_Click(object sender, EventArgs e)
        {
            bool errorCreated = false;
            // create new ErrorProvider
            ErrorProvider errorProvider = new ErrorProvider();

            // create new Animal and pass the input Values
            Animal animal = new Animal(

                txt_name.Text,
                Convert.ToDouble(num_size.Value),
                Convert.ToInt32(cbox_foodtype.SelectedItem),
                chbox_isSick.Checked,
                txt_species.Text,
                Convert.ToInt32(num_age.Value),
                Convert.ToDouble(num_foodAmount.Value)

                );

            // checking if all textboxes are filled
            foreach (TextBox control in Controls.OfType <TextBox>())
            {
                if (control.Text == "")
                {
                    errorProvider.SetError(control, "No Text given");
                    errorCreated = true;
                }
            }
            // checking if all numericupdowns are filled
            foreach (NumericUpDown num in Controls.OfType <NumericUpDown>())
            {
                if (num.Value == Convert.ToDecimal(num.Tag))
                {
                    errorProvider.SetError(num, "No Value given");
                    errorCreated = true;
                }
            }
            // Checking if all comboboxes are filled
            foreach (ComboBox item in Controls.OfType <ComboBox>())
            {
                if (item.SelectedItem == null)
                {
                    errorProvider.SetError(item, "No Value given");
                    errorCreated = true;
                }
            }

            // detecting if animal is in the AnimalList
            if (AnimalList.Contains(animal))
            {
                MessageBox.Show("Animal with name: " + animal.Name + " is already existing", "Animal exists", MessageBoxButtons.OK);
            }
            else
            {
                if (errorCreated == false)
                {
                    AnimalList.Add(animal);
                    Close();
                }
            }
        }