Example #1
0
        public Ration(Food food, ListOfAnimals animalFor)
        {
            Food = food;

            Id          = Guid.NewGuid();
            ListAnimals = animalFor;
        }
Example #2
0
        private void ReadAnimalsFromFile()
        {
            using (StreamReader reader = new StreamReader(@"C:\Users\Haunschmied.Bastian\source\repos\Nahrungsverwaltung\Files\Animals.csv"))
            {
                var    i    = 0;
                string line = "";
                while ((line = reader.ReadLine()) != null)
                {
                    if (i == 0)
                    {
                        i++;
                    }
                    else
                    {
                        string[] cutString = line.Split(',');
                        Animal   animal    = new Animal(

                            cutString[0],
                            Convert.ToDouble(cutString[1]),
                            Convert.ToInt32(cutString[2]),
                            Convert.ToBoolean(cutString[3]),
                            cutString[4],
                            Convert.ToInt32(cutString[5]),
                            Convert.ToDouble(cutString[6])
                            );

                        ListOfAnimals.Add(animal);
                    }
                }
            }
            UpdateControls();
        }
        public override void ToScreen()
        {
            Console.WriteLine(Description);

            if (!ListOfAnimals.Contains(GameSession.pig))
            {
                foreach (var item in ListOfItems)
                {
                    if (item == GameSession.bucket)
                    {
                        Console.WriteLine("Bredvid brunnen står det en [hink].");
                    }
                    else
                    {
                        if (item != GameSession.theWell)
                        {
                            Console.WriteLine(item.Name + ": " + item.Description);
                        }
                    }
                }
            }
            else if (ListOfAnimals.Contains(GameSession.pig))
            {
                GameSession.pig.ToScreen();
            }
        }
Example #4
0
 public T GetByName(string name)
 {
     return
         (ListOfAnimals.FirstOrDefault(
              h => string.Compare(h.Name, name,
                                  StringComparison.InvariantCultureIgnoreCase) == 0));
 }
    // usage examples.
    private static void Main(string[] args)
    {
        var donkeyInstance = new Donkey();
        var lizardInstance = new Lizard();
        var snakeInstance  = new Snake();

        var tableInstance           = new Table();
        var deskInstance            = new Desk();
        var conferenceTalbeInstance = new ConferenceTable();

        var listOfThingsWithLegs = new ListOfIhasLegs
        {
            donkeyInstance,
            lizardInstance,
            tableInstance,
            deskInstance,
            conferenceTalbeInstance
        };

        var listOfAnimals = new ListOfAnimals
        {
            donkeyInstance,
            lizardInstance,
            snakeInstance
        };

        var cageOfAnimalsWithLegs = new ListOfAnimalsWithLegs
        {
            donkeyInstance,
            lizardInstance,
        };
    }
Example #6
0
 public Food(string name, int weight, ListOfAnimals aviaryFor)
 {
     if (String.IsNullOrEmpty(name) || weight == 0)
     {
         throw new ArgumentNullException();
     }
     Name        = name;
     Weight      = weight;
     ListAnimals = aviaryFor;
 }
Example #7
0
        public Aviary(int number, ListOfAnimals animal)
        {
            Number      = number;
            ListAnimals = animal;
            Id          = Guid.NewGuid();

            //  if (id is  )
            //  {
            //      throw new ArgumentNullException();
            //  }
        }
Example #8
0
            public T Remove(T animal)
            {
                var element = ListOfAnimals.FirstOrDefault(h => h == animal);

                if (element != null)
                {
                    ListOfAnimals.Remove(element);
                    return(element);
                }
                throw new NullReferenceException("В экземпляре объекта не задана ссылка на объект!");
            }
Example #9
0
        public void SlaughterAnimal()
        {
            Animal target = null;

            foreach (var animal in ListOfAnimals)
            {
                if (target == null || animal.Hunger < target.Hunger)
                {
                    target = animal;
                }
            }
            ListOfAnimals.Remove(target);
        }
Example #10
0
 public void Breed()
 {
     if (FreeSlots > 0)
     {
         Animal animal = new Animal();
         ListOfAnimals.Add(animal);
         FreeSlots--;
     }
     else
     {
         Console.WriteLine("No free slots");
     }
 }
Example #11
0
 public void Breed()
 {
     if (Slots > 0)
     {
         var animal = new Animal();
         ListOfAnimals.Add(animal);
         Slots--;
     }
     else
     {
         Console.WriteLine("The Farm is full");
     }
 }
Example #12
0
        public void SlaughterOne()
        {
            int hunger = 50;
            int index  = 0;

            for (int i = 0; i < ListOfAnimals.Count; i++)
            {
                if (ListOfAnimals[i].Hunger <= hunger)
                {
                    hunger = ListOfAnimals[i].Hunger;
                    index  = i;
                }
            }
            ListOfAnimals.Remove(ListOfAnimals[index]);
        }
Example #13
0
        public Animal(Guid id, string name, DateTimeOffset yearOfBirth, int age, TypeOfAnimals typeOfAnimals, TypeOfAnimalsOnTutrion typeOfAnimalsOnTutrion, ListOfAnimals aviaryFor) : base(id, name)
        {
            Age           = age;
            ListAnimals   = aviaryFor;
            YearOfBirth   = yearOfBirth;
            TypeOfAnimals = typeOfAnimals;

            TypeOfAnimalsOnTutrion = typeOfAnimalsOnTutrion;



            if (String.IsNullOrEmpty(name) || yearOfBirth == null)
            {
                throw new ArgumentNullException();
            }
        }
Example #14
0
        public override void ToScreen()
        {
            Console.WriteLine(Description);

            if (!ListOfAnimals.Contains(GameSession.wolf))
            {
                foreach (var item in ListOfItems)
                {
                    if (item == GameSession.manure)
                    {
                        Console.WriteLine("Det ligger en hög med [gödsel]  på marken. Utmärkt som näring till växter vid plantering.");
                    }
                    else
                    {
                        Console.WriteLine(item.Name + ": " + item.Description);
                    }
                }
            }
            else if (ListOfAnimals.Contains(GameSession.wolf))
            {
                GameSession.wolf.ToScreen();
            }
        }
Example #15
0
 public void Add(Animal animal)
 {
     ListOfAnimals.Add(animal);
     Slots--;
 }
Example #16
0
        public void SlaughterLinq()
        {
            var hungryAnimal = ListOfAnimals.OrderByDescending(a => a.Hunger).First();

            ListOfAnimals.Remove(hungryAnimal);
        }
Example #17
0
        public static void Main()
        {
            Console.WriteLine("Welcome to Wildlife Park!");
            ListOfAnimals listOfAnimals = new ListOfAnimals();

            while (true)
            {
                Console.WriteLine("Enter desirable option [add/remove/track/animal list/quit]");

                string answer = Console.ReadLine();
                if (answer == "add")
                {
                    Console.WriteLine("Enter species: ");
                    string species = Console.ReadLine();
                    Console.WriteLine("Enter name: ");
                    string name = Console.ReadLine();
                    Console.WriteLine("Enter age: ");
                    int age = int.Parse(Console.ReadLine());
                    listOfAnimals.AddAnimal(species, name, age);
                }
                else if (answer == "remove")
                {
                    Console.WriteLine("What property do you want to use to remove animal? [id, name, species]");
                    string removeAnswer = Console.ReadLine();
                    if (removeAnswer == "id")
                    {
                        int idToRemove = int.Parse(Console.ReadLine());
                        if (listOfAnimals.RemoveAnimalById(idToRemove))
                        {
                            Console.WriteLine("Animal with id " + idToRemove + " was deleted successfully.");
                        }
                        else
                        {
                            Console.WriteLine("No animals with id " + idToRemove + " were found.");
                        }
                    }
                    else if (removeAnswer == "name")
                    {
                        string nameToRemove = Console.ReadLine();
                        if (listOfAnimals.RemoveAnimalByName(nameToRemove))
                        {
                            Console.WriteLine("Animal with name " + nameToRemove + " was deleted successfully.");
                        }
                        else
                        {
                            Console.WriteLine("No animals with name " + nameToRemove + " were found.");
                        }
                    }
                    else if (removeAnswer == "species")
                    {
                        string speciesToRemove = Console.ReadLine();
                        if (listOfAnimals.RemoveAnimalBySpecies(speciesToRemove))
                        {
                            Console.WriteLine("Animal with species " + speciesToRemove + " was deleted successfully.");
                        }
                        else
                        {
                            Console.WriteLine("No animals with species " + speciesToRemove + " were found.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Something went wrong!");
                    }
                }
                else if (answer == "track")
                {
                    Console.WriteLine("What property do you want to use to track animal? [id, name, species]");
                    string findAnswer = Console.ReadLine();
                    if (findAnswer == "id")
                    {
                        int idToFind = int.Parse(Console.ReadLine());
                        Console.WriteLine(listOfAnimals.FindAnimalById(idToFind));
                    }
                    else if (findAnswer == "name")
                    {
                        string nameToFind = Console.ReadLine();
                        Console.WriteLine(listOfAnimals.FindAnimalByName(nameToFind));
                    }
                    else if (findAnswer == "species")
                    {
                        string speciesToFind = Console.ReadLine();
                        Console.WriteLine(listOfAnimals.FindAnimalsBySpecies(speciesToFind));
                    }
                    else
                    {
                        Console.WriteLine("Something went wrong!");
                    }
                }
                else if (answer == "animal list")
                {
                    Console.WriteLine(listOfAnimals.GetListOfAnimals());
                }
                else if (answer == "quit")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Wrong command.");
                }
            }

            Console.WriteLine("Good-Bye");
        }
Example #18
0
 public IEnumerator <T> GetEnumerator()
 {
     return(ListOfAnimals.GetEnumerator());
 }
Example #19
0
 public void Sort()
 {
     ListOfAnimals.Sort();
 }
Example #20
0
 public void Add(T animal)
 {
     ListOfAnimals.Add(animal);
 }