private Animal castAnimal(int speciesIndex, CategoryType type) { //Checking which object to create: if (type == CategoryType.Bird) { BirdSpecies speciestype = (BirdSpecies)speciesIndex; animalis = BirdFactory.CreateBird(speciestype); } else if (type == CategoryType.Insect) { InsectSpecies insectSpec = (InsectSpecies)speciesIndex; animalis = InsectFactory.CreateInsect(insectSpec); } else if (type == CategoryType.Mammal) { MammalSpecies mammalSpec = (MammalSpecies)speciesIndex; animalis = MammalFactory.CreateMammal(mammalSpec); } else if (type == CategoryType.Marine) { MarineSpecies marineSpec = (MarineSpecies)speciesIndex; animalis = MarineFactory.CreateMarine(marineSpec); } else if (type == CategoryType.Reptile) { ReptileSpecies reptileSpec = (ReptileSpecies)speciesIndex; animalis = ReptileFactory.CreateReptile(reptileSpec); } return(animalis); }
static void Main(string[] args) { Console.WriteLine("----------Factory Method----------"); var bird1 = BirdFactory.CreateBird("cROw"); Console.Write("Voice bird : "); bird1.GetVoice(); Console.WriteLine("----------Singleton----------"); Singleton instanceSingleton = Singleton.GetInstance(); Console.WriteLine("Value SomeField in first object : {0} ", instanceSingleton.SomeField); instanceSingleton.SomeField += 5; Console.WriteLine("Changed value SomeField in first object : {0} ", instanceSingleton.SomeField); Singleton instanceSingleton2 = Singleton.GetInstance(); Console.WriteLine("Value SomeField in second object : {0} ", instanceSingleton2.SomeField); Console.WriteLine("----------Strategy----------"); Man man = new Man(22, "Ivan", new ConcreteStrategy1()); man.UseDatabase(); man.Strategy = new ConcreteStrategy2(); man.UseDatabase(); Console.WriteLine("----------Fasad----------"); VisualStudioFasad fasad = new VisualStudioFasad(new CLR(), new Compiller()); Console.WriteLine("Execute operation1:"); fasad.Operation1(); Console.WriteLine(); Console.WriteLine("Execute operation2:"); fasad.Operation2(); Console.WriteLine("----------Template method----------"); List <Shop> shops = new List <Shop>() { new FirstShop("FirstShop"), new SecondShop("SecondShop") }; shops.ForEach(x => x.Operation1()); Console.WriteLine("----------Observer----------"); var bank = new Bank(); var client1 = new Client("Metesky", bank); var client2 = new Client("Kot", bank); bank.ChangeCurrencies(); bank.ChangeCurrencies(); Console.WriteLine("----------Proxy----------"); Subject proxy = new Proxy(); proxy.Request(); Console.ReadKey(); }
public void Run() { string command = ""; while ((command = Console.ReadLine()) != "End") { string[] animalInfo = command.Split(); string[] foodInfo = Console.ReadLine().Split(); string animalType = animalInfo[0].ToLower(); string name = animalInfo[1]; double weight = double.Parse(animalInfo[2]); if (animalType == "cat" || animalType == "tiger") { string livingRegion = animalInfo[3]; string breed = animalInfo[4]; animal = (IAnimal)felineFactory.CreateFeline(animalType, name, weight, livingRegion, breed); } else if (animalType == "owl" || animalType == "hen") { double wingSize = double.Parse(animalInfo[3]); animal = (IAnimal)birdFactory.CreateBird(animalType, name, weight, wingSize); } else if (animalType == "mouse" || animalType == "dog") { string livingRegion = animalInfo[3]; animal = (IAnimal)mammalFactory.CreateMammal(animalType, name, weight, livingRegion); } animals.Add(animal); animal.ProduceSound(); try { string foodType = foodInfo[0]; double quantity = double.Parse(foodInfo[1]); IFood food = foodFactory.CreateFood(foodType, quantity); animal.Eat(food); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } } foreach (var animal in this.animals) { Console.WriteLine(animal); } }
public void Run() { string input = string.Empty; while ((input = Console.ReadLine()) != "End") { string[] animalInfo = input.Split(); string animalType = animalInfo[0]; string animalName = animalInfo[1]; double animalWeight = double.Parse(animalInfo[2]); if (animalType == "Hen" || animalType == "Owl") { double wingSize = double.Parse(animalInfo[3]); animal = birdFactory.CreateBird(animalType, animalName, animalWeight, wingSize); } else if (animalType == "Dog" || animalType == "Mouse") { string livingregion = animalInfo[3]; animal = mammalFactory.CreateMammal(animalType, animalName, animalWeight, livingregion); } else if (animalType == "Cat" || animalType == "Tiger") { string livingregion = animalInfo[3]; string breed = animalInfo[4]; animal = felineFactory.CreateFeline(animalType, animalName, animalWeight, livingregion, breed); } string[] foodInfo = Console.ReadLine().Split(); string foodType = foodInfo[0]; int foodQuantity = int.Parse(foodInfo[1]); Food food = foodFactory.CreateFood(foodType, foodQuantity); animal.ProduceSound(); animal.Eat(food); animals.Add(animal); } foreach (var animal in animals) { Console.WriteLine(animal); } }
public void Run() { var input = Console.ReadLine(); while (input != "End") { try { var animalArgs = input.Split(); var foodInfo = Console.ReadLine().Split(); var animalType = animalArgs[0]; var name = animalArgs[1]; var weight = double.Parse(animalArgs[2]); if (animalType == "Hen" || animalType == "Owl") { var wingSize = double.Parse(animalArgs[3]); animal = birdFactory.CreateBird(animalType, name, weight, wingSize); } else if (animalType == "Cat" || animalType == "Tiger") { var region = animalArgs[3]; var breed = animalArgs[4]; animal = felinesFactory.CreateFeline(animalType, name, weight, region, breed); } if (animalType == "Dog" || animalType == "Mouse") { var region = animalArgs[3]; animal = mammalFactory.CreateMammal(animalType, name, weight, region); } var foodType = foodInfo[0]; var foodQuantity = int.Parse(foodInfo[1]); var food = foodFactory.CreateFood(foodType, foodQuantity); animal.ProduceSound(); animal.Eat(food); animals.Add(animal); Console.WriteLine(animal); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } input = Console.ReadLine(); } }
public void Run() { string input = Console.ReadLine(); while (input != "End") { string[] animalArguments = input.Split(" ", StringSplitOptions.RemoveEmptyEntries); string typeAnimal = animalArguments[0].ToLower(); string name = animalArguments[1]; double weight = double.Parse(animalArguments[2]); if (typeAnimal == "hen" || typeAnimal == "owl") { double wingSize = double.Parse(animalArguments[3]); animal = birdFactory.CreateBird(typeAnimal, name, weight, wingSize); } else if (typeAnimal == "mouse" || typeAnimal == "dog") { string livingRegion = animalArguments[3]; animal = mammalFactory.CreateMammal(typeAnimal, name, weight, livingRegion); } else if (typeAnimal == "cat" || typeAnimal == "tiger") { string livingRegion = animalArguments[3]; string breed = animalArguments[4]; animal = felineFactory.CreateFeline(typeAnimal, name, weight, livingRegion, breed); } animal.ProduceSound(); string[] foodArguments = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); string typeFood = foodArguments[0]; int quantity = int.Parse(foodArguments[1]); var food = foodFactory.CreateFood(typeFood, quantity); animal.Eat(food); this.animals.Add(animal); input = Console.ReadLine(); } foreach (var animal in animals) { Console.WriteLine(animal.ToString()); } }
private void GetAnimal(string[] animalInfo, string typeOfAnimal, string name, double weight) { if (typeOfAnimal.Equals("Hen") || typeOfAnimal.Equals("Owl")) { double wingSize = double.Parse(animalInfo[3]); animal = birdFactory.CreateBird(typeOfAnimal, name, weight, wingSize); } else if (typeOfAnimal.Equals("Mouse") || typeOfAnimal.Equals("Dog")) { string livingRegion = animalInfo[3]; animal = mammalFactory.CreateMamal(typeOfAnimal, name, weight, livingRegion); } else if (typeOfAnimal.Equals("Cat") || typeOfAnimal.Equals("Tiger")) { string livingRegion = animalInfo[3]; string breed = animalInfo[4]; animal = felineFactory.CreateFeline(typeOfAnimal, name, weight, livingRegion, breed); } }
public override void Activate(Game game) { System.Diagnostics.Debug.Assert(this.Bee != null); base.Activate(game); this.TextureBody = this.ContentManager.Load<Texture2D>("sprites/bird_body"); this.TextureFace = this.ContentManager.Load<Texture2D>("sprites/bird_face"); this.TextureLegs = this.ContentManager.Load<Texture2D>("sprites/bird_legs"); this.TextureHead = this.ContentManager.Load<Texture2D>("sprites/bird_head"); this.TextureEyelids = this.ContentManager.Load<Texture2D>("sprites/bird_eyelids"); var lLevelData = this.ContentManager.Load<LevelData>("levels/level_" + this.CurrentLevel.ToString("00")); var lBirdFactory = new BirdFactory(this.ContentManager, this.BulletFired, this.Bee); this.Birds = lLevelData.BirdData.Select(x => lBirdFactory.CreateBird(x)).ToArray(); this.TotalBirdCount = this.Birds.Count; this.LevelDuration = lLevelData.EndTime; this.CurrentBirdIndex = 0; }
public void Run() { BirdFactory birdFactory = new BirdFactory(); MammalFactory mammalFactory = new MammalFactory(); FelineFactory felineFactory = new FelineFactory(); FoodFactory foodFactory = new FoodFactory(); List <Animal> animals = new List <Animal>(); while (true) { string[] currentAnimal = Console.ReadLine().Split(); if (currentAnimal[0] == "End") { break; } string[] currentFood = Console.ReadLine().Split(); string animalType = currentAnimal[0]; string animalName = currentAnimal[1]; double animalWeight = double.Parse(currentAnimal[2]); string foodType = currentFood[0]; int foodQuantity = int.Parse(currentFood[1]); Food food = foodFactory.CreateFood(foodType, foodQuantity); try { if (animalType == "Hen" || animalType == "Owl") { double wingSize = double.Parse(currentAnimal[3]); Animal animal = birdFactory.CreateBird(animalType, animalName, animalWeight, wingSize); animal.ProduceSound(); animals.Add(animal); animal.Eat(food); } else if (animalType == "Mouse" || animalType == "Dog") { string livingRegion = currentAnimal[3]; Animal animal = mammalFactory.CreateMammal(animalType, animalName, animalWeight, livingRegion); animal.ProduceSound(); animals.Add(animal); animal.Eat(food); } else if (animalType == "Cat" || animalType == "Tiger") { string livingRegion = currentAnimal[3]; string breed = currentAnimal[4]; Animal animal = felineFactory.CreateFeline(animalType, animalName, animalWeight, livingRegion, breed); animal.ProduceSound(); animals.Add(animal); animal.Eat(food); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } foreach (Animal animal in animals) { Console.WriteLine(animal); } }