static void Main(string[] args) { Bird bird1 = new Sparrow(); bird1.PerformFly(); bird1.PerformSound(); Bird bird2 = new Duck(); bird2.PerformFly(); bird2.PerformSound(); Bird bird3 = new Canary(); bird3.PerformFly(); bird3.PerformSound(); bird3.SetFlyBehavior(new FlyNoWay()); bird3.SetSoundBehavior(new Mute()); bird3.PerformFly(); bird3.PerformSound(); Bird bird4 = new Penguin(); bird4.PerformFly(); bird4.PerformSound(); Console.WriteLine("End of program"); Console.ReadKey(); }
static void Main() { Tiger Amur = new Tiger(); Amur.protection_status(); Amur.color(); WhiteTiger Timur = new WhiteTiger(); Timur.protection_status(); Timur.color(); Kitten Mur = new Kitten(); Mur.protection_status(); Mur.color(); Mur.noise(); Mur.quantity = 3; Console.WriteLine("This quantity of kitten of white tiger is {0}", Mur.quantity); Goose Grey = new Goose(10); Grey.protection_status(); Grey.features(); Console.WriteLine(Grey.speed); Grey.swim(); Sparrow Captain = new Sparrow(); Captain.protection_status(); Captain.features(); Captain.speed = 7; Console.WriteLine("Speed of Captain is {0}", Captain.speed); Captain.food(); Captain.place(); Captain.swim(); Captain.size(); }
static void Main(string[] args) { Console.WriteLine("--------------| IS |--------------"); Sparrow sparrow = new Sparrow(); Console.WriteLine(sparrow is Bird); // true Console.WriteLine(sparrow is Sparrow); // true Console.WriteLine(sparrow is Blackbird); // false Console.WriteLine("***"); Bird sparrow2 = new Sparrow(); Console.WriteLine(sparrow2 is Bird); // true Console.WriteLine(sparrow2 is Sparrow); // true Console.WriteLine(sparrow2 is Blackbird); // false Console.WriteLine("--------------| AS |--------------"); Console.WriteLine(sparrow2 as Bird); // Sparrow-object Console.WriteLine(sparrow2 as Sparrow); // Sparrow-object Console.WriteLine(sparrow2 as Blackbird); // null Console.ReadLine(); }
static void Main(string[] args) { Animal animal = new Animal(); Animal bird = new Bird(); Animal blackbird = new Blackbird(); Animal sparrow = new Sparrow(); animal.MakeSound(); bird.MakeSound(); blackbird.MakeSound(); sparrow.MakeSound(); Console.WriteLine("-------------------------"); Bird blackbird2 = new Blackbird(); Bird sparrow2 = new Sparrow(); blackbird2.MakeSound(); sparrow2.MakeSound(); ///* This gives an error, you can't assign classes as its siblings, only parents. */ //Blackbird sparrow3 = new Sparrow(); Console.ReadLine(); }
void itemImgSetter(int val, string imgPath) { switch (val) { case 0: Gun1.Load(imgPath); break; case 1: Gun2.Load(imgPath); break; case 2: Gun3.Load(imgPath); break; case 3: Head.Load(imgPath); break; case 4: Arms.Load(imgPath); break; case 5: Chest.Load(imgPath); break; case 6: Legs.Load(imgPath); break; case 7: ClassArmour.Load(imgPath); break; case 8: Ghost.Load(imgPath); break; case 9: Sparrow.Load(imgPath); break; case 10: Ship.Load(imgPath); break; case 11: SubClass.Load(imgPath); break; case 13: Embelm.Load(imgPath); break; } }
static void Main(string[] args) { List <Sparrow> sparrows = new List <Sparrow>(); Sparrow charlie = new Sparrow() { Name = "Charlie" }; //new Sparrow().Fly(); sparrows.Add(new Sparrow() { Name = "Alpha" }); sparrows.Add(new Sparrow() { Name = "Bravo" }); sparrows.Add(new Sparrow() { Name = "Delta" }); sparrows.Add(new Sparrow() { Name = "Echo" }); Console.WriteLine("Loop 1"); foreach (Sparrow sparrow in sparrows) { Console.WriteLine(sparrow.Name); } Console.WriteLine(); Console.WriteLine("Loop 2"); sparrows.Insert(2, charlie); foreach (Sparrow sparrow in sparrows) { Console.WriteLine(sparrow.Name); } Console.WriteLine(); Console.WriteLine($"Index of charlie = {sparrows.IndexOf(charlie)}"); Console.WriteLine(); Console.WriteLine($"sparrows contains {sparrows.Count} elements."); Console.WriteLine(); Console.WriteLine($"sparrows contains charlie = {(sparrows.Contains(charlie))}"); Sparrow[] sparrowArray = sparrows.ToArray(); }
static void Main(string[] args) { Sparrow dataBreakpointDemo = new Sparrow() { Name = "BreakpointDemo", Weight = 100.0 }; // TODO: Add more sparrows to dictionary Dictionary <string, Sparrow> dictionary = new Dictionary <string, Sparrow>(); dictionary.Add("Alpha", new Sparrow() { Name = "Alpha", Weight = 1.0 }); dictionary.Add("Bravo", new Sparrow() { Name = "Bravo", Weight = 2.0 }); dictionary.Add("Charlie", new Sparrow() { Name = "Charlie", Weight = 3.0 }); dictionary.Add("Delta", new Sparrow() { Name = "Delta", Weight = 4.0 }); dictionary.Add("Echo", new Sparrow() { Name = "Echo", Weight = 5.0 }); dictionary.Add("Foxtrot", new Sparrow() { Name = "Foxtrot", Weight = 6.0 }); Console.WriteLine(dataBreakpointDemo.Name); dataBreakpointDemo.Name = "test"; //PrintItemsInDictionary(dictionary); // PrintNameAndWeight(dictionary["Echo"]); Console.WriteLine(dataBreakpointDemo.Name); // TODO: Count more numbers /* * int x = 2; * * do * { * x = AddTwo(x); * } while (x < 1000); */ }
static void Main(string[] args) { Bird sparrow = new Sparrow(); Console.WriteLine((Sparrow)sparrow); // Sparrow-object Console.WriteLine((Blackbird)sparrow); // InvalidCastException Console.ReadLine(); }
/// <summary> /// 继承父类中的方法 /// </summary> public static void Folder1() { Bird sparrow = new Sparrow(); sparrow.Name = "麻雀"; Console.WriteLine($"{sparrow.GetName()}可以飞行{sparrow.Fly(10)}公里"); Bird wildGoose = new WildGoose(); wildGoose.Name = "大雁"; Console.WriteLine($"{wildGoose.GetName()}可以飞行{wildGoose.Fly(10)}公里"); }
static void Main(string[] args) { Parrot p = new Parrot(); Sparrow s = new Sparrow(); Penguin pe = new Penguin(); List <Bird> birds = new List <Bird>(); birds.Add(p); birds.Add(s); birds.Add(pe); foreach (Bird bird in birds) { bird.Fly(); bird.Run(); } Console.ReadLine(); }
public static void Perform() { IBird _sparrow = new Sparrow(); IToyDuck _toyDuck = new PlasticToyDuck(); // Wrap a bird in a birdAdapter so that it // behaves like toy duck IToyDuck _birdAdapter = new BirdAdapter(_sparrow); Console.WriteLine("Sparrow..."); _sparrow.Fly(); _sparrow.MakeSound(); Console.WriteLine("Toy Duck"); _toyDuck.Squeak(); // bird behaving like a toy duck Console.WriteLine("BirdAdapter..."); _birdAdapter.Squeak(); Console.WriteLine(); }
static void Main(string[] args) { Dictionary <string, Sparrow> dictionary = new Dictionary <string, Sparrow>(); dictionary.Add("Alpha", new Sparrow() { Name = "Alpha", Weight = 1.0 }); dictionary.Add("Bravo", new Sparrow() { Name = "Bravo", Weight = 2.0 }); dictionary.Add("Charlie", new Sparrow() { Name = "Charlie", Weight = 3.0 }); string key; do { Console.Write("Enter name of sparrow: "); key = Console.ReadLine(); if (dictionary.ContainsKey(key)) { Sparrow sparrow = dictionary[key]; Console.WriteLine($"{sparrow.Name} weights {sparrow.Weight} kg."); sparrow.ClimbThroughSmallHole(); } else if (key != "") { Console.WriteLine("Can not find sparrow in dictionary!"); } } while (key != ""); Console.WriteLine(); Console.WriteLine("Items in dictionary:"); foreach (KeyValuePair <string, Sparrow> keyValuePair in dictionary) { Console.WriteLine($"{keyValuePair.Key} = {keyValuePair.Value.Weight}"); } }
static void Main(string[] args) { IBird[] birds = new IBird[rand.Next(10, 20)]; for (int i = 0; i < birds.Length; i++) { IBird bird = null; var nextRand = rand.Next(0, 30); if (nextRand > 20) { bird = new Eagle(); } else if (nextRand > 10) { bird = new Lark(); } else { bird = new Sparrow(); } bird.CurrentSpeed = rand.Next(10, (int)bird.MaxSpeed - 1) + rand.NextDouble(); birds[i] = bird; } foreach (IBird bird in birds) { Console.WriteLine("=============================================================================="); try { var speedAcceleration = rand.Next(1, 100); Console.WriteLine("Current speed for {0} is {1}, the wind speed is {2}", bird.Name, bird.CurrentSpeed, speedAcceleration); bird.FlyWithinWind(speedAcceleration); Console.WriteLine("After windy weather the bird is Alive"); } catch (BirdFlewAwayException ex) { Console.WriteLine(ex.Message); } } Console.ReadLine(); }
static void Main(string[] args) { AnimalService animalService = new AnimalService(); #region Domain Models instantation Animal ace = new Animal("Ace", "green", true); // Create an object with constructor Animal stojan = new Animal("Stojan", "yellow", true); Animal mirce = new Animal() { Spicies = "Mirce", EyeColor = "green", CanSwim = true }; // Create an object in shorter way Cat bozana = new Cat(); // Cat inherits from class Animal Bird slave = new Bird("slavejce", "black", "white", false, true); // Bird inherits from class Animal Sparrow goran = new Sparrow("goran", "white", "awesome", "blue", true); Sparrow dejan = new Sparrow(); // Sparrow inherits from class Bird #endregion Console.WriteLine(animalService.GetInfo(mirce)); Console.WriteLine(animalService.GetInfo(ace)); Console.WriteLine(animalService.GetInfo(stojan)); mirce.Eat(); bozana.Eat(); // bozana is a Cat object but, the Eat methods belongs to Animal class, TIP: use hover on the Eat method for more information //rename and override Meow method bozana.MakeSound(); // bozana is a Cat object and the Meow method belongs to Cat class Tiger johny = new Tiger(); johny.MakeSound(); WhiteTiger jacky = new WhiteTiger(); jacky.MakeSound(); jacky.MakeATigerSound(); Console.WriteLine(slave.Wings); Console.Read(); }
static void Main(string[] args) { Stack <Sparrow> stack = new Stack <Sparrow>(); Sparrow alpha = new Sparrow() { Name = "Alpha", Weight = 1.0 }; Sparrow bravo = new Sparrow() { Name = "Bravo", Weight = 2.0 }; Sparrow charlie = new Sparrow() { Name = "Charlie", Weight = 3.0 }; Console.WriteLine($"Push {alpha} on top of the stack!"); stack.Push(alpha); Console.WriteLine($"Push {bravo} on top of the stack!"); stack.Push(bravo); Console.WriteLine($"Pop {bravo} from top of the stack!"); Sparrow topSparrow = stack.Pop(); Console.WriteLine($"{topSparrow} was removed from top of the stack!"); Console.WriteLine($"Push {charlie} on top of the stack!"); stack.Push(charlie); Console.WriteLine(); Console.WriteLine($"There is {stack.Count} sparrows on the stack:"); foreach (Sparrow sparrow in stack) { sparrow.Fly(); } }
static void Main(string[] args) { Queue <Sparrow> queue = new Queue <Sparrow>(); Sparrow alpha = new Sparrow() { Name = "Alpha", Weight = 1.0 }; Sparrow bravo = new Sparrow() { Name = "Bravo", Weight = 2.0 }; Sparrow charlie = new Sparrow() { Name = "Charlie", Weight = 3.0 }; Console.WriteLine($"{alpha} steps into the queue!"); queue.Enqueue(alpha); Console.WriteLine($"{bravo} steps into the queue!"); queue.Enqueue(bravo); Console.WriteLine($"{charlie} steps into the queue!"); queue.Enqueue(charlie); Sparrow serveFirst = queue.Dequeue(); serveFirst.Eat(); Console.WriteLine(); Console.WriteLine("The other sparrows in the queue dont get to eat! :("); foreach (Sparrow sparrow in queue) { sparrow.Fly(); } }
static void Main(string[] args) { Parrot parrot1 = new Parrot(34); parrot1.Eat(); parrot1.Fly(); parrot1.Talk("Hello there!"); parrot1.Talk(); Console.WriteLine(); Sparrow sparrow1 = new Sparrow() { Name = "Tom", Weight = 1.5 }; sparrow1.Eat(); sparrow1.Fly(); sparrow1.ClimbThroughSmallHole(); Parrot parrot2 = new Parrot(15) { Name = "Pelle", Weight = 45.6 };; Parrot parrot3 = new Parrot(15) { Name = "Anna", Weight = 235.6 };; Sparrow sparrow2 = new Sparrow() { Name = "Mats", Weight = 23.4 };; Bird[] birds = { parrot1, parrot2, sparrow1, parrot3, sparrow2 }; Console.WriteLine(); Console.WriteLine("Bird array:"); Console.WriteLine(); foreach (Bird bird in birds) { bird.Eat(); if (bird is Parrot) { Parrot temporaryParrot = (Parrot)bird; //(bird as Parrot).Talk(); temporaryParrot.Talk(); temporaryParrot.Fly(); } else { Console.WriteLine($"{bird.Name} can not talk!"); } } Console.WriteLine(); foreach (Bird bird in birds) { bird.Die(); } }
override protected void ActivateWithPass(int pass, Sparrow.Textures.Texture texture, Sparrow.Geom.Matrix mvpMatrix) { if (_colorMatrixDirty) { UpdateShaderMatrix(); } GL.UseProgram(_shaderProgram.Name); Matrix4 mvp = mvpMatrix.ConvertToMatrix4(); GL.UniformMatrix4(_uMvpMatrix, false, ref mvp); GL.UniformMatrix4(_uColorMatrix, false, ref _shaderMatrix); GL.Uniform4(_uColorOffset, ref _shaderOffset); }
static void Main(string[] args) { try { Console.Title = "ТАРАКАНИЩЕ"; Console.WriteLine(" ТАРАКАНИЩЕ\r\n"); Console.WriteLine("Created by Koleso\nStory by Chykovskiy"); Console.WriteLine(); Медведь bears = new Медведь(); Console.WriteLine(bears); bears.Move(); Console.WriteLine(); Кот cat = new Кот(); Console.WriteLine(cat); cat.Move(); Console.WriteLine(); Комар mosquito = new Комар(); Console.WriteLine(mosquito); mosquito.Move(); Console.WriteLine(); ак crayfish = new ак(); Console.WriteLine(crayfish); crayfish.Speak(); crayfish.Move(); Console.WriteLine(); Волк wolf = new Волк(); Console.WriteLine(wolf); wolf.Move(); Console.WriteLine(); Лев lion = new Лев(); Console.WriteLine(lion); lion.Move(); Console.WriteLine(); Заяц hare = new Заяц(); Console.WriteLine(hare); hare.Move(); Console.WriteLine(); Жаба frog = new Жаба(); Console.WriteLine(frog); frog.Move(); Console.WriteLine(); Герои.Smile(); Герои.Eat(); Таракан roach = Таракан.Instance; Console.WriteLine(roach.Places); Console.WriteLine(roach.Types); Console.WriteLine(roach); roach.Growl(); roach.Shout(); roach.Stir(); roach.Speak(); Console.WriteLine(); Герои.frighten(); Console.WriteLine(frog); frog.FrightSpeak(); Console.WriteLine(); Console.WriteLine(wolf); wolf.FrightSpeak(); Console.WriteLine(); Console.WriteLine(crayfish); crayfish.FrightSpeak(); Console.WriteLine(); Sparrow obj10 = new Sparrow(); Console.WriteLine(); Console.WriteLine(); obj10.Speak(); obj10.Kill(); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }