static void Main() { var donald = new Duck(); var josh = new Person(); InTheForest(donald); InTheForest(josh); }
static void Main() { Console.WriteLine("before creating the first duck"); Duck Phillip = new Duck(3.5); Console.WriteLine("before creating the second duck"); Duck Harry = new Duck(4.2); }
void Awake () { inputState = GetComponent<InputState> (); walkBehaviour = GetComponent<Walk> (); duckBehaviour = GetComponent<Duck> (); animator = GetComponent<Animator> (); collisionState = GetComponent<CollisionState> (); }
static void Main(string[] args) { Animal duck=new Duck(); Duck duck2= new Duck(); Console.WriteLine("duck 1 walking:"); duck.Walk(); Console.WriteLine("duck 2 walking:"); duck2.Walk(); Console.WriteLine("duck 2 eating:"); duck2.Eat(); duck2.Eat("pizza"); //apeleaza metoda din clasa de baza Console.WriteLine("duck 3 eating:"); Animal duck3 = duck2; duck3.Eat(); Console.WriteLine("Cat walking:"); var cat = new Cat { Age = 10 }; cat.Walk(); Console.WriteLine("Cat's age:"); Console.WriteLine(cat.Age); Console.ReadLine(); }
public DuckAdapter(Duck duck) { this.duck = duck; }
static void Main(string[] args) { Ninja n = new Ninja(25, "Andrew"); Duck d = new Duck(10, "Programmer"); List<IAttack> atl = new List<IAttack>(); for (int i = 0; i < 5; i++) { atl.Add(n); atl.Add(d); } foreach (IAttack aia in atl) { aia.Fight(); } foreach (IStats sta in atl) { Console.WriteLine("Current objects health is: " + sta.Health.ToString()); } Console.Read(); }
public void Can_Get_With_Parameters() { var duck = new Duck {Name = "Donald"}; var ignore = new IgnoreNull(duck); Assert.AreEqual(duck.Name, ignore.QuackGet("Item", new object[1] {1}).ToString()); }
public static void Main() { Animal herman = new Lion(); Animal zelda = new Giraffe(); Animal don = new Duck(); Animal[] three = {herman, zelda, don}; Feed(three); }
public void Can_Set_With_Parameters() { var duck = new Duck(); var ignore = new IgnoreNull(duck); ignore.QuackSet("Item", new object[1] {1}, "Donald"); Assert.AreEqual("Donald", duck.Name); }
// Use this for initialization public EnemyAI(Duck owner) { if (owner != null) { this._owner = owner; } else { Debug.LogError("No actor attached"); } }
public override void Update() { this.wait -= 0.004f; if ((double)this.wait >= 0.0) { return; } this.wait = 1f; Duck duck = new Duck(this.x, this.y, Profiles.DefaultPlayer1) { ai = new DuckAI() }; duck.mindControl = (InputProfile)duck.ai; duck.derpMindControl = false; (Level.current.camera as FollowCam).Add((Thing)duck); Level.Add((Thing)duck); }
public void should_implement_more_than_one_interface() { var duck = new Duck(); var castToMoveable = (IMoveable)duck; var castToTalkable = (ITalkable)duck; castToMoveable.MoveTo(2, 3); var duckPosition = duck.WhereAmI; var duckTalk = castToTalkable.Talk(); // change the variable values for the following 2 lines to fix the test. const string expectedDuckPosition = "You are at (2, 3)"; const string expectedTalk = "Ga, ga, ..."; Assert.Equal(expectedDuckPosition, duckPosition); Assert.Equal(expectedTalk, duckTalk); }
//오리 생성함수 public void OnHatchEggInHatchery(Hatchery hatchery, Egg egg) { Debug.Log("삐약"); GameObject objectBase = Instantiate(Resources.Load("Prefabs/duck"), hatchery.transform.position, Quaternion.identity) as GameObject; string objectID = $"duck_{s_duckUniqueID++}"; Duck duckling = objectBase.GetComponent <Duck>(); duckling.ObjectID = objectID; duckling.male = egg.male; duckling.name = objectID; ducksList.Add(objectID, duckling); foodsList.Remove(egg.ObjectID); GameObject.Destroy(egg.gameObject); eggCount--; }
// Use this for initialization void Start() { highscore = PlayerPrefs.GetInt("highscore"); scoremap1 = PlayerPrefs.GetInt("scoremap1"); if (highscore == null) { highscore = 0; } if (scoremap1 == null) { scoremap1 = 0; } facingRight = true; myRigibody = GetComponent <Rigidbody2D>(); myAnimator = GetComponent <Animator>(); duck = GetComponent <Duck>(); sound = GameObject.FindGameObjectWithTag("sound").GetComponent <SoundManager>(); }
public override void OnPressAction() { if (this.owner == null) { return; } Thing owner = this.owner; Duck duck = this.duck; if (duck != null) { ++duck.profile.stats.presentsOpened; this.duck.ThrowItem(); } Level.Remove((Thing)this); Level.Add((Thing) new OpenPresent(this.x, this.y, this._sprite.frame)); for (int index = 0; index < 4; ++index) { Level.Add((Thing)SmallSmoke.New(this.x + Rando.Float(-2f, 2f), this.y + Rando.Float(-2f, 2f))); } SFX.Play("harp", 0.8f); if (this._contains == (System.Type)null) { this.Initialize(); } if (!(Editor.CreateThing(this._contains) is Holdable thing)) { return; } if (Rando.Int(500) == 1 && thing is Gun && (thing as Gun).CanSpawnInfinite()) { (thing as Gun).infiniteAmmoVal = true; (thing as Gun).infinite.value = true; } thing.x = owner.x; thing.y = owner.y; Level.Add((Thing)thing); if (duck == null) { return; } duck.GiveHoldable(thing); duck.resetAction = true; }
public static void CollectInput(Farm farm, Duck duck) { Console.Clear(); DuckHouse anyHouseWithRoom = farm.DuckHouses.Find(dh => dh.CurrentCapacity < dh.MaxCapacity); if (anyHouseWithRoom != null) { for (int i = 0; i < farm.DuckHouses.Count; i++) { DuckHouse currentHouse = farm.DuckHouses[i]; if (currentHouse.CurrentCapacity < currentHouse.MaxCapacity) { Console.WriteLine($"{i + 1}. {currentHouse}"); } } Console.WriteLine(); // How can I output the type of plant chosen here? if (UserTriedToSelectAFullFacility) { Console.WriteLine("That facility is already full."); } Console.WriteLine($"Place the duck where?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()) - 1; farm.DuckHouses[choice].AddResource(farm, duck); } else { PurchaseStock.ThereIsNoRoomForTheAnimalBeingPurchased = true; Program.DisplayBanner(); PurchaseStock.CollectInput(farm); } /* * Couldn't get this to work. Can you? * Stretch goal. Only if the app is fully functional. */ // farm.PurchaseResource<IGrazing>(animal, choice); }
private void NextLevel() { var level = _levelController.CurrentLevel; if (_hud.NumberOfDucksShot == 12) { _hud.ResetDuckCounter(); _levelController.NextLevel(); level = _levelController.CurrentLevel; _billboard.StartBillBoard("Level " + _levelController.LevelNumber); } level.Ducks.Shuffle(); _duck = new Duck("duck", level.Ducks[0].StartX, level.Ducks[0].Flip, level.Ducks[0].HorizontalVelocity, level.Ducks[0].VerticalVelocity); _duck2 = new Duck("duck2", level.Ducks[1].StartX, level.Ducks[1].Flip, level.Ducks[1].HorizontalVelocity, level.Ducks[1].VerticalVelocity); _duck3 = new Duck("duck3", level.Ducks[2].StartX, level.Ducks[2].Flip, level.Ducks[2].HorizontalVelocity, level.Ducks[2].VerticalVelocity); _duck4 = new Duck("duck4", level.Ducks[3].StartX, level.Ducks[3].Flip, level.Ducks[3].HorizontalVelocity, level.Ducks[3].VerticalVelocity); _scene.RemoveSpriteFromLayer(RenderLayerEnum.LAYER2, _duck); _scene.RemoveSpriteFromLayer(RenderLayerEnum.LAYER2, _duck2); _scene.RemoveSpriteFromLayer(RenderLayerEnum.LAYER2, _duck3); _scene.RemoveSpriteFromLayer(RenderLayerEnum.LAYER2, _duck4); CollisionManager.RemoveSpriteToCollisionManager(_duck.Name); CollisionManager.RemoveSpriteToCollisionManager(_duck2.Name); CollisionManager.RemoveSpriteToCollisionManager(_duck3.Name); CollisionManager.RemoveSpriteToCollisionManager(_duck4.Name); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER2, _duck); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER2, _duck2); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER2, _duck3); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER2, _duck4); _gameClock.Reset(); _gameClock.Start(); Round1Triggered = false; Round2Triggered = false; Round3Triggered = false; _hud.ResetGun(); }
public static bool Prefix(TeamBeam __instance, Duck d) { if (!(ducksField.GetValue(__instance) as List <BeamDuck>).Any((BeamDuck t) => t.duck == d)) { float num; if (d.y <= 59f) { num = 25f; } else if (60f <= d.y && d.y <= 119f) { num = 85f; } else { num = 145f; } SFX.Play("stepInBeam", 1f, 0f, 0f, false); d.beammode = true; d.immobilized = true; d.crouch = false; d.sliding = false; if (d.holdObject != null) { (gunsField.GetValue(__instance) as List <Thing>).Add(d.holdObject); } d.ThrowItem(true); d.solid = false; d.grounded = false; d.offDir = 1; (ducksField.GetValue(__instance) as List <BeamDuck>).Add(new BeamDuck { duck = d, entryHeight = num, leaving = false, entryDir = ((d.x < __instance.x) ? -1 : 1), sin = new SinWave(0.1f, 0f), sin2 = new SinWave(0.05f, 0f) }); } return(false); }
// Use this for initialization void Start() { float steps = 360.0f / AirConsoleManager.Instance.ActivePlayers().Count; int steppers = 0; foreach (AirConsoleManager.Player p in AirConsoleManager.Instance.ActivePlayers()) { Vector2 spawnPosition = new Vector2(1, 0); spawnPosition = spawnPosition.Rotate(steppers * steps); Transform instantiatedDuckTransform = Instantiate(JPL.Core.Prefabs.duck, new Vector3(spawnPosition.x * DuckGameGlobalConfig.startDistance, 0, spawnPosition.y * DuckGameGlobalConfig.startDistance), Quaternion.identity); Duck neededDuck = instantiatedDuckTransform.GetComponent <Duck>(); neededDuck.playerId = p.PlayerId; neededDuck.playerName = p.playerName; duckList.Add(neededDuck); steppers++; } startTime = Time.time; maxDistance = DuckGameGlobalConfig.startDistance + 1; }
public virtual AIState DoUpdate(Duck duck, DuckAI ai) { if (this._state.Count <= 0) { return(this.Update(duck, ai)); } AIState aiState = this._state.Peek().DoUpdate(duck, ai); if (aiState == null) { this._state.Pop(); } else if (aiState != this._state.Peek()) { this._state.Pop(); this._state.Push(aiState); } return(this); }
public Duck GetInfo() { Duck result = new Duck(); wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("h1"))); result.Name = driver.FindElement(By.CssSelector("h1.title")).Text; result.RegularPrice = regularPriceElement.Text; result.RegularPriceColor = regularPriceElement.GetCssValue("color"); result.RegularPriceSize = Convert.ToInt32(regularPriceElement.GetCssValue("font-size").Replace("px", "")); result.IsRegularPriceCrossed = regularPriceElement.TagName == "s"; result.CampaignPriceColor = campaignPriceElement.GetCssValue("color"); result.CampaignPrice = campaignPriceElement.Text; result.CampaignPriceSize = Convert.ToInt32(campaignPriceElement.GetCssValue("font-size").Replace("px", "")); result.IsCampaignPriceBold = campaignPriceElement.TagName == "strong"; return(result); }
public override void Update() { PhysicsObject physicsObject = this._attach; if (this._attach is Duck) { Duck attach = this._attach as Duck; physicsObject = attach.ragdoll != null ? (PhysicsObject)attach.ragdoll.part1 : (PhysicsObject)attach; } if (physicsObject == null) { return; } double num1 = (double)this.Solve((PhysicsObject)this, physicsObject, 30f); int num2 = 0; PhysicsObject b2 = (PhysicsObject)this; foreach (ChainLink link in this._links) { double num3 = (double)this.Solve((PhysicsObject)link, b2, 2f); b2 = (PhysicsObject)link; link.depth = this._attach.depth - 8 - num2; ++num2; } double num4 = (double)this.Solve(physicsObject, b2, 2f); base.Update(); if ((double)this._sparkWait > 0.0) { this._sparkWait -= 0.1f; } else { this._sparkWait = 0.0f; } if ((double)this._sparkWait != 0.0 || !this.grounded || (double)Math.Abs(this.hSpeed) <= 1.0) { return; } this._sparkWait = 0.25f; Level.Add((Thing)Spark.New(this.x + ((double)this.hSpeed > 0.0 ? -2f : 2f), this.y + 7f, new Vec2(0.0f, 0.5f))); }
public virtual float GetWishSpeed() { var ws = Duck.GetWishSpeed(); if (ws >= 0) { return(ws); } if (Input.Down(InputButton.Run)) { return(SprintSpeed); } if (Input.Down(InputButton.Walk)) { return(WalkSpeed); } return(DefaultSpeed); }
void Awake() { inputState = GetComponent <InputState> (); walkBehavior = GetComponent <Walk> (); animator = GetComponent <Animator> (); collisionState = GetComponent <CollisionState> (); duckBehavior = GetComponent <Duck> (); if (blockAnimationNeed) { blockBehavoir = GetComponent <Block> (); } if (shootAnimationInAirNeed) { fireBehavior = GetComponent <FireProjectile> (); } if (changeStateNeed) { changeStateBevavior = GetComponent <ChangeState> (); } }
private static SpawnPoint AttemptTeamSpawn( Team team, List <SpawnPoint> usedSpawns, List <Duck> spawned) { Level current = Level.current; List <TeamSpawn> teamSpawnList = new List <TeamSpawn>(); foreach (TeamSpawn teamSpawn in Level.current.things[typeof(TeamSpawn)]) { if (!usedSpawns.Contains((SpawnPoint)teamSpawn)) { teamSpawnList.Add(teamSpawn); } } if (teamSpawnList.Count <= 0) { return((SpawnPoint)null); } TeamSpawn teamSpawn1 = teamSpawnList[Rando.Int(teamSpawnList.Count - 1)]; usedSpawns.Add((SpawnPoint)teamSpawn1); for (int index = 0; index < team.numMembers; ++index) { Vec2 position = teamSpawn1.position; if (team.numMembers == 2) { float num = 18.82353f; position.x = (float)((double)teamSpawn1.position.x - 16.0 + (double)num * (double)index); } else if (team.numMembers == 3) { float num = 9.411764f; position.x = (float)((double)teamSpawn1.position.x - 16.0 + (double)num * (double)index); } Duck duck = new Duck(position.x, position.y - 7f, team.activeProfiles[index]); duck.offDir = teamSpawn1.offDir; spawned.Add(duck); } return((SpawnPoint)teamSpawn1); }
/// <summary> /// POO herencia /// permite derivar una clase de otra, por lo tanto habra clases hijos y clases padres /// se podria simular heredar de 2 clases con composicion, ver ducktoy /// </summary> /// <param name="args"></param> static void Main(string[] args) { // Console.WriteLine("Hello World!"); Duck duck = new Duck() { Color = "amarillo", Race = "normal" }; Console.WriteLine($"duck: {duck.ToString()}"); Duck duck2 = new Duck() { Color = "blanco" }; Console.WriteLine($"duck2: {duck2.ToString()}"); Duck duck3 = new Duck() { Race = "normal" }; Console.WriteLine($"duck3: {duck3.ToString()}"); DuckToy ducktoy = new DuckToy("amarillo", "normal", "goma", 2); Console.WriteLine($"Ducktoy: {ducktoy.ToString()}"); Motorcycle moto = new Motorcycle() { Brand = "marca", Displacement = 200, MaxVelocity = 100, Model = "modelo", WheelQuantity = 2 }; Console.WriteLine($"moto: {moto.ToString()}"); }
public static void CollectInput(Farm farm, Duck animal) { // Console.Clear(); int j = 0; for (int i = 0; i < farm.DuckHouses.Count; i++) { if (farm.DuckHouses[i].Animals.Count < farm.DuckHouses[i].Capacity) { Console.WriteLine($"{j + 1}. Duck House ({farm.DuckHouses[i].Animals.Count} ducks)"); j++; } } Console.WriteLine(); // How can I output the type of animal chosen here? Console.WriteLine($"Place {animal.Type.ToLower()} where?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()); try { if (farm.DuckHouses[choice - 1].Animals.Count < farm.DuckHouses[choice - 1].Capacity) { farm.DuckHouses[choice - 1].AddResource(animal); } } catch (ArgumentOutOfRangeException) { Console.WriteLine($"{choice} is not a valid option"); } /* * Couldn't get this to work. Can you? * Stretch goal. Only if the app is fully functional. */ // farm.PurchaseResource<IGrazing>(animal, choice); }
public Pedestal(float xpos, float ypos, Team team, int place) : base(xpos, ypos) { this._team = team; this._sprite = new SpriteMap("rockThrow/placePedastals", 38, 45); this._sprite.frame = place; this.center = new Vec2((float)(this._sprite.w / 2), (float)this._sprite.h); this.graphic = (Sprite)this._sprite; this.depth = new Depth(0.062f); this._scoreCard = new Sprite("rockThrow/scoreCard"); this._font = new BitmapFont("biosFont", 8); this._scoreCard.CenterOrigin(); this._trophy = new Sprite("trophy"); this._trophy.CenterOrigin(); if (Network.isServer) { int num1 = 0; foreach (Profile activeProfile in team.activeProfiles) { float num2 = (float)((team.activeProfiles.Count - 1) * 10); Duck duck = new Duck(xpos - num2 / 2f + (float)(num1 * 10), this.GetYOffset() - 15f, activeProfile); duck.depth = new Depth(0.06f); Level.Add((Thing)duck); if (place == 0) { Trophy trophy = new Trophy(duck.x, duck.y); Level.Add((Thing)trophy); if (!Network.isActive) { duck.Fondle((Thing)trophy); duck.GiveHoldable((Holdable)trophy); } } ++num1; } } Level.Add((Thing) new Platform(xpos - 17f, this.GetYOffset(), 34f, 16f)); Level.Add((Thing) new Block(-6f, this.GetYOffset() - 100f, 6f, 200f)); Level.Add((Thing) new Block(320f, this.GetYOffset() - 100f, 6f, 200f)); Level.Add((Thing) new Block(-20f, 155f, 600f, 100f)); }
static void SortDuck() { var ducks = new Duck[] { new Duck("Duffy", 8), new Duck("Dewey", 2), new Duck("Howard", 7), new Duck("Louie", 2), new Duck("Donal", 10), new Duck("Huey", 3) }; Console.WriteLine("Before sorting:"); DisplayDucks(ducks); Array.Sort(ducks); Console.WriteLine(); Console.WriteLine("After sorting:"); DisplayDucks(ducks); }
void AddCape(Duck duck) { if (CapeTexture == null) { return; //The skin had no cape texture, return. } Cape cape = new Cape(0, 0, duck); cape.SetCapeTexture(CapeTexture); Level.Add(cape); //Add Cape to the level. if (Capes.ContainsKey(duck)) //If theres already a cape in the level { Level.Remove(Capes[duck]); //Remove the already existing cape from the level Capes[duck] = cape; //Change the cape. return; } Capes.Add(duck, cape); //If no existing cape was found, add it to the dictionary. }
void Start() { duck = Resources.FindObjectsOfTypeAll <Duck>()[0]; gamePlay = Resources.FindObjectsOfTypeAll <Gameplay>()[0]; screenEffect = transform.Find("ScreenEffect").GetComponent <Image>(); flyAway = transform.Find("FlyAway").gameObject; pointsIndicator = transform.Find("PointsIndicator").gameObject; gameStats = transform.Find("GameStats").gameObject; winScreen = transform.Find("WinScreen").gameObject; flyAway.SetActive(false); pointsIndicator.SetActive(false); gameStats.SetActive(false); winScreen.SetActive(false); screenEffect.gameObject.SetActive(true); screenEffect.CrossFadeAlpha(0, 0f, false); scoreText = gameStats.transform.Find("ScoreBox").transform.Find("Score").GetComponent <TextMeshProUGUI>(); reloadText = gameStats.transform.Find("Reload").transform.Find("ReloadText").GetComponent <TextMeshProUGUI>(); ducks = gameStats.transform.Find("HitBox").transform.Find("Ducks").GetComponentsInChildren <Image>(); bullets = gameStats.transform.Find("BulletBox").transform.Find("Bullets").GetComponentsInChildren <Image>(); }
IEnumerator CollectDuckAnimation(Duck duck) { sRenderer.sprite = OneDuck[0]; yield return(new WaitForSeconds(0.2f)); for (int i = 0; i < 13; i++) { transform.position += Vector3.up * movementStep; yield return(new WaitForSeconds(0.05f)); } yield return(new WaitForSeconds(0.3f)); for (int i = 0; i < 13; i++) { transform.position += Vector3.down * movementStep; yield return(new WaitForSeconds(0.05f)); } yield return(new WaitForSeconds(0.1f)); transform.parent.GetComponent <Gameplay>().NextDuck(); }
public void ThrowDuck(Vector3 target) { if (_duck != null) { _duck.Throw((target - _duck.transform.position).normalized * 3f); _animator.SetBool("grabbing", false); _animator.SetTrigger("throw"); LerpUtility.Instance.TranslateTransform( _duck.transform, _duck.transform.position, target, 0.25f, () => { _duck.Die(); _duck = null; _gameController.PlayerStruckEngine(); } ); } }
public static void RevisaoPOO1() { Duck duck = new Duck(); MallardDuck mallardDuck = new MallardDuck(); RubberDuck rubberDuck = new RubberDuck(); RedHeadDuck redHeadDuck = new RedHeadDuck(); duck.display(); duck.swim(); mallardDuck.display(); mallardDuck.quack(); mallardDuck.fly(); rubberDuck.display(); rubberDuck.quack(); redHeadDuck.display(); redHeadDuck.fly(); redHeadDuck.quack(); }
public static void CollectInput(Farm farm, Duck duck) { Console.Clear(); List <DuckHouse> availableHouses = new List <DuckHouse>(); for (int i = 0; i < farm.DuckHouses.Count; i++) { if ((farm.DuckHouses[i].Capacity) > farm.DuckHouses[i].GetDuckCount()) { availableHouses.Add(farm.DuckHouses[i]); } } int duckCount = 1; if (availableHouses.Count == 0) { Console.WriteLine("You do not currently have any houses with enough capacity to add this animal. Please add a new facility. Press ENTER to continue."); Console.ReadLine(); } for (int i = 0; i < availableHouses.Count; i++) { while (duckCount > 0) { // How can I output the type of animal chosen here? Console.WriteLine($"{i + 1}: This duck house currently has {availableHouses[i].GetDuckCount()} duck(s) in stock with a capacity of {availableHouses[i].Capacity} ducks."); Console.WriteLine($"Enter house number to send duck"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()); int realChoice = choice - 1; availableHouses[realChoice].AddResource(duck); Console.WriteLine($"A duck has been added to the facility. You currently have {availableHouses[realChoice].GetDuckCount()} duck(s) in this house. Press the 'Enter' key to continue."); duckCount--; Console.ReadLine(); } } }
// Update is called once per frame void Update() { if (!isGameFinished) { if (!isPreFallOffFinished && Time.time >= startTime + DuckGameGlobalConfig.preDropOffTime) //Duck dieing starts { isPreFallOffFinished = true; lastDropOffTime = Time.time; Debug.Log("dropoff starting"); } if (isPreFallOffFinished) { if (Time.time >= lastDropOffTime + DuckGameGlobalConfig.dropOffTime) //Furthers duck dies { lastDropOffTime = Time.time; Duck furtherstDuck = GetFurtherstDuck(); furtherstDuck.Kill(); maxDistance = Vector3.Distance(furtherstDuck.transform.position, Vector3.zero); hexGrid.SetFalloff(Vector3.Distance(furtherstDuck.transform.position, Vector3.zero)); Debug.Log("someone lost"); } } foreach (Duck d in duckList) { float duckDistance = Vector3.Distance(d.transform.position, new Vector3(0, 0, 0)); if (duckDistance >= maxDistance) //if duck distance is higher than max distance, kill the duck { d.Kill(); } if (duckDistance <= DuckGameGlobalConfig.winDistance) { PlayerWon(d.playerName); return; } } } }
public Animal GetAnimal(string animalName) { var random = new Random().Next(1, 4); Animal animal = null; switch (random) { case 1: animal = new Cat(animalName); break; case 2: animal = new Dog(animalName); break; case 3: animal = new Duck(animalName); break; } return(animal); }
public void should_implement_more_than_one_interface() { // IMovable and ITalkable are interfaces // IMovable has an abstract method MoveTo(x, y) and a property WhereAmI() // ITalkable has an abstract method Talk() // Duck can implement more than one interface var duck = new Duck(); var castToMoveable = (IMoveable)duck; var castToTalkable = (ITalkable)duck; castToMoveable.MoveTo(2, 3); string duckPosition = duck.WhereAmI; string duckTalk = castToTalkable.Talk(); // change the variable values for the following 2 lines to fix the test. const string expectedDuckPosition = "You are at (2, 3)"; const string expectedTalk = "Ga, ga, ..."; Assert.Equal(expectedDuckPosition, duckPosition); Assert.Equal(expectedTalk, duckTalk); }
static void Main(string[] args) { Duck exp1 = new Duck(); Console.WriteLine("Я живая утка:\n"); exp1.Fly(); exp1.Swim(); exp1.Quack(); WoodenDuck exp2 = new WoodenDuck(); Console.WriteLine("\nЯ деревянная утка:\n"); exp2.Fly(); exp2.Swim(); exp2.Quack(); RubberDuck exp3 = new RubberDuck(); Console.WriteLine("\nЯ резиновая утка:\n"); exp3.Fly(); exp3.Swim(); exp3.Quack(); Console.ReadLine(); }
public static void CollectInput(Farm farm, Duck animal) { // Utils.Clear (); var AvailableFarms = farm.DuckHouses.Where(houses => houses.Capacity > houses.ResourceCount).ToList(); if (AvailableFarms.Count == 0) { Console.WriteLine("Please add a Facility"); } else { foreach (var house in farm.DuckHouses) { if (house.ResourceCount < house.Capacity) { Console.WriteLine($"{farm.DuckHouses.IndexOf(house) + 1}. {house}"); } else { } } Console.WriteLine(); // How can I output the type of animal chosen here? Console.WriteLine($"Place the animal where?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()); farm.DuckHouses[(choice - 1)].AddResource(animal); } /* * Couldn't get this to work. Can you? * Stretch goal. Only if the app is fully functional. */ // farm.PurchaseResource<IGrazing>(animal, choice); }
public void TestCanCast() { Duck duck = new Duck(); IInterface proxy = DuckTyping.Cast<IInterface>(duck); Assert.IsTrue(DuckTyping.CanCast<IInterface, Duck>(), "CanCast should have returned true."); Assert.IsTrue(DuckTyping.CanCast<IInterface>(duck), "CanCast should have returned true."); Assert.IsTrue(DuckTyping.CanCast<IInterface>(typeof(Duck)), "CanCast should have returned true."); Assert.IsTrue(DuckTyping.CanCast(typeof(IInterface), duck), "CanCast should have returned true."); Assert.IsTrue(DuckTyping.CanCast(typeof(IInterface), typeof(Duck)), "CanCast should have returned true."); Assert.IsTrue(DuckTyping.CanCast<Duck, IInterface>(), "CanCast should have returned true."); Assert.IsFalse(DuckTyping.CanCast<IFormattable>(duck), "CanCast should have returned false."); Assert.IsTrue(DuckTyping.CanCast<GeneralDelegate, SpecializedDelegate>(), "CanCast should have returned true."); Assert.IsTrue(DuckTyping.CanCast<SpecializedDelegate, GeneralDelegate>(), "CanCast should have returned true."); Assert.IsFalse(DuckTyping.CanCast<GeneralDelegate, EventHandler>(), "CanCast should have returned false."); Assert.IsTrue(DuckTyping.CanCast<AttributeTargets, string>(), "CanCast should have returned true."); Assert.IsTrue(DuckTyping.CanCast<string, AttributeTargets>(), "CanCast should have returned true."); Assert.IsFalse(DuckTyping.CanCast<AttributeTargets, DateTime>(), "CanCast should have returned false."); }
public void TestInterfaceCast() { Duck duck = new Duck(); IInterface proxy = DuckTyping.Cast<IInterface>(duck); Assert.IsNotNull(proxy, "DuckTyping.Cast<IInterface>(duck) return null."); Assert.IsTrue(proxy is IDuckProxy, "Cast did not return a proxy."); Assert.AreEqual(duck, ((IDuckProxy)proxy).UnwrapDuck(), "Cast returned a proxy that refers to the wrong duck object."); Assert.AreEqual(duck, DuckTyping.Cast<Duck>(proxy), "Reverse cast returned the wrong value."); }
public void TestInterfaceProxyToString() { Duck duck = new Duck(); IInterface proxy = DuckTyping.Cast<IInterface>(duck); Assert.AreEqual(duck.ToString(), proxy.ToString(), "Interface proxy does not properly forward calls to ToString method."); }
public void TestInterfaceProxyProperty() { Duck duck = new Duck(); IInterface proxy = DuckTyping.Cast<IInterface>(duck); string stringValue = "String value."; int intValue = 5; proxy.Property = stringValue; Assert.AreEqual(stringValue, proxy.Property, "Property not implemented correctly."); proxy.ValueProperty = intValue; Assert.AreEqual(intValue, proxy.ValueProperty, "Value type property not implemented correctly."); proxy[4] = stringValue; Assert.AreEqual(stringValue, proxy[4], "Indexed property not implemented correctly."); }
public void TestInterfaceProxyMethodVariance() { Duck duck = new Duck(); IInterface proxy = DuckTyping.Cast<IInterface>(duck); string stringValue = "String value."; int intValue = 5; Assert.AreEqual(stringValue, proxy.ContravariantMethod(stringValue), "Contravariant method returned wrong value."); Assert.IsNull(proxy.ContravariantMethod(null), "Passing and returning a null value to and from a contravariant method failed."); try { proxy.ContravariantMethod(new object[0]); Assert.Fail("Passing a non-string object through a contravariant method that takes a string parameter should have thrown an InvalidCastException."); } catch (InvalidCastException) { } try { proxy.ContravariantValueMethod(7); Assert.Fail("Passing a non-DateTime object through a contravariant method that takes a DateTime parameter should have thrown an InvalidCastException."); } catch (InvalidCastException) { } try { proxy.ContravariantValueMethod(null); Assert.Fail("Passing null through a contravariant method that takes a value type parameter should have thrown a NullReferenceException."); } catch (NullReferenceException) { } Assert.AreEqual("Method", proxy.ContravariantEnumMethod("Method"), "Contravariant method returned wrong enum value."); try { proxy.ContravariantEnumMethod(null); Assert.Fail("Passing null through a contravariant method that taks an enum parameter should have thrown a NullReferenceException."); } catch (NullReferenceException) { } Assert.AreEqual(stringValue, proxy.CovariantMethod(stringValue), "Covariant method returned wrong value."); Assert.IsNull(null, proxy.CovariantMethod(null), "Passing and returning a null value to and from a covariant method failed."); Assert.AreEqual(intValue, proxy.CovariantValueMethod(intValue), "Covariant method returned wrong int value."); Assert.AreEqual(AttributeTargets.Class, proxy.CovariantEnumMethod(AttributeTargets.Class), "Covariant method returned wrong enum value."); // Note: This next line is primarily to check whether the system handles a recursive cast properly. If it doesn't, // a StackOverflowException will be thrown. Assert.IsTrue(proxy.Equals(proxy.VariantByRecursiveCastMethod(duck)), "Variant by recursive cast method returned wrong value."); Assert.AreEqual(duck, proxy.VariantByUncastMethod(proxy), "Variant by uncast method returned wrong value."); }
public void TestInterfaceProxyEvent() { Duck duck = new Duck(); IInterface proxy = DuckTyping.Cast<IInterface>(duck); object sender = this; AddingNewEventArgs e = new AddingNewEventArgs(); EventHandler eventHandler = new EventHandler(this.EventHandlerMethod); AddingNewEventHandler addingNewEventHandler = new AddingNewEventHandler(this.AddingNewEventHandlerMethod); m_Sender = null; m_EventArgs = null; proxy.Event += eventHandler; duck.RaiseEvent(sender, e); Assert.AreEqual(sender, m_Sender, "Proxy class did not properly forward adding of an event handler."); m_Sender = null; m_EventArgs = null; proxy.Event -= eventHandler; duck.RaiseEvent(sender, e); Assert.IsNull(m_Sender, "Proxy class did not properly forward removing of an event handler."); m_Sender = null; m_EventArgs = null; proxy.CovariantEvent += addingNewEventHandler; duck.RaiseCovariantEvent(sender, e); Assert.AreEqual(sender, m_Sender, "Proxy class did not properly forward adding of an event handler to a covariant event."); m_Sender = null; m_EventArgs = null; proxy.CovariantEvent -= addingNewEventHandler; duck.RaiseCovariantEvent(sender, e); Assert.IsNull(m_Sender, "Proxy class did not properly forward removing of an event handler from a covariant event."); m_Sender = null; m_EventArgs = null; proxy.ContravariantEvent += eventHandler; duck.RaiseContravariantEvent(sender, e); Assert.AreEqual(sender, m_Sender, "Proxy class did not properly forward adding of an event handler to a contravariant event."); m_Sender = null; m_EventArgs = null; proxy.ContravariantEvent -= eventHandler; duck.RaiseContravariantEvent(sender, e); Assert.IsNull(m_Sender, "Proxy class did not properly forward removing of an event handler from a contravariant event."); }
public void Setup() { duck= new DecoyDuck(); }
public void DuckCanRecieveAnyCalls() { dynamic d = new Duck(); d.WriteSomething("print_this_string"); }
static void simulate(Duck duck) { duck.quack(); }
private static void TestDuck(Duck duck) { duck.Display(); duck.Quack(); duck.Fly(); }
private void BuildAnimations() { // Counter Stuff int x, y; Sprite temp; x = HelperUtils.SafeBoundary.X + 578; y = HelperUtils.SafeBoundary.Y + 566; // Create the ducks for the counter for (int i = 0; i < 10; i++) { temp = new Sprite(); temp.Texture = m_duckcount_txt; temp.X_Pos = x; temp.Y_Pos = y; m_ducks[i] = new Duck(); m_ducks[i].m_spr = temp; x -= (m_duckcount_txt.Width + 2); } m_counter_spr.Texture = m_countbg_txt; m_counter_spr.X_Pos = HelperUtils.SafeBoundary.X + 512 - (m_countbg_txt.Width / 2); m_counter_spr.Y_Pos = HelperUtils.SafeBoundary.Y + 536; // Intermission Stuff m_flyawayduck_anim_1.BuildAnimation(m_flyingaway_txt, 1, 3, true, new int[4] { 0, 1, 2, 1 }); m_flyawayduck_anim_1.SetFrame(0, 4, null); m_flyawayduck_anim_1.SetFrame(1, 4, m_flapwing_snd); m_flyawayduck_anim_1.SetFrame(2, 4, null); m_flyawayduck_anim_1.SetFrame(3, 4, m_flapwing_snd); m_flyawayduck_anim_2.BuildAnimation(m_flyingaway_txt, 1, 3, true, new int[4] { 0, 1, 2, 1 }); m_flyawayduck_anim_2.SetFrame(0, 4, null); m_flyawayduck_anim_2.SetFrame(1, 4, m_flapwing_snd); m_flyawayduck_anim_2.SetFrame(2, 4, null); m_flyawayduck_anim_2.SetFrame(3, 4, m_flapwing_snd); m_laughdog_anim.BuildAnimation(m_laughingdog_txt, 1, 2, true, new int[2] { 0, 1 }); m_laughdog_anim.SetFrame(0, 6, null); m_laughdog_anim.SetFrame(1, 6, null); m_dog_laugh_scn_inter.AddAnimation(new DirXYMover(m_laughdog_anim, 0, -47, 1.4f), m_doglaugh_snd); m_dog_laugh_scn_inter.AddAnimation(new TimeOutDrawable(m_laughdog_anim, 60, true)); m_dog_laugh_scn_inter.AddAnimation(new DirXYMover(m_laughdog_anim, 0, 47, 1.6f)); }
protected void NewGame() { player = -1; if (ducks == null) ducks = new Duck[16]; for (int i = 0; i < 16; i++) { Duck d = ducks[i]; if (d == null) { if (i < map.NumberOfStartPositions) { d = new Duck(i, map.GetStartPosition(i).position, map); d.Reset(); } } else { d.NewGameReset(map.GetStartPosition(i).position, map); } } NextDuck(); ChangeState(State.Playing); camera.Reset(); map.Reset(); }
private void NextDuck() { player++; ducks[player] = new Duck(player, map.GetStartPosition(player).position, map); ducks[player].visible = true; Duck.currentDuck = ducks[player]; }
static void Main(string[] args) { Ninja n = new Ninja(); Duck d = new Duck(); List<IDamageable> fighters = new List<IDamageable>(); fighters.Add(n); fighters.Add(d); Console.WriteLine("Ninja and Duck got into a fight!"); Console.WriteLine("Ninja has " + n.health + " chi remaining."); Console.WriteLine("Duck has " + d.health + " feathers remaining."); for (int i = 0; i < 50; i++) { foreach(IDamageable f in fighters) { f.takeDamage(3); } Console.WriteLine("Each fighter takes 3 damage."); Console.WriteLine("Ninja has " + n.health + " chi remaining."); Console.WriteLine("Duck has " + d.health + " feathers remaining."); if (d.health <= 0) { Console.WriteLine("Duck has no more feathers; Ninja is the winner!"); Console.WriteLine("Press any key to exit."); Console.ReadKey(); Environment.Exit(0); } if (n.health <= 0) { Console.WriteLine("Ninja has no more chi; Duck is the winner!"); Console.WriteLine("Press any key to exit."); Console.ReadKey(); Environment.Exit(0); } } Console.ReadLine(); }
public void Setup() { duck = new MallardDuck(); }
public void Setup() { duck = new RubberDuck(); }
static void testduck(Duck pduck) { pduck.quack(); pduck.fly(); }
public void TestInterfaceProxyEquals() { Duck duck1 = new Duck(); Duck duck2 = new Duck(); IInterface proxy1a = DuckTyping.Cast<IInterface>(duck1); IInterface proxy1b = DuckTyping.Cast<IInterface>(duck1); IInterface proxy2 = DuckTyping.Cast<IInterface>(duck2); Assert.IsTrue(proxy1a.Equals(proxy1b), "Interface proxy does not properly forward calls to the Equals method."); Assert.IsTrue(!proxy1a.Equals(proxy2), "Interface proxy overrides the Equals method improperly."); Assert.AreEqual(proxy1a.GetHashCode(), duck1.GetHashCode(), "Interface proxy does not properly forward calls to the GetHashCode method."); }