Inheritance: MonoBehaviour
Ejemplo n.º 1
0
	private Shot Solve(Bird currentBird, Pig targetPig, Vector2 slingPos) 
	{
		// 1. Random pick up a pig
		Vector2 shotPos = targetPig.transform.position;
		
		// 2. If the target is very close to before, randomly choose a point near it
		if(_lastTargetPig != null && _lastTargetPig == targetPig)
		{
			float angle = Random.value * Mathf.PI * 2f;
			if(Random.value < 0.5)
				angle *= -1f;

			shotPos.x = shotPos.x + Mathf.Cos(angle) * 0.5f;
			shotPos.y = shotPos.y + Mathf.Cos(angle) * 0.5f;
		}
		
		_lastTargetPig = targetPig;
		
		// 3. Estimate the trajectory
		float birdVel = currentBird._launchForce.x * -2f;
		float birdGrav =  currentBird._launchGravity * Physics2D.gravity.y;

		Vector2 releasePoint = TrajectoryPlanner.estimateLaunchPoint(slingPos, shotPos, birdVel, birdGrav);

		// 5. Calculate the tapping time according the bird type 	
		return new Shot(slingPos.x, slingPos.y, releasePoint.x, releasePoint.y, 0.5f);
	}
Ejemplo n.º 2
0
        public PigAI(Server server)
        {
            Server = server;
            gravity = new Vector3(0, -Config.PhysicsGravity, 0);

            Pig = new Pig { Scale = new Vector3(Config.PigScale) };
        }
Ejemplo n.º 3
0
    public void Register(Pig pig)
    {
        if (_pigList == null)
        {
            _pigList = new List <Pig>();
        }

        _pigList.Add(pig);
    }
Ejemplo n.º 4
0
        } //End PigForm

        /// <summary>
        /// Resets all key components to a succesful run through of the game.
        /// Pre: the existing data from the previous game lingers, either after a game
        /// has finished or you have re-entered from the login screen after a game.
        /// Post: the labels and variables have been reset to provide consistent games.
        /// </summary>
        private void ResetForm()
        {
            Pig.ResetGlobals();
            whosTurn = Pig.USER;
            UpdateLabels();
            btnPlayAgain.Enabled = false;
            btnCancel.Enabled    = false;
            btnRoll.Enabled      = true;
        } //End ResetForm
Ejemplo n.º 5
0
        protected override void Initialize()
        {
            // TEMP create game entities
            pigObject = mEntityManager.RequestEntity <Pig>();
            // TEMP initialise game entities
            pigObject.Initialise(new Vector3(600, 695, 0), Content.Load <Texture2D>("Graphics/Pig1"), new Vector3(8, 0, 0));

            base.Initialize();
        }
Ejemplo n.º 6
0
 public void Inject(Pig subject)
 {
     subject.Immunity = GetImmunity(15);
     if (randomElement.NextDouble() < 3 * DeathRate)
     {
         subject.Alive = false;
         Console.WriteLine($"Pig {subject.ID} is dead by vaccination");
     }
 }
Ejemplo n.º 7
0
    // Use this for initialization
    void Awake()
    {
        if (pigInstance == null)
        {
            pigInstance = this;
        }

        this.health = new Health(100.0f);
    }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Animal myAnimal = new Animal();
            Animal myPig    = new Pig();
            Animal myDuck   = new Duck();

            myAnimal.sound();
            myPig.sound();
            myDuck.sound();
        }
Ejemplo n.º 9
0
        static void MainPolymorhism(string[] args)
        {
            Animal myAnimal = new Animal();
            Pig    myPig    = new Pig();
            Duck   myDuck   = new Duck();

            myAnimal.sound();
            myPig.sound();
            myDuck.sound();
        }
Ejemplo n.º 10
0
        public NetworkPacketPig(Pig pig, byte id = 0) : base(NetworkPacketTypes.Pig, id, 0, pig)
        {
            AddBool(pig.IsGravityEnabled);
            AddBool(pig.IsCaught);

            if (pig.IsCaught)
            {
                AddByte(pig.Captor.Client.PlayerId);
            }
        }
Ejemplo n.º 11
0
            public static void display()
            {
                Animal al    = new Animal();
                Animal alPig = new Pig();
                Animal alBen = new Ben();

                al.sound();
                alPig.sound();
                alBen.sound();
            }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            Animal myAnimal = new Animal(); // Create a Animal object
            Animal myPig    = new Pig();    // Create a Pig object
            Animal myDog    = new Dog();    // Create a Dog object

            myAnimal.animalSound();
            myPig.animalSound();
            myDog.animalSound();
        }
        private static void CallRunTimeExample1PolymorphismToOutput()
        {
            Animal myAnimal = new Animal();        // Create a Animal object
            Animal myPig    = new Pig();           // Create a Pig object
            Animal myDog    = new Dog();           // Create a Dog object

            myAnimal.animalSound();
            myPig.animalSound();
            myDog.animalSound();
        }
Ejemplo n.º 14
0
    public void GiveNameChangesNamePig()
    {
        Pig    bird   = new Pig();
        string actual = bird.Name;

        bird.GiveName("Bob");

        string expected = bird.Name;

        Assert.AreNotEqual(expected, actual, "GiveName() should change name.");
    }
Ejemplo n.º 15
0
    public void EatIncreasesWeightPig()
    {
        Pig testObj = new Pig();
        int actual  = testObj.weight;

        testObj.Eat();

        int expected = testObj.weight;

        Assert.AreEqual(expected, actual + 1, "Eat() should increase weight by 1");
    }
Ejemplo n.º 16
0
        public void Adapter_GivenAPig_UseFlyingAnimalAdapter_GetFlyingPig()
        {
            //arrange
            var pig       = new Pig("Piggy");
            var flyingPig = new FlyingAnimalAdapter(pig);
            //act
            var actionResult = flyingPig.DoAction();

            //assert
            AreEqual(actionResult, "Piggy the Pig is flying!");
        }
Ejemplo n.º 17
0
    // Use this for initialization
    void Awake()
    {
        if (pigInstance == null)
        {
            pigInstance = this;
        }

        this.health           = new Health(100.0f);
        this.pigSpeed         = 5.0f;
        this.currentDirection = Direction.E;
    }
        static void Main(string[] args)
        {
            List <ISound> animals = new List <ISound>();

            //
            // OLD MACDONALD
            //
            Console.WriteLine("Old MacDonald had a farm ee ay ee ay oh");

            // Let's try singing about a Farm Animal
            animals.Add(new Horse());
            animals.Add(new Chicken());
            animals.Add(new Ferrari());
            animals.Add(new Pig());

            foreach (var animal in animals)
            {
                Pig pig = animal as Pig;
                if (pig != null)
                {
                    Console.WriteLine($"Am I a FarmAnimal {((FarmAnimal)animal).MakeSoundTwice()}");
                    Console.WriteLine($"Or am i a Pig {pig.MakeSoundTwice()}");
                    Console.WriteLine();
                }

                if (animal is FarmAnimal)
                {
                    FarmAnimal farmAnimal = (FarmAnimal)animal;
                    Console.WriteLine("And on his farm there was a " + farmAnimal.Name + " ee ay ee ay oh");
                    Console.WriteLine("With a " + farmAnimal.MakeSoundTwice() + " here and a " + farmAnimal.MakeSoundTwice() + " there");
                    Console.WriteLine("Here a " + farmAnimal.MakeSoundOnce() + ", there a " + farmAnimal.MakeSoundOnce() + " everywhere a " + farmAnimal.MakeSoundTwice());
                    Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh");
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("I'm not a farm animal dude, have some respect.");
                    Console.WriteLine();
                }
            }

            Console.WriteLine();
            foreach (var animal in animals)
            {
                Console.WriteLine($"Sound I make going round and round is {animal.MakeSound()}");
            }


            // 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();
        }
Ejemplo n.º 19
0
 // Use this for initialization
 void Start()
 {
     stateMachine = GetComponent <StateMachine> ();
     pig          = GetComponent <Pig> ();
     agent        = GetComponent <NavMeshAgent> ();
     sourceAudio  = GetComponent <AudioSource> ();
     if (player == null)
     {
         player = GameObject.Find("Player").transform;
     }
 }
Ejemplo n.º 20
0
        public IHttpActionResult Post(Pig pig)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _ctx.Pigs.Add(pig);
            _ctx.SaveChanges();
            return(Created("Added to Db", pig));
        }
Ejemplo n.º 21
0
        public Animal ReadAnimal(int id, DatabaseManager manager)
        {
            Animal    returnAnimal;
            DataTable outcomePigs = manager.RunQuery($"select * from Pigs where Id = {id}");

            returnAnimal = new Pig(id, outcomePigs.Rows[0]["Sex"].ToString(),
                                   Convert.ToInt32(outcomePigs.Rows[0]["Life_length"]),
                                   Convert.ToInt32(outcomePigs.Rows[0]["Level_of_food"]),
                                   Convert.ToDateTime(outcomePigs.Rows[0]["Birth_date"]));
            return(returnAnimal);
        }
Ejemplo n.º 22
0
        static void AbstractClassExample()
        {
            Pig myPig = new Pig();  // Create a Pig object

            myPig.animalSound();
            myPig.sleep();
            var test = myPig.StrReadonly;
            var t    = Pig.StrConstant;

            Pig newPig = new Pig("I am from Program.cs file");
        }
Ejemplo n.º 23
0
        private static Pig AddPig()
        {
            Pig temp = new Pig();

            Console.Write("Enter the name: ");
            temp.Name = Console.ReadLine();
            Console.Write("What color is it: ");
            temp.Color = Console.ReadLine();

            return(temp);
        }
        private void InitAnimals()
        {
            Pig   ghita   = new Pig("Ghita");
            Cat   puffy   = new Cat("Puffy");
            Horse patrick = new Horse("Patrick");
            Dog   spike   = new Dog("Spike");

            animals.Add(ghita);
            animals.Add(puffy);
            animals.Add(patrick);
            animals.Add(spike);
        }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            //
            // OLD MACDONALD
            //

            //Applying Polymorphism, we're allowed to work in terms of
            // generic types and not concrete classes. In this case
            // the list holds a collection of IFarmAnimal, meaning
            // any class that implements the IFarmAnimal interface is allowed
            // to be in the list.

            Chicken chicken = new Chicken();
            Cow     cow     = new Cow();
            Duck    duck    = new Duck();
            Pig     wilbur  = new Pig();

            //List<FarmAnimal> army = new List<FarmAnimal>();
            List <ISingableItem>  army  = new List <ISingableItem>();
            Stack <ISingableItem> stack = new Stack <ISingableItem>();

            //ISingableItem item = new ISingableItem(); //<-- not allowed here

            army.Add(new Cow());
            army.Add(new Duck());
            army.Add(new Chicken());
            army.Add(new Pig());
            army.Add(new Chicken());
            army.Add(new Tractor("Lil Toot Toot"));

            // Get the first item back out
            //FarmAnimal firstAnimal = army[0];
            //Cow firstCow = (Cow)army[0]; // Retrieve first item and cast to cow
            //Console.WriteLine(army[0]);  // Print out type of first animal

            Console.WriteLine("Old MacDonald had a farm ee ay ee ay oh");

            foreach (ISingableItem animal in army)
            {
                Console.WriteLine("And on his farm there was a " + animal.Name + " ee ay ee ay oh");
                Console.WriteLine("With a " + animal.MakeSoundTwice() + " here and a " + animal.MakeSoundTwice() + " there");
                Console.WriteLine("Here a " + animal.MakeSoundOnce() + ", there a " + animal.MakeSoundOnce() + " everywhere a " + animal.MakeSoundTwice());
                Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh");
                Console.WriteLine();
            }


            // ----- THIS IS GETTING REPETITIVE!
            // We can do better
            // How can we use what we've learned about inheritance
            // to help us remove code duplication
            //
        }
        public bool CheckCollision(Pig pig)
        {
            lock (this)
            {
                Mushroom mushroom = Mushrooms.FirstOrDefault(m => m.Intersects(pig));

                if (mushroom != null)
                    mushroom.OnCapture(pig.Thrower);

                return (mushroom != null);
            }
        }
        public void Test_PigDaliy()
        {
            // given
            var expected = new Pig();

            // when
            var result = new HigherLayer("PIG").GetAnimal();

            // then

            Assert.AreEqual(expected.GetType(), result.GetType());
        }
Ejemplo n.º 28
0
        private void InitAnimals()
        {
            Pig   peppa    = new Pig("Peppa");
            Cat   garfield = new Cat("Gafield");
            Dog   grivei   = new Dog("Grivei");
            Horse trojan   = new Horse("Trojan");

            animals.Add(peppa);
            animals.Add(garfield);
            animals.Add(grivei);
            animals.Add(trojan);
        }
        //传递多个Json对象
        public IActionResult MoreJsonObject([FromBody] MoreModelClass model)
        {
            string _dogstr = JsonConvert.SerializeObject(model.dogobj);
            string _pigstr = JsonConvert.SerializeObject(model.pigobj);

            Dog _dogobj = JsonConvert.DeserializeObject <Dog>(_dogstr);
            Pig _pigobj = JsonConvert.DeserializeObject <Pig>(_pigstr);

            string _res = string.Format("*传递多个Json对象*两个动物的名字是{0}和{1}", _dogobj.Name, _pigobj.Name);

            Console.WriteLine(_res);
            return(Json(_res));
        }
Ejemplo n.º 30
0
        static void Main(string[] args)
        {
            Pig myPig = new Pig();  // Create a Pig object

            myPig.AnimalSound();
            myPig.Sleep();


            Dog myDog = new Dog();  // Create a Dog object

            myDog.AnimalSound();
            myDog.Sleep();
        }
Ejemplo n.º 31
0
        public bool CheckCollision(Pig pig)
        {
            lock (this)
            {
                Mushroom mushroom = Mushrooms.FirstOrDefault(m => m.Intersects(pig));

                if (mushroom != null)
                {
                    mushroom.OnCapture(pig.Thrower);
                }

                return(mushroom != null);
            }
        }
Ejemplo n.º 32
0
 private void loadMap(int a)
 {
     currMap = a;
     Map     = content.maps[a];
     for (var _a = 0; _a < Pigs.Length; _a++)
     {
         Pigs[_a].Dispose();
     }
     Pigs = new Pig[Map.pigs.GetLength(0)];
     for (var _a = 0; _a < Pigs.Length; _a++)
     {
         Pigs[_a] = new Pig(_a);
     }
     player.init(Map.start);
 }
Ejemplo n.º 33
0
    void c08Predicate_Find()
    {
        List <Pig> list = GetPigList();
        Pig        pig  = list.Find(p => p.PigID == 100);

        if (pig == null)
        {
            Debug.LogError("pig == null");
        }
        else
        {
            Debug.LogError("pig != null");
            Debug.LogError(pig.PigID);
        }
    }
Ejemplo n.º 34
0
	public void ThrowBird(Bird currentBird, Pig targetPig, Vector2 slingPos)
	{
		if(_lastTargetPig)
			_lastTargetPig.GetComponent<SpriteRenderer>().material.color = Color.white;

		IsThrowingBird = true;
		
		_throwTimer = 0f;
		_currentBird = currentBird;

		// Highlight the target
		if(!GameWorld.Instance._isSimulation)
			targetPig.GetComponent<SpriteRenderer>().material.color = Color.red;

		_nextShot = Solve(currentBird, targetPig, slingPos);
		currentBird.SelectBird();
	}
Ejemplo n.º 35
0
 void Awake()
 {
     instance = this;
 }
Ejemplo n.º 36
0
        private void sureClick(object sender, RoutedEventArgs e)
        {
            if (times == 0)
            {
                Say += p.saying;
                Say += d.saying;
                Say += c.saying;
            }


            if (textBox.Text == "Pig" || textBox.Text == "pig")
            {
                Animal a = new Pig(textBlock);
                a.saying(sender, new myEventArgs(1));
            }
            if (textBox.Text == "Dog" || textBox.Text == "dog")
            {
                Animal a = new Dog(ref textBlock);
                a.saying(sender, new myEventArgs(2));
            }
            if (textBox.Text == "Cat" || textBox.Text == "cat")
            {
                Animal a = new Cat(textBlock);
                a.saying(sender, new myEventArgs(3));
            }

            textBox.Text = "";

            times++;
        }
Ejemplo n.º 37
0
        private void speakClick(object sender, RoutedEventArgs e)
        {
            if (times == 0)
            {
                p = new Pig(textBlock);
                d = new Dog(ref textBlock);
                c = new Cat(textBlock);
                Say += p.saying;
                Say += d.saying;
                Say += c.saying;
            }

            Random ran = new Random();

            Say(this, new myEventArgs(ran.Next(1, 4)));

            times++;
        }
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            // release any pig that was being dragged
            if(input.TouchState.Count == 0) {
                if(selectedPig != null) {
                    if(selectedPig.drop(old_pos)) {
                        pennedPigs[selectedPig.color].Add(selectedPig);
                        mainPigs.Remove(selectedPig);
                    }
                    soundList["blop"].Play();
                    selectedPig.selected = false;
                }
                selectedPig = null;
            } else {
                foreach(TouchLocation loc in input.TouchState) {
                    Vector2 scaledPos = Helpers.ScaleInput(new Vector2(loc.Position.X, loc.Position.Y));

                    if(selectedPig == null && phase == Phase.Begin) {
                        foreach(Pig p in mainPigs) {
                            // Don't let users grab falling pigs
                            if(p.State == PigStates.Falling)
                                continue;
                            Rectangle pig = new Rectangle((int)p.Coord.X - 75, (int)p.Coord.Y - 75, 150, 150);
                            if(pig.Contains(new Point((int)scaledPos.X, (int)scaledPos.Y))) {
                                selectedPig = p;
                                soundList["blop2"].Play();
                                p.selected = true;
                                old_pos = selectedPig.Coord;

                                if(p.State == PigStates.Entering) {
                                    old_pos += new Vector2(0, 96);
                                    p.timeLeft = p.EXPLODE_TIME;
                                }
                                break;
                            }
                        }
                    } else {
                        selectedPig.Coord = scaledPos;
                    }
                }
            }

            base.HandleInput(gameTime, input);
        }
 protected void AddFlyingPig(int color)
 {
     Pig p = new Pig(this, PigStates.Falling, rand);
     p.color = color;
     mainPigs.Add(p);
 }