Inheritance: Animal
Exemple #1
0
        static void Main()
        {
            /* Objects and Classes*/
            
            Animal dogAnimal = new Animal(); // You create an instance of the Class 'Animal' with the empty constructor
            dogAnimal.Name = "Dog"; //You set the property Name to Dog

            Animal catAnimal = new Animal("Cat"); // You create an instance of the Class 'Animal' with a parameter for Name

            Console.WriteLine("Dog's animal name is " + dogAnimal.Name);
            Console.WriteLine("Cats's animal name is " + catAnimal.Name);

            //Two vars can reference the same Object
            Animal bearOne = new Animal("Bear");
            Animal bearTwo = bearOne;
            Console.WriteLine("bearTwo name is " + bearTwo.Name);

            //One var can reference different Objects (at different time)
            Animal lion = new Animal("Tiger");
            lion = new Animal("Lion");
            Console.WriteLine("lion name is " + lion.Name);

            /* Inheritance*/

            Animal dog = new Dog("Dog");
            Console.WriteLine("Dog's name is " + dog.Name);

            Animal cat = new Cat("Cat");
            Console.WriteLine("Cat's name is " + cat.Name);
            Console.WriteLine("Cat's, which are Animals, breathe like this ");
            cat.Breathe(); //method defined for all Animals 

            Console.ReadLine();
        }
Exemple #2
0
        static void Visit()
        {
            Console.WriteLine("YOU CHOSE TO VISIT THE FARM");
            Console.ReadLine();

            //CONSTRUCTORS
            Pig     Napoleon = new Pig("Napoleon");
            Horse   Clover   = new Horse("Clover");
            Dog     Dog      = new Dog("Dog");
            Pig     Snowball = new Pig("Snowball");
            Horse   Mollie   = new Horse("Mollie");
            Pig     Piggie   = new Pig("Piggie");
            Horse   Horsey   = new Horse("Horsey");
            Cat     Cat      = new Cat("Cat");
            Chicken Dave     = new Chicken("Dave");
            Pig     Pig      = new Pig("Pig");
            Chicken Chicken  = new Chicken("Chicken");
            Sheep   Sheep    = new Sheep("Sheep");
            Horse   Horse    = new Horse("Horse");



            FarmStory.Intro();
            Console.WriteLine("<Napoleon escorts you to the farm>");
            Console.ReadLine();

            //SOME OF THE METHODS
            Dog.Talk();
            Cat.Meow();
            Horsey.Neigh();
            Horsey.Speak("Horsey");
            Piggie.Oink();
            Sheep sheep = new Sheep("Sheepie");

            sheep.Speak("Sheepie");
            sheep.Eat();
            Dave.Cluck("Dave");
            Console.ReadLine();

            FarmStory.Scene1();
            Console.ReadLine();
            string input = "";

            do   //THESE METHODS ARE FOUND IN ANIMAL.CS
            {
                Console.WriteLine("What would you like to learn about?");
                Console.WriteLine("1. The Pigs");
                Console.WriteLine("2. The Horses");
                Console.WriteLine("3. The Cat");
                Console.WriteLine("4. The Dog");
                Console.WriteLine("5. The Sheep");
                Console.WriteLine("6. The Chickens");
                Console.WriteLine("<When you are ready to move on, enter any other value>");
                input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    Piggie.GetInfo("Pigs", 4, 2, "pink");
                    break;

                case "2":
                    Horse.GetInfo("Horses", 4, 2, "Brown");
                    break;

                case "3":
                    Cat.GetInfo("cat", 4, 2, "black");
                    break;

                case "4":
                    Dog.GetInfo("dog", 4, 2, "tan");
                    break;

                case "5":
                    Dog.GetInfo("sheep", 4, 2, "white");
                    break;

                case "6":
                    Dog.GetInfo("chickens", 2, 2, "tan");
                    break;

                default:
                    break;
                }
            } while (input == "1" || input == "2" || input == "3" || input == "4" || input == "5" || input == "6");

            Console.ReadLine();



            do   //THESE METHODS ARE FOUND IN ANIMAL.CS
            {
                Console.WriteLine("Who would you like to talk to?");
                Console.WriteLine("1. Piggie");
                Console.WriteLine("2. Horsey");
                Console.WriteLine("3. The Cat");
                Console.WriteLine("4. The Dog");
                Console.WriteLine("<When you are ready to move on, enter any other value>");
                input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    Piggie.Dialogue("Piggie");
                    break;

                case "2":
                    Horsey.Dialogue(4, 2, "Horsey");
                    break;

                case "3":
                    Cat.Dialogue();
                    break;

                case "4":
                    Dog.Dialogue("Dog");
                    break;

                default:
                    break;
                }
            } while (input == "1" || input == "2" || input == "3" || input == "4");


            FarmStory.Scene2();

            FarmStory.EndScene();
        }