Beispiel #1
0
        static void Main()
        {
            string input = Console.ReadLine();
            AnimalFactory animalFactory=new AnimalFactory();
            FoodFactory foodFactory=new FoodFactory();
            Animal.Animal a;
            Food.Food food;
            while (!input.Equals("End"))
            {
                string[] animalInput = input.Split(' ');
                if (animalInput.Length == 4)
                {
                    a = animalFactory.CreateAnimal(animalInput[0], animalInput[1], double.Parse(animalInput[2]),
                        animalInput[3]);
                }
                else
                {
                    a = animalFactory.CreateAnimal(animalInput[0], animalInput[1], double.Parse(animalInput[2]),
                        animalInput[3],animalInput[4]);
                }

                string[] foodInput = Console.ReadLine().Split(' ');

                food = foodFactory.CreateFood(foodInput[0], int.Parse(foodInput[1]));

                a.MakeNoise();
                a.EatFood(food);
                Console.WriteLine(a);
                input = Console.ReadLine();
            }
        }
Beispiel #2
0
    public static void Main()
    {
        string        input         = Console.ReadLine();
        AnimalFactory animalFactory = new AnimalFactory();
        FoodFactory   foodFactory   = new FoodFactory();
        Animal        a;
        Food          food;

        while (!input.Equals("End"))
        {
            string[] animalInput = input.Split(' ');
            if (animalInput.Length == 4)
            {
                a = animalFactory.CreateAnimal(animalInput[0], animalInput[1], double.Parse(animalInput[2]),
                                               animalInput[3]);
            }
            else
            {
                a = animalFactory.CreateAnimal(animalInput[0], animalInput[1], double.Parse(animalInput[2]),
                                               animalInput[3], animalInput[4]);
            }

            string[] foodInput = Console.ReadLine().Split(' ');

            food = foodFactory.CreateFood(foodInput[0], int.Parse(foodInput[1]));

            a.MakeNoise();
            a.EatFood(food);
            Console.WriteLine(a);
            input = Console.ReadLine();
        }
    }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            IBagFactory    bagFactory = new DefaultBagFactory();
            IBagService    bagService = bagFactory.GetBagService();
            IAnimalFactory factory    = new AnimalFactory();

            bagService.AddAnimal(factory.CreateAnimal("mops", 3, AnimalType.OKKAM));
            bagService.AddAnimal(factory.CreateAnimal("sharpey", 3, AnimalType.OKKAM));
            bagService.SetDay();
            Console.WriteLine("NovDay");
            Console.WriteLine(bagService.CommandVoiceToConcreteAnimal("mops"));
            Console.WriteLine(bagService.CommandVoiceToConcreteAnimal("sharpey"));
            Console.WriteLine(bagService.CommandVoiceToAllAnimals());
            bagService.SetNight();
            Console.WriteLine("NovNight");
            Console.WriteLine(bagService.CommandVoiceToConcreteAnimal("mops"));
            Console.WriteLine(bagService.CommandVoiceToConcreteAnimal("sharpey"));
            try
            {
                Console.WriteLine(bagService.CommandVoiceToAllAnimals());
            }
            catch (CallAllAnimalsAtNightException e)
            {
                Console.WriteLine(e.GetType());
            }
            Console.WriteLine("GetTotalFoodWeightPerDay");
            Console.WriteLine(bagService.GetTotalFoodWeightPerDay());
            Console.WriteLine("CountAllAnimals");
            Console.WriteLine(bagService.CountAllAnimals());
            Console.WriteLine("GetAverageFoodWeightPerAnimal");
            Console.WriteLine(bagService.GetAverageFoodWeightPerAnimal());
        }
Beispiel #4
0
        public void CreateAnimalShould()
        {
            var displayMoq = new Mock <IPresenting>().Object;

            var instance = new AnimalFactory(displayMoq);

            var bird     = instance.CreateAnimal <Bird>("orange");
            var dog      = instance.CreateAnimal <Dog>("orange");
            var hedgehog = instance.CreateAnimal <Hedgehog>("orange");

            Assert.True(bird is Bird);
            Assert.True(dog is Dog);
            Assert.True(hedgehog is Hedgehog);
        }
Beispiel #5
0
        public void Run()
        {
            string line;

            while ((line = reader.ReadLine()) != "End")
            {
                var    animalInfo = line.Split();
                var    foodInfo   = reader.ReadLine().Split();
                Animal animal     = animalFactory.CreateAnimal(animalInfo);
                Food   food       = foodFactory.CreateFood(foodInfo);
                writer.WriteLine(animal.ProduceSound());
                try
                {
                    animal.Feed(food);
                }
                catch (ArgumentException ae)
                {
                    writer.WriteLine(ae.Message);
                }
                animals.Add(animal);
            }

            foreach (var animal in this.animals)
            {
                writer.WriteLine(animal.ToString());
            }
        }
Beispiel #6
0
    private static void Main()
    {
        string        command;
        List <Animal> animals = new List <Animal>();

        while ((command = Console.ReadLine()) != "Beast!")
        {
            string        animalType = command;
            List <string> info       = Console.ReadLine()
                                       .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                       .ToList();
            try
            {
                Animal animal = AnimalFactory.CreateAnimal(animalType, info);
                animals.Add(animal);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        foreach (var animal in animals)
        {
            Console.WriteLine(animal);
        }
    }
Beispiel #7
0
        public void AnimalFoodIsInitializedTest()
        {
            var pet = (Cat)AnimalFactory.CreateAnimal("Cat", Gender.Male, "Wiskers");

            //var pet = new Cat(Gender.Male, "Wiskers");
            Assert.AreEqual(pet.MeatFoodAllowed.Count(), 1);
        }
Beispiel #8
0
        public void Run()
        {
            string        input         = string.Empty;
            List <Animal> listOfAnimals = new List <Animal>();

            while ((input = Console.ReadLine()) != "E")
            {
                string[] animalData = input.Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                      .ToArray();
                string[] foodData = Console.ReadLine()
                                    .Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();

                Animal animal = AnimalFactory.CreateAnimal(animalData);
                listOfAnimals.Add(animal);
                Food food = FoodFactory.CreateFood(foodData);
                Console.WriteLine(animal.ProduceSound());
                try
                {
                    animal.Eat(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }
            }
            listOfAnimals.ForEach(Console.WriteLine);
        }
        public void Run()
        {
            string type = "";

            while ((type = Console.ReadLine()) != "Beast!")
            {
                try
                {
                    string[] data   = Console.ReadLine().Split(' ');
                    string   name   = data[0];
                    int      age    = int.Parse(data[1]);
                    string   gender = data[2];

                    Animal currentAnimal = AnimalFactory.CreateAnimal(type, name, age, gender);
                    animals.Add(currentAnimal);
                }
                catch (ArgumentException exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.ToString());
                animal.ProduceSound();
            }
        }
Beispiel #10
0
        public void Run()
        {
            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                var animalData = command.Split();
                var foodData   = Console.ReadLine().Split();

                IAnimal animal = animalFactory.CreateAnimal(animalData);
                IFood   food   = foodFactory.CreateFood(foodData[0], int.Parse(foodData[1]));

                animal.ProduceSound();
                try
                {
                    animal.Eat(food);
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }

                animals.Add(animal);
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Beispiel #11
0
        public void Run()
        {
            string input;

            while ((input = Read()) != "End")
            {
                try
                {
                    IAnimal animal = animalFactory.CreateAnimal(input.Split());

                    IFood food = foodFactory.CreateFood(Read().Split());

                    animals.Add(animal);
                    Print(animal.AskFood());

                    animal.Eat(food);
                }
                catch (ArgumentException ae)
                {
                    Print(ae.Message);
                }
            }

            animals.ForEach(a => Print(a.ToString()));
        }
Beispiel #12
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (!input.Equals("Beast!"))
            {
                try
                {
                    string[] arguments = Console.ReadLine().Split();
                    string   name      = arguments[0];
                    int?     age       = int.Parse(arguments[1]);
                    string   gender    = arguments[2];

                    var newAnimal = animalFactory.CreateAnimal(input, name, age, gender);
                    animals.Add(newAnimal);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                input = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
                Console.WriteLine($"{animal.Name} {animal.Age} {animal.Gender}");
                animal.ProduceSound();
            }
        }
Beispiel #13
0
        private void CreateAnimal_Click(object sender, EventArgs e)
        {
            var gender = MaleButton.Checked ? MaleButton.Text : FemaleButton.Text;

            Gender currentGender = (Gender)(Enum.Parse(typeof(Gender), gender));

            try
            {
                if (comboBox1.SelectedItem == null || petNameTextBox.Text == "Pet Name")
                {
                    throw new CustomException("Please fill the form!");
                }
                pet = AnimalFactory.CreateAnimal(comboBox1.SelectedItem.ToString(), currentGender, petNameTextBox.Text);

                player = new Player(pet);

                shop.LoadStore(pet);
                shopList.Items.AddRange(shop.FoodsInStore.Select(x => x.GetType().Name).ToArray());
                priceList.Items.AddRange(shop.FoodsInStore.Select(x => x as IBuyable).Select(x => x.Price.ToString()).ToArray());

                petPictureBox.BackgroundImage = Image.FromFile(pet.Pictures[0]);

                SetGameplayWindow();
            }
            catch (CustomException)
            {
                MessageBox.Show("Please fill the form", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }


            gameTimer.Enabled = true;
        }
Beispiel #14
0
        /// <summary>
        /// The button used to add an animal to the list box.
        /// </summary>
        /// <param name="sender"> Not available.</param>
        /// <param name="e"> The parameter is not used.</param>
        private void addAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Get the selected animal type from the list box.
                AnimalType animalType = (AnimalType)this.animalTypeComboBox.SelectedItem;

                // Create an animal based on the type.
                Animal animal = AnimalFactory.CreateAnimal(animalType, "Yoooo", 17, 71, Gender.Female);

                // Make a new window with the new animal.
                AnimalWindow animalWindow = new AnimalWindow(animal);

                // If the dialog box is shown then add the animal to the list and repopulate the screen with the updated list.
                if (animalWindow.ShowDialog() == true)
                {
                    zoo.AddAnimal(animal);

                    PopulateAnimalListBox();
                }
                else
                {
                    // If the above code doesn't work, do nothing.
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("You must choose an animal type before you can add an animal.");
            }
        }
Beispiel #15
0
        public void Run()
        {
            string type = Console.ReadLine();

            while (type.Equals("Beast!") == false)
            {
                try
                {
                    string[] token = Console.ReadLine()
                                     .Split();

                    string name   = token[0];
                    int    age    = int.Parse(token[1]);
                    string gender = token[2];

                    Animal animal = animalFactory
                                    .CreateAnimal(type, name, age, gender);

                    animals.Add(animal);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                type = Console.ReadLine();
            }

            Print();
        }
Beispiel #16
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (input != "Beast!")
            {
                try
                {
                    string   type = input;
                    string[] data = Console.ReadLine().Split();

                    string name   = data[0];
                    int    age    = int.Parse(data[1]);
                    string gender = data[2];

                    Animal animal = animalFactory.CreateAnimal(type, name, age, gender);
                    animals.Add(animal);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                input = Console.ReadLine();
            }

            Print();
        }
Beispiel #17
0
        public void Run()
        {
            var input = Console.ReadLine();

            while (input != "Beast!")
            {
                try
                {
                    var type = input;
                    var data = Console.ReadLine().Split();

                    var name   = data[0];
                    var age    = int.Parse(data[1]);
                    var gender = data[2];

                    Animal animal = animalFactory.CreateAnimal(type, name, age, gender);
                    animals.Add(animal);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                input = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Beispiel #18
0
        static void Main()
        {
            List <Animal> animals = new List <Animal>();

            string input;

            while ((input = Console.ReadLine()) != "End")

            {
                Animal animal = AnimalFactory.CreateAnimal(input.Split(' '));
                animals.Add(animal);
                Console.WriteLine(animal.Sound());
                Food food = FoodFactory.CreateFood(Console.ReadLine().Split(" "));

                try
                {
                    animal.EatFood(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            animals.ForEach(Console.WriteLine);
        }
    static void Main(string[] args)
    {
        IAnimal animal = AnimalFactory.CreateAnimal <Dog>();

        animal.Speak();
        Console.ReadKey();
    }
Beispiel #20
0
        public void Run()
        {
            string line = Console.ReadLine();

            while (line != "End")
            {
                string[] animalInfo = line
                                      .Split()
                                      .ToArray();

                string[] foodInfo = Console.ReadLine()
                                    .Split()
                                    .ToArray();

                Animal animal = AnimalFactory.CreateAnimal(animalInfo);
                Food   food   = FoodFactory.CreateFood(foodInfo);

                Console.WriteLine(animal.MakeSound());

                try
                {
                    animal.Feed(food);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animals.Add(animal);

                line = Console.ReadLine();
            }

            PrintAnimals();
        }
Beispiel #21
0
        public void Run()
        {
            string input = reader.ReadLine();

            while (input != "End")
            {
                string[] firstSplit = input.Split();
                Animal   animal     = animalFactory.CreateAnimal(firstSplit);
                animals.Add(animal);

                string[] secondSplit = reader.ReadLine().Split();
                Food     food        = foodFactory.CreateFood(secondSplit);

                writer.WriteLine(animal.ProduceSound());
                try
                {
                    animal.Feed(food);
                }
                catch (Exception ae)
                {
                    writer.WriteLine(ae.Message);
                }

                input = reader.ReadLine();
            }

            foreach (var anim in animals)
            {
                writer.WriteLine(anim.ToString());
            }
        }
Beispiel #22
0
      public static void CreateAppointment()
      {
          var customer    = _customerFactory.CreateCustomer();
          var animal      = _animalFactory.CreateAnimal();
          var appointment = _appointmentFactory.CreateAppointment(animal, customer);

          Console.WriteLine(" ");
          //appointment.Display();
      }
Beispiel #23
0
        public void Run()
        {
            string input;
            var    countLines = 0;

            while ((input = Console.ReadLine()) != "End")
            {
                try
                {
                    if (countLines % 2 == 0)
                    {
                        try
                        {
                            var animalInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
                            animal = animalFactory.CreateAnimal(animalInfo);
                            countLines++;
                            continue;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    else
                    {
                        try
                        {
                            var foodInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
                            food = foodFactory.CreateFood(foodInfo);
                            countLines++;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }

                    try
                    {
                        Console.WriteLine(animal.ProduceSound());
                        animal.Eat(food);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    animals.Add(animal);
                }
                catch (Exception)
                {
                    throw;
                }
            }

            animals.ForEach(a => Console.WriteLine(a));
        }
Beispiel #24
0
        public void AnimalChangeConditionTest()
        {
            var pet = AnimalFactory.CreateAnimal("Cat", Gender.Male, "Wiskers");

            pet.CurrentCondition.ChangeHappiness(-10);
            Assert.AreEqual(pet.CurrentCondition.Happiness, 90);
            pet.CurrentCondition.ChangeFeed(10);
            Assert.AreEqual(pet.CurrentCondition.Feed, 100);
            //Assert.AreEqual(pet.CurrentCondition.Happiness, 90);
        }
        public void IterateShould()
        {
            var mockDisplay = new Mock <IPresenting>();
            var factory     = new AnimalFactory(mockDisplay.Object);
            var animals     = new List <Animal>
            {
                factory.CreateAnimal <Dog>(""), factory.CreateAnimal <Bird>(""), factory.CreateAnimal <Hedgehog>("")
            };

            var instance = new AnimalIterator(mockDisplay.Object);

            instance.Iterate(animals);

            animals.ForEach(x =>
            {
                Assert.Equal("Grey", x.Color);
            });

            mockDisplay.Verify(c => c.DisplayOnLine(It.IsAny <string>()), Times.AtLeast(2));
        }
        public Enclosure Build(int enclosureId, char enclosureName)
        {
            var enclosure = new Enclosure(enclosureId, enclosureName);

            foreach (var animalInfo in animals)
            {
                var animal = AnimalFactory.CreateAnimal(animalInfo.Item1, animalInfo.Item2);
                enclosure.AddAnimal(animal);
            }
            return(enclosure);
        }
Beispiel #27
0
        private IAnimal CreateAnimal(ConsoleKeyInfo?keyPressedInfo)
        {
            if (!keyPressedInfo.HasValue)
            {
                return(null);
            }

            var animalChar = char.ToUpper(keyPressedInfo.Value.KeyChar);

            return(_animalFactory.CreateAnimal(animalChar));
        }
Beispiel #28
0
        public void AnimalSerializeTest()
        {
            var pet   = AnimalFactory.CreateAnimal("Cat", Gender.Male, "Wiskers");
            var pizza = new Pizza();
            var steak = new Steak();

            pet.FoodsInfinite = new List <Food> {
                pizza, steak
            };
            pet.Serialize();
        }
Beispiel #29
0
        public IAnimal Spawn(IAnimal animal, IEnumerable <IAnimal> animals)
        {
            animal.MatingIndex = GetMatingIndex(animal, animals);
            if (animal.MatingIndex == ConstantValues.MatingMaxIndex)
            {
                var newAnimal = _animalFactory.CreateAnimal(animal.Symbol);
                animal.MatingIndex = 0;
                return(newAnimal);
            }

            return(null);
        }
Beispiel #30
0
        public void CreateAnimal_WhenLionKeyisPassedDown_ShouldCreateInstanceOfAnimal()
        {
            // ARRANGE

            Field field = new Field()
            {
                Width   = 20,
                Height  = 20,
                Animals = new List <Animal>
                {
                    new Animal()
                }
            };

            facadeMock.Setup(f => f.GetRandomMinMax(0, 20)).Returns(0);
            ConsoleKey key = TextParameters.LionKey;

            //ACT
            var result = animalFactory.CreateAnimal(key, field);

            // ASSERT
            Assert.IsInstanceOf <Animal>(result);
        }
Beispiel #31
0
        public void Run()
        {
            int    line  = 0;
            string input = Console.ReadLine();

            while (input != "End")
            {
                if (line % 2 == 0)
                {
                    IAnimal animal = animalFactory.CreateAnimal(input.Split());
                    if (animal == null)
                    {
                        continue;
                    }
                    animals.Add(animal);
                }
                else
                {
                    IFood food = foodFactory.CreateFood(input.Split());
                    if (food == null)
                    {
                        continue;
                    }
                    foods.Add(food);
                }

                line++;
                input = Console.ReadLine();
            }

            for (int i = 0; i < foods.Count; i++)
            {
                IAnimal animal = animals[i];
                IFood   food   = foods[i];
                Console.WriteLine(animal.ProduceSound());
                try
                {
                    animal.Eat(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }