Пример #1
0
        public static void RunDemo()
        {
            var bengalTiger = new Tiger("Razor", 1);
            var whiteTiger  = new Tiger("Kali", 0);
            var brownTiger  = new Tiger("Chochko", 1);
            var megaTiger   = new Tiger("SBTech Tiger", 2);
            var lameTiger   = new Tiger("Obicham da qm", 21);

            var peshoTheKeeper = new ZooKeeper();
            var goshoTheKeeper = new ZooKeeper();

            var zoo = new Zoo();

            zoo.AddAnimal(bengalTiger);
            zoo.AddAnimal(whiteTiger);
            zoo.AddAnimal(brownTiger);
            zoo.AddAnimal(megaTiger);
            zoo.AddAnimal(lameTiger);

            peshoTheKeeper.Assign(bengalTiger);
            peshoTheKeeper.Assign(whiteTiger);

            goshoTheKeeper.Assign(brownTiger);
            goshoTheKeeper.Assign(megaTiger);
            goshoTheKeeper.Assign(lameTiger);

            zoo.AddZooKeeper(peshoTheKeeper);
            zoo.AddZooKeeper(goshoTheKeeper);

            for (int i = 0; i < 120; i++)
            {
                zoo.TriggerCycle();
            }
        }
Пример #2
0
        public void Setup()
        {
            londonZoo = new Zoo();

            londonZoo.AddAnimal(new Animal()
            {
                Name = "Monkey", MovesBy = new List <MovementType>()
                {
                    MovementType.Walk
                }
            });
            londonZoo.AddAnimal(new Animal()
            {
                Name = "Dolphin", MovesBy = new List <MovementType>()
                {
                    MovementType.Swim
                }
            });
            londonZoo.AddAnimal(new Animal()
            {
                Name = "Bat", MovesBy = new List <MovementType>()
                {
                    MovementType.Fly, MovementType.Walk
                }
            });
            londonZoo.AddAnimal(new Animal()
            {
                Name = "Penguin", MovesBy = new List <MovementType>()
                {
                    MovementType.Walk, MovementType.Swim
                }
            });
            londonZoo.AddAnimal(new Duck());
        }
Пример #3
0
        public void SumWeightTest()
        {
            f1.Add(f2);
            f1.Add(bearAviary);
            f2.Add(giraffeAviary);
            f2.Add(wolfAviary);
            zoo.AddField(f1);

            zoo.AddAnimal("Some Animal 1", 1);
            zoo.AddAnimal("Some Animal 2", 2);

            Assert.AreEqual(zoo.SumWeight(), 3);
        }
Пример #4
0
        private void Run()
        {
            Zoo zoo = new Zoo();

            byte[] tigerEnclosure = zoo.enclosureFactory.GetBytes(new TigerEnclosure(55));
            zoo.AddEnclosure(tigerEnclosure);

            byte[] tiger1 = zoo.animalFactory.GetBytes(new Tiger(50));
            byte[] tiger2 = zoo.animalFactory.GetBytes(new Tiger(60));
            byte[] whale1 = zoo.animalFactory.GetBytes(new Whale(670.4f));
            byte[] whale2 = zoo.animalFactory.GetBytes(new Whale(915.7f));
            byte[] alien  = zoo.animalFactory.GetBytes(new Alien("mars"));

            zoo.AddAnimal(tiger1);
            zoo.AddAnimal(tiger2);
            zoo.AddAnimal(whale1);
            zoo.AddAnimal(whale2);
            zoo.AddAnimal(alien);
        }
Пример #5
0
    public void Run()
    {
        Zoo zoo = new Zoo();

        zoo.AddAnimal("Tom", 8);
        foreach (Animal a in zoo.Animals)
        {
            Console.WriteLine(a.ToString());
        }
    }
Пример #6
0
        static void Main(string[] args)
        {
            var fido = new Dog()
            {
                Name = "Fido"
            };
            var bryan = new Dolphin {
                Name = "Bryan"
            };
            var zoo = new Zoo();

            zoo.AddAnimal(fido);
            zoo.AddAnimal(bryan);
            zoo.AddAnimal(new Cricket()
            {
                Name = "Toby"
            });

            zoo.Tour();
        }
Пример #7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            formLogic   = new FormLogic();
            timeTB.Text = "0:00";

            var storage = new Storage();
            var zoo     = new Zoo(storage);

            var CornType  = new FoodType("Corn");
            var MeatType  = new FoodType("Meat");
            var BoneType  = new FoodType("Bone");
            var PlantType = new FoodType("Planty");
            var FishType  = new FoodType("Fish");

            var corn    = new Food("corn", 100, CornType);
            var cow     = new Food("cow", 120, MeatType);
            var chicken = new Food("chicken", 150, MeatType);
            var bone    = new Food("bone", 100, BoneType);
            var grass   = new Food("grass", 200, PlantType);
            var fish    = new Food("fish", 180, FishType);

            var mammal1 = new Mammal("Misha", 300, 5, MeatType, BoneType);
            var fish1   = new Fish("Nemo", 1, 2, CornType, PlantType);
            var bird1   = new Bird("Chick", 2, 4, CornType, PlantType);
            var bird2   = new Bird("Levi", 15, 6, CornType, PlantType);
            var mammal2 = new Mammal("Pengin", 12, 7, FishType, CornType);
            var mammal3 = new Mammal("Tiger", 120, 3, MeatType, FishType, BoneType);
            var fish2   = new Fish("Karp", 3, 4, CornType, PlantType);

            zoo.AddAnimal(mammal1, mammal2, mammal3, bird1, bird2, fish1, fish2);

            this.zoo = zoo;

            storage.AddFood(corn, 10);
            storage.AddFood(cow, 4);
            storage.AddFood(chicken, 12);
            storage.AddFood(bone, 2);
            storage.AddFood(grass, 3);
            storage.AddFood(fish, 1);

            foreach (Animal animal in zoo.GetAnimals())
            {
                AnimalsLV.Items.Add(animal.GetName());
            }

            List <Food> keys = zoo.GetStorage().GetStore().Keys.ToArray().ToList();

            foreach (Food key in keys)
            {
                StorageLV.Items.Add(key.GetName());
            }
        }
Пример #8
0
        public static void Main()
        {
            Zoo Zoo = new Zoo("GRADINA ZOOLOGICA");

            Zoo.AddAnimal("leul", "carne cruda");
            Zoo.AddAnimal("vulpea", "gaini");
            Zoo.AddAnimal("caprioara", "iarba");
            Zoo.AddAnimal("iepurele", "morcovi");
            Zoo.AddAnimal("maimutele", "banane");
            Zoo.AddAnimal("soarecii", "branza");
            Zoo.PresentZoo();
            Zoo.Transfer("maimutele");
            Zoo.PresentZoo();
        }
Пример #9
0
        /// <summary>
        /// Adds a new animal to the zoo.
        /// </summary>
        /// <param name="zoo">The current zoo.</param>
        private static void AddAnimal(Zoo zoo)
        {
            AnimalType animalType = ConsoleUtil.ReadAnimalType();

            Animal animal = AnimalFactory.CreateAnimal(animalType, string.Empty, 0, 1, Gender.Female);

            if (animal == null)
            {
                throw new NullReferenceException("Animal could not be found.");
            }

            animal.Name   = ConsoleUtil.InitialUpper(ConsoleUtil.ReadAlphabeticValue("Name"));
            animal.Gender = ConsoleUtil.ReadGender();
            animal.Age    = ConsoleUtil.ReadIntValue("Age");
            animal.Weight = ConsoleUtil.ReadDoubleValue("Weight");

            zoo.AddAnimal(animal);

            ConsoleHelper.ShowAnimal(zoo, animal.Name);
        }
Пример #10
0
        /// <summary>
        /// Adds an animal to the zoo.
        /// </summary>
        /// <param name="zoo">The zoo in which to add an animal.</param>
        private static void AddAnimal(Zoo zoo)
        {
            // Reads the animal type from the console.
            AnimalType readAnimal = ConsoleUtil.ReadAnimalType();

            // Creates the entered animal type.
            Animal animal = AnimalFactory.CreateAnimal(readAnimal, "Max", 2, 78, Gender.Female) as Animal;

            // Prompt for animal name.
            bool nameSuccess = false;

            while (!nameSuccess)
            {
                try
                {
                    string animalName = ConsoleUtil.ReadAlphabeticValue("Name");
                    animal.Name = ConsoleUtil.InitialUpper(animalName);

                    nameSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // prompt for animal gender.
            bool genderSuccess = false;

            while (!genderSuccess)
            {
                try
                {
                    animal.Gender = ConsoleUtil.ReadGender();

                    genderSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Prompt for animal age.
            bool ageSuccess = false;

            while (!ageSuccess)
            {
                try
                {
                    animal.Age = ConsoleUtil.ReadIntValue("Age");

                    ageSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Prompt for animal weight.
            bool weightSuccess = false;

            while (!weightSuccess)
            {
                try
                {
                    animal.Weight = ConsoleUtil.ReadDoubleValue("Weight");

                    weightSuccess = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // Add the newly created animal to the list.
            zoo.AddAnimal(animal);

            // Show the new animal.
            ShowAnimal(zoo, animal.Name);
        }
Пример #11
0
        /// <summary>
        /// Adds a new animal to the zoo.
        /// </summary>
        /// <param name="zoo">The current zoo.</param>
        private static void AddAnimal(Zoo zoo)
        {
            bool success = false;

            AnimalType animalType = ConsoleUtil.ReadAnimalType();

            Animal animal = AnimalFactory.CreateAnimal(animalType, string.Empty, 0, 1, Gender.Female);

            if (animal == null)
            {
                throw new NullReferenceException("Animal could not be found.");
            }

            while (!success)
            {
                try
                {
                    string name = ConsoleUtil.ReadAlphabeticValue("Name");

                    animal.Name = ConsoleUtil.InitialUpper(name);

                    success = true;
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            success = false;

            while (!success)
            {
                try
                {
                    animal.Gender = ConsoleUtil.ReadGender();

                    success = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            success = false;

            while (!success)
            {
                try
                {
                    int age = ConsoleUtil.ReadIntValue("Age");

                    animal.Age = age;
                    success    = true;
                }
                catch (ArgumentOutOfRangeException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            success = false;

            while (!success)
            {
                try
                {
                    double weight = ConsoleUtil.ReadDoubleValue("Weight");

                    animal.Weight = weight;
                    success       = true;
                }
                catch (ArgumentOutOfRangeException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            zoo.AddAnimal(animal);

            ConsoleHelper.ShowAnimal(zoo, animal.Name);
        }
Пример #12
0
 public override void Execute()
 {
     zoo.AddAnimal(name, type);
 }
Пример #13
0
        public frmZooSimulator()
        {
            InitializeComponent();
            _zoo = new Zoo(lblZooTime);
            _zoo.AddAnimal(AnimalType.Monkey, pbrMonkey1, lblMonkeyStatus1, lblMonkeyHealth1);
            _zoo.AddAnimal(AnimalType.Monkey, pbrMonkey2, lblMonkeyStatus2, lblMonkeyHealth2);
            _zoo.AddAnimal(AnimalType.Monkey, pbrMonkey3, lblMonkeyStatus3, lblMonkeyHealth3);
            _zoo.AddAnimal(AnimalType.Monkey, pbrMonkey4, lblMonkeyStatus4, lblMonkeyHealth4);
            _zoo.AddAnimal(AnimalType.Monkey, pbrMonkey5, lblMonkeyStatus5, lblMonkeyHealth5);

            _zoo.AddAnimal(AnimalType.Elephant, pbrElephant1, lblElephantStatus1, lblElephantHealth1);
            _zoo.AddAnimal(AnimalType.Elephant, pbrElephant2, lblElephantStatus2, lblElephantHealth2);
            _zoo.AddAnimal(AnimalType.Elephant, pbrElephant3, lblElephantStatus3, lblElephantHealth3);
            _zoo.AddAnimal(AnimalType.Elephant, pbrElephant4, lblElephantStatus4, lblElephantHealth4);
            _zoo.AddAnimal(AnimalType.Elephant, pbrElephant5, lblElephantStatus5, lblElephantHealth5);

            _zoo.AddAnimal(AnimalType.Giraffe, pbrGiraffe1, lblGiraffeStatus1, lblGiraffeHealth1);
            _zoo.AddAnimal(AnimalType.Giraffe, pbrGiraffe2, lblGiraffeStatus2, lblGiraffeHealth2);
            _zoo.AddAnimal(AnimalType.Giraffe, pbrGiraffe3, lblGiraffeStatus3, lblGiraffeHealth3);
            _zoo.AddAnimal(AnimalType.Giraffe, pbrGiraffe4, lblGiraffeStatus4, lblGiraffeHealth4);
            _zoo.AddAnimal(AnimalType.Giraffe, pbrGiraffe5, lblGiraffeStatus5, lblGiraffeHealth5);
        }
Пример #14
0
        static void Main(string[] args)
        {
            Zoo          zoo               = new Zoo();
            ScreenDrawer drawer            = new ScreenDrawer(zoo.Animals);
            string       lastCommandResult = String.Empty;

            zoo.Animals.RepositoryChanged += drawer.DrawEventMessage;
            zoo.ZooClosing += OnZooClosing;

            while (true)
            {
                drawer.CleanLine(Console.WindowHeight - 2);
                Console.SetCursorPosition(0, Console.CursorTop - 1);

                drawer.CommandMessage = lastCommandResult;
                drawer.Draw();

                string   commandString = drawer.ReadLineWithControl();
                string[] command       = commandString.Split(' ');

                try
                {
                    switch (command[0])
                    {
                    case "help":
                        drawer.ShowHelp();
                        break;

                    case "add":
                        zoo.AddAnimal(command[1], command[2]);
                        lastCommandResult = $"New {command[2]} {command[1]} in zoo!";
                        break;

                    case "remove":
                        lastCommandResult = zoo.RemoveAnimal(command[1]) ? $"Bye {command[1]}(" : "Hey, it\'s alive, actually!";
                        break;

                    case "feed":
                        zoo.FeedAnimal(command[1]);
                        break;

                    case "heal":
                        zoo.HealAnimal(command[1]);
                        break;

                    case "quit":
                        Environment.Exit(0);
                        break;

                    case "all":
                        drawer.SetDataSource(zoo.Animals.GetAll());
                        break;

                    case "GetByType":
                        drawer.SetDataSource(zoo.Animals.GetByType(command[1]));
                        break;

                    case "GetByState":
                        drawer.SetDataSource(zoo.Animals.GetByState(command[1]));
                        break;

                    case "GetSickTigers":
                        drawer.SetDataSource(zoo.Animals.GetSickTigers());
                        break;

                    case "GetElephantByName":
                        drawer.SetDataSource(new List <Animal>()
                        {
                            zoo.Animals.GetElephantByName(command[1])
                        });
                        break;

                    case "GetHungryNames":
                        lastCommandResult = String.Empty;

                        foreach (var a in zoo.Animals.GetHungryNames())
                        {
                            lastCommandResult += $"{a}, ";
                        }
                        lastCommandResult.Remove(lastCommandResult.Count() - 1, 1);
                        break;

                    case "GetMostHelthy":
                        drawer.SetDataSource(zoo.Animals.GetMostHelthy());
                        break;

                    case "GetDeadCountPerType":
                        lastCommandResult = String.Empty;

                        foreach (var t in zoo.Animals.GetDeadCountPerType())
                        {
                            lastCommandResult += $"{t.Item1}: {t.Item2}\n";
                        }
                        break;

                    case "GetWolfsAndBearsByHealth":
                        drawer.SetDataSource(zoo.Animals.GetWolfsAndBearsByHealth(3));
                        break;

                    case "GetMinAndMaxHealthy":
                        drawer.SetDataSource(zoo.Animals.GetMinAndMaxHealthy());
                        break;

                    case "GetHealthAverage":
                        lastCommandResult = zoo.Animals.GetHealthAverage().ToString();
                        break;

                    default:
                        lastCommandResult = "Unknown command";
                        break;
                    }
                }
                catch (AnimalNotFoundException ex)
                {
                    lastCommandResult = $"Animal named {ex.Message} is not exist";
                }
                catch (NameAlreadyUsedException ex)
                {
                    lastCommandResult = $"Name {ex.Message} already in use";
                }
                catch (SpeciesNotFoundException ex)
                {
                    lastCommandResult = $"Unknown species named {ex.Message}";
                }
                catch (Exception ex)
                {
                    lastCommandResult = $"Error: {ex.Message}";
                }
            }
        }
Пример #15
0
        private void AddAnimal(Type animalType)
        {
            Debug.WriteLine(animalType);

            Zoo.AddAnimal(animalType);
        }
Пример #16
0
        /// <summary>
        /// Adds the animal.
        /// </summary>
        /// <param name="zoo"> The zoo being added.</param>
        private static void AddAnimal(Zoo zoo)
        {
            // Creates a dingo with all of the inputted values.
            Animal animal = new Dingo("Joey", 43, 344, Gender.Male);

            bool success = false;

            AnimalType animalType = ConsoleUtil.ReadAnimalType();

            animal = AnimalFactory.CreateAnimal(animalType, "null", 1, 1, Gender.Male);

            // Sets the name for the animal.
            while (!success)
            {
                try
                {
                    // Gets the name and makes it upper case.

                    animal.Name = ConsoleUtil.ReadAlphabeticValue("Name");
                    animal.Name = ConsoleUtil.InitialUpper(animal.Name);

                    success = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Value must only contain letters and spaces.");
                }
            }

            success = false;

            // Sets the gender for the animal.
            while (!success)
            {
                try
                {
                    animal.Gender = ConsoleUtil.ReadGender();

                    success = true;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            success = false;

            // Sets the age for the animal.
            while (!success)
            {
                try
                {
                    animal.Age = ConsoleUtil.ReadIntValue("Age");

                    success = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Value must be between 0 and 100.");
                }
            }

            success = false;

            // Sets the weight for the animal.
            while (!success)
            {
                try
                {
                    animal.Weight = ConsoleUtil.ReadDoubleValue("Weight");

                    success = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Value must be between 0 and 1000.");
                }
            }

            zoo.AddAnimal(animal);

            ShowAnimal(zoo, animal.Name);
        }
Пример #17
0
        public void NoPlaceTest()
        {
            Zoo zoo = new Zoo();

            zoo.AddAnimal("Some Animal", 100);
        }