static void Main(string[] args) { Eagle orzelPrawdziwy = new Eagle(); //orzelPrawdziwy.Hello(); var orzełJednakPtak = (Bird)orzelPrawdziwy; //orzełJednakPtak.Hello(); IFlyable orzel = new Eagle(); //orzel.Fly(); IFlyable[] ptaki = new IFlyable[2]; ptaki[0] = new Eagle(); ptaki[1] = new Duck(); ptaki[1].Fly(); ptaki[0].Fly(); var pingwinPingwin = new Penguin(); pingwinPingwin.Swim(); var pingwinPtak = (ISwimmable) new Penguin(); pingwinPtak.Swim(); }
public AnimalBase(string name) { _name = name; walkingBehavior = new NoWalk(); swimmingBehavior = new NoSwim(); flyingBehavior = new NoFly(); }
static void Main(string[] args) { IVehicle[] vehicles = new IVehicle[] { new Car(), new Plane() }; IFlyable[] thingsThatFly = new IFlyable[] { new Plane(), new Bird() }; Console.WriteLine("Iterating through vehicles"); foreach (var v in vehicles) { v.Move(); } Console.WriteLine("Iterating through thingsThatFly"); foreach (var t in thingsThatFly) { t.Fly(); } Console.ReadLine(); }
static void Main(string[] args) { FlyingCar car = new FlyingCar(); car.Run(); car.Fly(); car.Company = "현대"; IRunnable runnable = car as IRunnable; runnable.Run(); IFlyable flyable = car as IFlyable; flyable.Fly(); TestClass t = new TestClass(); t.Run(); IWalkable w = t as IWalkable; w.Run(); IRunnable r = t as IRunnable; r.Run(); }
static void Main(string[] args) { IVehicle[] vehicles = new IVehicle[] { new Car(), new Plane() }; IFlyable[] flyingThings = new IFlyable[] { new Plane(), new Bird() }; Console.WriteLine("Iterating through vehicles"); foreach (var v in vehicles) { v.Move(); } Console.WriteLine("Iterating through flying things"); foreach (var f in flyingThings) { f.Fly(); } }
public static void GoToFlightSchool(IFlyable flyingStudent) { Console.Write(flyingStudent.ToString()); Console.WriteLine(" says:"); flyingStudent.Fly(); Console.WriteLine(); }
public Animal(string name, int weight, int age, string color, IFlyable flyBehaviour) { Name = name; this.Weight = weight; this.Age = age; this.color = color; FlyBehaviour = flyBehaviour; }
public Duck(string name, IFlyable flyBehavior, IQuackable quackBehavior) { this.Name = name; this._flyBehavior = flyBehavior; this._quackBehavior = quackBehavior; this.Display(); }
void MakeFlight(IFlyable dingetje) { dingetje.LiftOff(); dingetje.Fly(); dingetje.Fly(); dingetje.Fly(); dingetje.Land(); Console.WriteLine(); }
static void Main(string[] args) { IFlyable[] participants = new IFlyable[] { new Bird(), new Plane() }; foreach (var item in participants) { item.Fly(); } Console.ReadKey(); }
void OnCollisionEnter(Collision collsion) { IFlyable ifly = collsion.collider.GetComponent <IFlyable>(); if (ifly != null) { ifly.flyingStrategy = gameObject.GetComponent <FlyRocket>(); Destroy(this); } }
public Duck 裝上可飛行的道具(Object obj) { if (obj is IFlyable) { FlyBehavior = obj as IFlyable; } else { Console.WriteLine("裝備的物件,不具有飛行能力,無法安裝"); } return(this); }
static void Main(string[] args) { IFlyable[] flyables = new IFlyable[4]; flyables[0] = new Bird("Pinguin", false); flyables[1] = new Plane("Airbus", 7500); flyables[2] = new Plane(); flyables[3] = new Bird(); foreach (IFlyable flyable in flyables) { flyable.Fly(); } Console.ReadKey(); }
static void Main(string[] args) { FlyingCar car = new FlyingCar(); car.Run(); car.Fly(); IRunnable runnble = car as IRunnable; IFlyable flyable = car as IFlyable; runnble.Run(); flyable.Fly(); }
public override void Fly(Animal animal) { if (fuel.fuelLevel > 0f) { fuel.fuelLevel -= 10f * Time.deltaTime; rigidBody.AddForce(Vector3.forward * 2f, ForceMode.VelocityChange); } else { ifly.flyingStrategy = new FlyNone(); ifly = null; } }
public override bool IsMovable(IBody obj) { if (obj is IFlyable) { IFlyable flyable = (IFlyable)obj; if (flyable.FlyingHeight > _height) { flyable.Fly(); } } return(false); }
public MainWindow() { InitializeComponent(); SuperHero s = new SuperHero() { FirstName = "Max", MiddleName = "A", LastName = "Million" }; SuperHero s1 = new SuperHero(); s1.FirstName = "Max"; s1.MiddleName = "A"; s1.LastName = "Million"; tbOutput.Text = string.Format("{0} {1}\r\n", s.Flies(), s); IFlyable flyer = new SuperHero(); IFlyable nFly = new Jet(2); IFlyable[] flyers = new IFlyable[6]; flyers[0] = new Jet(5); flyers[1] = new SuperHero(); flyers[2] = flyer; flyers[3] = flyers[2]; flyers[4] = nFly; flyers[5] = s.CloneMe(); foreach (IFlyable f in flyers) { tbOutput.Text += string.Format("{0} {1}\r\n", f.Flies(), f); } Jet ourJet = new Jet(2); Person p = new SuperHero("Bat", "Man"); String b = ourJet + p; Person pt = new Villian() { FirstName = "Joker" }; String c = ourJet + pt; Person ph = new SuperHero("Wonder", "Woman"); String d = ourJet + ph; int a = 1 + 2; }
static void Main(string[] args) { Flyingcar a = new Flyingcar(); a.run(); a.fly(); IRunnable b = a as IRunnable; b.run(); IFlyable c = a as IFlyable; c.fly(); }
static void Main(string[] args) { FlyingCar clsCar = new FlyingCar(); clsCar.Fly(); clsCar.Run(); IRunnable iRunable = clsCar as IRunnable; iRunable.Run(); IFlyable iFlyable = clsCar as IFlyable; iFlyable.Fly(); }
static void Main(string[] args) { FlyingCar car = new FlyingCar(); car.Run(); car.Fly(); IRunnable runnable = car as IRunnable; // 강제 형변환 as를 통해 car(class FlyingCar, IRunnable, IFlyable)을 // IRunnable로 변환시킨다. runnable.Run(); IFlyable flyable = car as IFlyable; // as를 통해 car(IRunnable)을 flyable.Fly(); // IFlyable로 변환시킨다. }
static void Main(string[] args) { FlyingCar car = new FlyingCar(); car.Run(); car.Fly(); car.Company = "현대"; IRunnable runnable = car; // as IRunnable; 생략 가능 runnable.Run(); IFlyable flyable = car; // as IFlyable; 생략 가능 flyable.Fly(); }
static void Main(string[] args) { FlyingCar car = new FlyingCar(); car.Run(); car.Fly(); car.Company = "현대"; IRunnable runnable = car as IRunnable; //형변환, 형변환 안되면 null값 들어감 runnable.Run(); IFlyable flyable = car as IFlyable; flyable.Fly(); }
static void MultiInterfaceInheritance() { WriteLine("\nMultiInterfaceInheritance()"); FlyingCar car = new FlyingCar(); car.Run(); car.Fly(); IRunnable runnable = car as IRunnable; runnable.Run(); IFlyable flyable = car as IFlyable; flyable.Fly(); }
static void Main(string[] args) { // // OLD MACDONALD // List <ISingAbout> animals = new List <ISingAbout>(); animals.Add(new Horse()); animals.Add(new Elephant()); animals.Add(new Dragon()); animals.Add(new Tractor()); FarmAnimal flyingThing = new Dragon(); IFlyable trogdor = GetFlyingThing(); foreach (ISingAbout item in animals) { SingAbout(item); } /* * * // Let's try singing about a Farm Animal * FarmAnimal animal = new Horse(); * SingAbout(animal); * * // Horse horse = (Horse)animal; * // horse.Gallop(); * * Elephant elephant = new Elephant(); * SingAbout(elephant); * * Dragon dragon = new Dragon(); * SingAbout(dragon); * // Same thing as: SingAbout(new Dragon()); */ // What if we wanted to sing about other things on the farm that were // singable but not farm animals? // Can it be done? Console.ReadLine(); }
static void Main(string[] args) { IFormattableLogger logger = new ConsoleLogger2(); logger.WriteLog("{0} + {1} = {2}", 1, 1, 2); FlyingCar car = new FlyingCar(); car.Run(); car.Fly(); IRunnable runnable = car as IRunnable; IFlyable flyable = car as IFlyable; runnable.Run(); flyable.Fly(); }
static void Main(string[] args) { // 다중 상속받은 클래스 FlyingCar car = new FlyingCar(); car.Run(); car.Fly(); car.Company = "현대"; // 부모 인터페이스 // 부모연산자인 IRunnable에 as 연산자를 사용하여 자식 클래스인 car에 캐스팅 하였다. IRunnable runnable = car as IRunnable; runnable.Run(); IFlyable flyable = car as IFlyable; flyable.Fly(); }
static void Main(string[] args) { FlyingCar car = new FlyingCar(); car.Run(); car.Fly(); // this car can't fly IRunnable runnable = car as IRunnable; runnable.Run(); // this car can't run IFlyable flyable = car as IFlyable; flyable.Fly(); return; }
static void Main(string[] args) { FlyingCar car = new FlyingCar(); car.Run(); car.Fly(); IRunnable runnable = car as IRunnable; runnable.Run(); IFlyable flyable = car as IFlyable; flyable.Fly(); car.Company = "Naver"; car.HorsePower = 12.4f; car.Year = 1234; WriteLine($"{car.Company} {car.HorsePower} {car.Year}"); }
void Freeze() { GameObject tempFly; for (int j = 0; j < flyTab.Count; j++) { tempFly = flyTab[j] as GameObject; IFlyable component = (IFlyable)tempFly.GetComponent(typeof(IFlyable)); component.Freeze(); } for (int k = 0; k < enemieTab.Count; k++) { tempFly = enemieTab[k] as GameObject; IFlyable component = (IFlyable)tempFly.GetComponent(typeof(IFlyable)); component.Freeze(); } timer.GetComponent <Timer> ().PauseTimer(); tongue.GetComponent <Tongue>().Pause(); }
static void Main(string[] args) { FlyingCar car = new FlyingCar(); car.Run(); car.Fly(); IRunnable runnable = car as IRunnable; runnable.Run(); IFlyable flyable = car as IFlyable; flyable.Fly(); MyVehicle myVehicle = new MyVehicle(); myVehicle.car.Run(); myVehicle.plane.Fly(); }
public void SetFlyBehaviour(IFlyable newFlyBehaviour) { flyBehaviour = newFlyBehaviour; }
public DuckBase() { flyBehaviour = new FlyWithWings(); quackBehaviour = new SimpleQuack(); }