protected Duck() { _fly = new FlyClass(); _quack = new QuackClass(); _walk = new WalkClass(); _swim = new SwimClass(); }
public Duck(Idisplay display, ISwim swim, IFly fly, IKuak kuak) : this(display, swim, fly) { if (kuak != null) { _kuak = kuak; } }
static void Main(string[] args) { Duck d = new Duck(); //Duck对象d可以使用3种方法: //1.自身定义的; //2.父类定义的 //3.接口定义的 d.Fly(); d.Cook(); d.Swim(); //将子类(Duck)对象赋给基类变量 Bird b = d; //现在只能使用基类定义的Fly()方法 b.Fly(); //将Duck对象赋给ISwin接口变量 ISwim s = d; //现在只能使用接口定义的Swim()方法 s.Swim(); //将Duck对象赋给另一个实现的接口IFood接口变量 IFood f = d; //现在只能使用接口定义的Cook()方法 f.Cook(); Console.ReadKey(); }
public Duck(IFly f, IQuack q, IWalk w, ISwim s) { _fly = f; _quack = q; _walk = w; _swim = s; }
public TurkeyCock(IFly f, ICluck c, IWalk w, ISwim s) { _fly = f; _cluck = c; _walk = w; _swim = s; }
protected BaseDuck(IFly fly, IQuack quack, ISwim swim, IWalk walk, IName name) { _fly = fly; _quack = quack; _swim = swim; _walk = walk; _name = name; }
protected BaseTurkey(IFly fly, IGobble gobble, ISwim swim, IWalk walk, IName name) { _fly = fly; _gobble = gobble; _swim = swim; _walk = walk; _name = name; }
public void addPredators(ISwim pred) { Coordinate empty; for (int i = 0; i < NumPredator; i++) { empty = LogicMove.getEmptyCellCoord(this); cells[empty._y, empty._x] = new Predator(empty, pred); } }
public void addPrey(ISwim prey) { Coordinate empty; for (int i = 0; i < NumPrey; i++) { empty = LogicMove.getEmptyCellCoord(this); cells[empty._y, empty._x] = new Prey(empty, prey, Prey.TIME_TO_REPRODUCE); } }
void Act(GameObject animal) { switch (input) { case InputType.LMB: { ISpeak speak = animal.GetComponent <ISpeak>(); if (speak != null) { speak.Speak(); speakCount++; } break; } case InputType.RMB: { IWalk walk = animal.GetComponent <IWalk>(); if (walk != null) { walk.Walk(); walkCount++; } break; } case InputType.Space: { ISwim swim = animal.GetComponent <ISwim>(); if (swim != null) { swim.Swim(); swimCount++; } break; } case InputType.I: { IID id = animal.GetComponent <IID>(); if (id != null) { id.Identify(); } break; } default: break; } }
public Duck(Idisplay display, ISwim swim, IFly fly) { if (display != null) { _display = display; } if (swim != null) { _swim = swim; } if (fly != null) { _fly = fly; } }
//public delegate TResult Func<in T, out TResult>(T arg); /// <summary> /// Отримати всі ТЗ які вміють плавати /// </summary> /// <param name="arrVehicle">Масив транспортних засібів</param> /// <param name="arrProcess">Масив ТЗ які плавають</param> public static void GetISwimFromArrVeh(CVehicle[] arrVehicle, out ISwim[] arrProcess) { //List<ISwim> newList = new List<ISwim>().Add(arrVehicle.Where(x => x is IFly)); ISwim[] masSwim = new ISwim[arrVehicle.Length]; int i = 0; foreach (var item in arrVehicle) { if (item is ISwim) { masSwim[i++] = item as ISwim; } } Array.Resize(ref masSwim, i); arrProcess = masSwim; }
/// <summary> /// This method shows an example of interface methods being implemented /// </summary> public static void WeCanSwim() { ISwim[] swim = new ISwim[2]; // Creating new Hippo Objects Hippo hiphop = new Hippo() { Name = "Hippy the Hippo", HoldBreathAmount = 5 }; Dolphins dolphins = new Dolphins() { Name = "Fin", HoldBreathAmount = 10 }; swim[0] = hiphop; swim[1] = dolphins; // for loop that will loop through the swim array and will call the interface methods that are //implemented in the classes for (int i = 0; i < swim.Length; i++) { var aniSwimming = swim[i]; if (aniSwimming is Hippo) { var h = (Hippo)aniSwimming; Console.WriteLine($"My name is {h.Name} and I can hold my breath for {h.HoldBreathAmount} minutes!"); Console.WriteLine(h.WiggleBody()); Console.WriteLine(h.Float()); Console.ReadLine(); } else if (aniSwimming is Dolphins) { var d = (Dolphins)aniSwimming; Console.WriteLine(); Console.WriteLine($"Hi! My name is {d.Name}!"); Console.WriteLine(d.WiggleBody()); Console.WriteLine(d.Float()); Console.ReadLine(); } } }
private void FixedUpdate() { if (listPlayerCollision != null) { foreach (GameObject playerCollider in listPlayerCollision) { if (playerCollider) { RaycastHit info; Vector3 origin = playerCollider.transform.position; origin.y += 3; bool isTrigger = Physics.Raycast(origin, Vector3.down, out info, 10, 1 << LayerMask.NameToLayer(R.S.Layer.Water)); Debug.DrawRay(origin, Vector3.down, Color.red); if (isTrigger) { ISwim actorController = playerCollider.GetComponent <PlayerController>(); if (actorController == null) { actorController = playerCollider.GetComponentInParent <ActorAI>(); } if (actorController != null && actorController.IsSwimming == false) { actorController.IsSwimming = true; } } else { ISwim actorController = playerCollider.GetComponent <PlayerController>(); if (actorController == null) { actorController = playerCollider.GetComponentInParent <ActorAI>(); } if (actorController != null && actorController.IsSwimming) { actorController.IsSwimming = false; } } } } } }
static void Main(string[] args) { Duck duck = new Duck(); duck.Fly(); duck.Swim(); duck.Cook(); Bird bird = duck; bird.Fly(); //将Duck对象赋给ISwin接口变量 ISwim s = duck; //只会游泳 s.Swim(); //将Duck对象赋给另一个实现的接口IFood接口变量 IFood food = duck; //只会Cook food.Cook(); Console.ReadKey(); }
public Duck(IFly fly, IQuack quack, ISwim swim) : base(fly, quack, swim) { }
public void Welcome(ISwim obj) => obj.Swim();
protected BaseDuck(IFly fly, IQuack quack, ISwim swim) { _fly = fly; _quack = quack; _swim = swim; }
public Bird(IFly flyBehaviour, ISpeak speakBehaviour, ISwim swimBehaviour) { FlyBehaviour = flyBehaviour; SpeakBehaviour = speakBehaviour; SwimBehaviour = swimBehaviour; }
public NoIoC() { Run = new Sprint(); RideBike = new RideRoadBike(); Swim = new FreeStyleSwim(); }
public Duck(IFly flyBehaviour, ISwim swimBehaviour, IWalk walkBehaviour) { _flyBehaviour = flyBehaviour; _swimBehaviour = swimBehaviour; _walkBehaviour = walkBehaviour; }
public void initCells(ISwim prey, ISwim pred) { addObstacles(); addPredators(pred); addPrey(prey); }
public BaseDuck(IFly fly, IQuack quack, ISwim swim) { _fly = fly; _quack = quack; _swim = swim; }
static void Main(string[] args) { Human stud1 = new Student("Vasya", 1); Human doc1 = new Doctor("Aybolit", 66); Human fight1 = new Fighter("Bruce Lee", 100); /*Console.WriteLine(stud1); * stud1.Eat(); * //stud1.Study(); * * Console.WriteLine(doc1); * doc1.Eat(); * //doc1.Cure(); * * Console.WriteLine(fight1); * fight1.Eat(); * //fight1.Fight();*/ //PeopleFactory pf = new PeopleFactory(); Human[] masHuman = new Human[5]; /*for (int i = 0; i < masHuman.Length; i++) * { * masHuman[i] = pf.NextHuman(); * }*/ masHuman[0] = stud1; masHuman[1] = doc1; masHuman[2] = fight1; masHuman[3] = new VetDoctor("House", 666, "Cat"); masHuman[4] = new Doctor("Semenov", 33); int iDoc = -1; Doctor[] masDoc = new Doctor[5]; ISwim[] masSwim = new ISwim[3]; int iSwim = -1; masSwim[++iSwim] = new Dog(); Console.WriteLine("--------------------------"); for (int i = 0; i < masHuman.Length; i++) { if (masHuman[i] is ISwim) { masSwim[++iSwim] = masHuman[i] as ISwim; Console.WriteLine("Swim = " + masSwim[i]); } if (masHuman[i] is Doctor) { //Doctor doc = (Doctor)masHuman[i]; Doctor doc = masHuman[i] as Doctor; Console.WriteLine(doc.IdLicense); masDoc[++iDoc] = doc; } Doctor doc2 = masHuman[i] as Doctor; if (doc2 != null) { Console.WriteLine(doc2.IdLicense); } if (masHuman[i].GetType().Name == "Doctor") { Console.WriteLine("doc................."); } //Console.WriteLine(masHuman[i]); masHuman[i].print(); } Console.WriteLine("--------------------------"); Array.Resize(ref masDoc, iDoc + 1); Console.WriteLine(masDoc.Length); for (int i = 0; i < masDoc.Length; i++) { if (masDoc[i] == null) { continue; } Console.WriteLine(masDoc[i]); } for (int i = 0; i < masSwim.Length; i++) { //if (masDoc[i] == null) continue; Console.WriteLine(masSwim[i]); } int[] mas = { 1, 2, 3, 22, 7, 8, 3, 6, 8, 5 }; Array.Sort(mas); foreach (var item in mas) { Console.WriteLine(item); } Array.Sort(masHuman); foreach (var item in masHuman) { Console.WriteLine(item); } }
public Prey(Coordinate coo, ISwim iPrey, int timeToReproduce) : this(coo, timeToReproduce) { _swim = iPrey; }
public CustomDuck(IFly _fly, IQuack _quack, ISwim _swim) { flyAction = _fly; quackAction = _quack; swimAction = _swim; }
public void Swim(ISwim swim) { Console.WriteLine("Person lives " + this.GetType().Name + " swim in " + swim.GetType().Name); swim.Swim(); }
public Bird(IFly flyBehaviour, ISpeak speakBehaviour, ISwim swimBehaviour) { FlyBehaviour = flyBehaviour; SpeakBehaviour = speakBehaviour; SwimBehaviour = swimBehaviour; }
public Predator(Coordinate coo, ISwim iPredator, int timeToFeed = TIME_TO_FEED) : this(coo, Prey.TIME_TO_REPRODUCE) { _swim = iPredator; }
public Turkey(IFly fly, ISwim swim, ICackle cackle) { _fly = fly; _swim = swim; _cackle = cackle; }
public InjectByConstructor(IRun run, IRideBike rideBike, ISwim swim) { this.Run = run; this.RideBike = rideBike; this.Swim = swim; }
public bool Swim(ISwim swim) { return(true); }