Ejemplo n.º 1
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.º 2
0
        //测试多态
        public static void testDuotai()
        {
            Animal ai = new Animal();

            ai.Eat();
            ai = new Cat();
            ai.Eat();

            ai = new BlackCat();
            ai.Eat();

            ai = new Pig();
            ai.Eat(); // Pig中的Eat 方法用了new修饰 破坏了多态性

            //using MyDOtai = ConsoleClientApp.duotai; using的用法 对引用的命名空间进行重命名
            //MyDOtai.Animal ai = new MyDOtai.Animal();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Pig Babe = new Pig();

            Babe.sayName("Babe");
            Babe.Speak();
            Babe.Eat();
            Babe.benefit();

            Horse Ed = new Horse();

            Ed.sayName("Mr. Ed to you!");
            Ed.Speak();
            Ed.Eat();
            Ed.benefit();

            Cow Isis = new Cow();

            Isis.sayName("Isis the Goddess");
            Isis.Speak();
            Isis.Eat();
            Isis.benefit();

            Rabbit bugs = new Rabbit();

            bugs.sayName("Sir Bugguswald Bunny");
            bugs.Speak();
            bugs.Eat();
            bugs.benefit();

            Horse SB = new Horse();

            SB.sayName("SeaBiscuit the prize horse!!");
            SB.Speak();
            SB.Eat();
            SB.benefit();

            Rabbit PR = new Rabbit();

            PR.sayName("The young Peter Rabbit");
            PR.Speak();
            PR.Eat();
            PR.benefit();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //I created a farm in the Main() method.  I did not include my
            //animal classes.  I couldn't find a way create a messase for
            //namespace that is missing.
            try
            {
                Animal dog = new Animal();
                dog.Speak();

                Horse horse = new Horse();
                horse.Speak();
                horse.Move();
                horse.Action();
                horse.Eat();
                Console.ReadKey();

                Goat goat = new Goat();
                goat.Speak();
                goat.Move();
                goat.Action();
                goat.Eat();
                Console.ReadKey();

                Pig pig = new Pig();
                pig.Speak();
                pig.Move();
                pig.Action();
                pig.Eat();
                Console.ReadKey();

                Chicken chicken = new Chicken();
                chicken.Speak();
                chicken.Move();
                chicken.Action();
                chicken.Eat();
                Console.ReadKey();
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Pig Bacon = new Pig();

            Bacon.name = "Bacon";
            Bacon.printbase();
            Bacon.Speak();
            Bacon.Eat();
            Bacon.poop();

            Console.WriteLine();

            Cow Henry = new Cow();

            Henry.name = "Henry";
            Henry.printbase();
            Henry.Speak();
            Henry.Eat();
            Henry.poop();

            Console.WriteLine();

            Horse Stephen = new Horse();

            Stephen.name = "Stephen";
            Stephen.printbase();
            Stephen.Speak();
            Stephen.Eat();
            Stephen.poop();


            Console.WriteLine();

            Chicken Rex = new Chicken();

            Rex.name = "Rex";
            Rex.printbase();
            Rex.Speak();
            Rex.Eat();
            Rex.poop();
        }
Ejemplo n.º 6
0
 void Update()
 {
     if (Input.GetAxis("Eat") > 0)
     {
         Pig pig = gameObjectAdmin.pigs[this.GetComponent <SelectPig>().currentPig].GetComponent <Pig>();
         if (pig.hasFood)
         {
             pig.eating = true;
             pig.Eat();
         }
     }
     else if (Input.GetAxis("Poop") > 0)
     {
         Pig pig = gameObjectAdmin.pigs[this.GetComponent <SelectPig>().currentPig].GetComponent <Pig>();
         if (pig.hasToPoo)
         {
             pig.pooping = true;
             pig.Poop();
         }
     }
 }