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); }
public Engine() { this.birdFactory = new BirdFactory(); this.felineFactory = new FelineFactory(); this.mammalFactory = new MammalFactory(); this.foodFactory = new FoodFactory(); this.animals = new List <Animal>(); }
public Engine() { birdFactory = new BirdFactory(); felineFactory = new FelineFactory(); mammalFactory = new MammalFactory(); foodFactory = new FoodFactory(); animals = new List <Animal>(); }
private static void Main(string[] args) { var eagle = BirdFactory.GetBird("Eagle"); var swan = BirdFactory.GetBird("Swan"); Console.WriteLine($"Bird Name : {eagle.Name}"); Console.WriteLine($"Bird Name : {swan.Name}"); }
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(); }
internal void DoBirdSpawning() { if (BirdList.Count <= BirdCountMax) { var x = FlatRedBallServices.Random.Between(birdRadiusEstimate, Map.Width - birdRadiusEstimate); var y = FlatRedBallServices.Random.Between(birdRadiusEstimate, -Map.Height + birdRadiusEstimate); var altitude = FlatRedBallServices.Random.Between(Bird.MinBirdAltitude, Bird.MaxBirdAltitude); var bird = BirdFactory.CreateNew(x, y); bird.Altitude = altitude; } }
static void Main(string[] args) { List <int> numbers = new List <int>() { 2, -2, 5, -1, 5, 2, 7, 2, -2, -1, 7, 2, 7, -1, 4 }; List <char> letters = new List <char>() { 'A', 'C', 'G', 'H', 'J', 'A', 'G', 'A' }; List <string> cities = new List <string>() { "ROME", "LONDON", "NAIROBI", "CALIFORNIA", "ZURICH", "NEW DELHI", "AMSTERDAM", "ABU DHABI", "PARIS" }; string sentence = "DET her er et STYKKE TEKST med BLANDET casing"; List <Bird> birds = BirdFactory.GetDefaultBirds(); FindNonNegativeNumbersMethodSyntax(numbers); FindNonNegativeNumbersQuerySyntax(numbers); FindAndCountNumbersMethodSyntax(numbers); FindAndCountNumbersQuerySyntax(numbers); FindAndCountLettersMethodSyntax(letters); FindAndCountLettersQuerySyntax(letters); FindWordsThatStartWithNAndEndWithIMethodSyntax(cities); FindWordsThatStartWithNAndEndWithIQuerySyntax(cities); FindWordsThatAreUpperCaseQuerySyntax(sentence); FindWordsThatAreUpperCaseMethodSyntax(sentence); CreateListWithBirdNamesQuerySyntax(birds); CreateListWithBirdsNamesMethodSyntax(birds); CreateListWithDistinctBirdNamesQuerySyntax(birds); CreateListWithDistinctBirdNamesMethodSyntax(birds); FindAllBlackBirdsMethodSyntax(birds); FindAllBlackBirdsQuerySyntax(birds); FindBlackBirdWithMostSightingsMethodSyntax(birds); FindBlackBirdWithMostSightingsQuerySyntax(birds); FindAllBlackAndRedBirdsMethodSyntax(birds); FindAllBlackAndRedBirdsQuerySyntax(birds); FindBirdWithMostSightingsMethodSyntax(birds); FindBirdWithMostSightingsQuerySyntax(birds); CreateListOfAllBirdsExceptTheTwoBirdsWithMostSightingsMethodSyntax(birds); CreateListOfAllBirdsExceptTheTwoBirdsWithMostSightingsQuerySyntax(birds); CreateListOfAnonymousTypesQuerySyntax(birds); CreateListOfAnonymousTypesMethodSyntax(birds); CheckIfAllBirdsAreBlackMethodSyntax(birds); CheckIfAnyBirdIsWhiteMethodSyntax(birds); SortBirdsByNameColorAndSightingsMethodSyntax(birds); SortBirdsByNameColorAndSightingsQuerySyntax(birds); SelectBirdsInAListByNameFromAnotherListMethodSyntax(birds); SelectBirdsInAListByNameFromAnotherListQuerySyntax(birds); Console.Read(); }
void Start() { _availableBaseBirds = new List <BaseBird>(); _currentInactiveBirdPosition = birdsInactiveStartPosition; foreach (Bird birdType in availableTypeBirds) { BaseBird bird = BirdFactory.Create(birdType); bird.gameObject.transform.SetParent(transform); bird.gameObject.transform.position = transform.position + _currentInactiveBirdPosition; _currentInactiveBirdPosition += birdsInactiveOffset; _availableBaseBirds.Add(bird); } _lineRenderer = GetComponent <LineRenderer>(); GameManager.Instance.Register(this); }
private void Create() { #if DEBUG Debugger.Log(1, "Main", "Started initialization phase.\n"); #endif Rectangle window = new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); sky = new Sky(skyTex, window); yat = new Yat(yatClimbing, yatRunning, yatSmashing, yatFalling, snapEffect, window); BlockManager blockManager = new BlockManager(ground3Tex, ground2Tex, ground1Tex, ladder, window); level = new Level(blockManager, window); experience = new Experiencebar(yat, cage, xpBar, button14, new Vector2(50, window.Height - 50), new Resize(DockType.LowerLeft, new Vector2(cage.Width, cage.Height), new Vector2(25)), 0, 100, AmountType.AmountAndTotal); XPManager xpManager = new XPManager(yat, experience, xpOrb, xpEffect); MushroomFactory mgen = new MushroomFactory(mushroomSheet, fireballSheet, Mushroom.Size, level, yat, flameEffect, squashEffect, xpManager, window); CoinFactory cgen = new CoinFactory(level, yat, coin, coinEffect, window); BirdFactory bgen = new BirdFactory(level, yat, birdSheet, hawkEffect, xpManager, window); PotionManager pmanager = new PotionManager(yat, (Experiencebar)experience, new Texture2D[] { potionRed, potionGreen, potionBlue, potionYellow }, potionEffect, 20); yat.Init(level, pmanager); Plains hillzone = new Plains(ground3Tex, ground2Tex, ground1Tex, ladder, 2, 7, Rand.Next(10, 20), window); level.Init(new IFactory <ILevelObject>[] { cgen }, new IFactory <IEntity>[] { mgen, bgen }, new ITerrain[] { hillzone }); fpsCounter = new FPSCounter(new Vector2(10), new Resize(new Vector2(10)), window, button14, Color.Black); score = new Score(new Vector2(0, 10), new Resize(new Vector2(2, 0), new Vector2(0, 35)), window, button36, Color.Black); gameoverLabel = new Button(new Vector2(0, window.Height / 3), new Resize(new Vector2(2, 3), new Vector2(0, 0)), window, "Game over", button72, true, Color.Black, Color.Black, false, null, tint); mainMenuLabel = new Button(new Vector2(0, window.Height / 3 + 100), new Resize(new Vector2(2, 3), new Vector2(0, 100)), window, "Main menu", button36, true, Color.Black, Color.Red, true, new Request(0, 2, delegate() { Actions.Gameover = false; Score.Points = 0; })); soundButton = new ImageButton(new Vector2(window.Width - 50, 20), new Resize(DockType.UpperRight, new Vector2(soundLoud.Width, soundLoud.Height), new Vector2(50, 20)), new Action[] { delegate() { Settings.PlaySounds = false; MediaPlayer.IsMuted = true; }, delegate() { Settings.PlaySounds = true; MediaPlayer.IsMuted = false; } }, window, null, false, soundLoud, soundMute); playPauseButton = new ImageButton(new Vector2(window.Width - 120, 20), new Resize(DockType.UpperRight, new Vector2(pauseButton.Width, pauseButton.Height), new Vector2(120, 20)), new Request[] { new Request(1, 2), new Request(3, 2) }, window, 'P', true, pauseButton, playButton); healthbar = new Healthbar(yat, cage, healthBar, button14, new Vector2(window.Width - 200, window.Height - 50), new Resize(DockType.LowerRight, new Vector2(cage.Width, cage.Height), new Vector2(25)), Yat.health, Yat.health, AmountType.Percentage); clock = new Clock(button36, new Vector2(window.Width / 2, 75), new Resize(new Vector2(2, 0), new Vector2(0, 75)), Color.Black, window); gameplay = new Screen(1, new IButton[] { fpsCounter, score, clock, soundButton, playPauseButton, healthbar, experience }, new IObject[] { sky, level, yat }, gameplaySong, true); Button title = new Button(new Vector2(0, window.Height / 3), new Resize(new Vector2(2, 3), new Vector2(0)), window, "Yat Sprint", button72, true, Color.Black, Color.DimGray, false, null); Button play = new Button(new Vector2(0, window.Height / 3 + 100), new Resize(new Vector2(2, 3), new Vector2(0, 100)), window, "Play", button36, true, Color.Black, Color.DimGray, true, new Request(1, 1)); Button fullscreen = new Button(new Vector2(0, window.Height / 3 + 150), new Resize(new Vector2(2, 3), new Vector2(0, 150)), window, "Fullscreen", button36, true, Color.Black, Color.DimGray, true, new Request(-1, 1, delegate() { if (graphics.IsFullScreen) { graphics.PreferredBackBufferWidth = 800; graphics.PreferredBackBufferHeight = 600; graphics.ApplyChanges(); } else { graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; graphics.ApplyChanges(); } display.UpdateWindow(new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); Actions.ToggleFullscreen = true; })); Button exit = new Button(new Vector2(0, window.Height / 3 + 200), new Resize(new Vector2(2, 3), new Vector2(0, 200)), window, "Exit", button36, true, Color.Black, Color.DimGray, true, new Request(-1, 1, delegate() { Actions.Exitgame = true; })); Button motd = new Button(new Vector2(window.Width / 2 + 250, window.Width / 3 + 10), new Resize(new Vector2(2, 3), new Vector2(250, 25)), window, Messages[Rand.Next(Messages.Length)], button14, false, Color.Black, Color.Black, false, null); motd.SetRotation(Rand.Next(-45, -20)); titleScreen = new Screen(0, new IButton[] { fpsCounter, soundButton, title, motd, play, fullscreen, exit }, new IObject[] { sky }, mainmenuSong, true); gameover = new Screen(2, new IButton[] { fpsCounter, score, soundButton, gameoverLabel, mainMenuLabel }, new IObject[] { sky }, gameplaySong, true); Button pauseTitle = new Button(new Vector2(0, window.Height / 3), new Resize(new Vector2(2, 3), new Vector2(0)), window, "Paused", button72, true, Color.Black, Color.Black, false, null, tint); Button resumeButton = new Button(new Vector2(0, window.Height / 3 + 100), new Resize(new Vector2(2, 3), new Vector2(0, 100)), window, "Resume", button36, true, Color.Black, Color.Gray, true, new Request(1, 2)); Button mainMenuPause = new Button(new Vector2(0, window.Height / 3 + 150), new Resize(new Vector2(2, 3), new Vector2(0, 150)), window, "Main Menu", button36, true, Color.Black, Color.Gray, true, new Request(0, 2)); paused = new Screen(3, new IButton[] { fpsCounter, score, soundButton, playPauseButton, pauseTitle, resumeButton, mainMenuPause }, new IObject[] { sky }, gameplaySong, false); display = new Display(); display.Add(gameplay); display.Add(titleScreen); display.Add(gameover); display.Add(paused); MediaPlayer.Play(mainmenuSong); #if DEBUG Debugger.Log(1, "Main", "Finished initialization phase.\n"); #endif }
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); } }
public Engine() { birdFactory = new BirdFactory(); animals = new List <Animal>(); }