예제 #1
0
        static void Main(string[] args)
        {
            //Animal animal = new Pig(); new Cow(); new Goat(); new Chicken();
            Console.WriteLine("Choose from the following options: ");
            Console.WriteLine("Chicken, Pig, Cow, Goat: ");
            string userInput = Console.ReadLine();

            Chicken myChicken = new Chicken();

            if (userInput == "Chicken" || userInput == "chicken")

            {
                myChicken.Eat();
                myChicken.NumberOfLegs();
                myChicken.Speak();
                myChicken.Use();
            }
            else if (userInput == "Pig" || userInput == "pig")
            {
                Pig myPig = new Pig();
                myPig.Eat();
                myPig.NumberOfLegs();
                myPig.Speak();
                myPig.Use();
            }
            else if (userInput == "Cow" || userInput == "cow")
            {
                Cow myCow = new Cow();
                myCow.Eat();
                myCow.NumberOfLegs();
                myCow.Speak();
                myCow.Use();
            }

            else if (userInput == "Goat" || userInput == "goat")
            {
                Goat myGoat = new Goat();
                myGoat.Eat();
                myGoat.NumberOfLegs();
                myGoat.Speak();
                myGoat.Use();
            }
            else
            {
                Console.WriteLine("Wrong Input");
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            List <Animal> FarmHouse = new List <Animal>(); //FarmHouse has a List of Animals

            Chicken chicken1 = new Chicken("Moe", "Cluck", true, 10, 3);
            Cow     cow1     = new Cow("Curly", "Moo", true, 200, 7);
            Pig     pig1     = new Pig("Larry", "Cluck", true, 120, 5);
            Dog     dog1     = new Dog();

            FarmHouse.Add(chicken1);
            FarmHouse.Add(cow1);
            FarmHouse.Add(pig1);

            for (int i = 0; i < FarmHouse.Count(); i++)
            {
                FarmHouse[i].DisplayInfo();
                FarmHouse[i].Speak();
            }

            Console.Read();
        }
예제 #3
0
        public Barn()
        {
            Animals = new Animal[4];
            Animal an1 = new Cow("Flower");
            Animal an2 = new Horse("Ben");
            Animal an3 = new Pig("Martha");
            Animal an4 = new Sheep("Meggie");

            Farmers = new Farmer[3];
            Farmer fa1 = new Farmer("John", 15);
            Farmer fa2 = new Farmer("Samanta", 4);
            Farmer fa3 = new Farmer("Nick", 7);

            Animals[0] = an1;
            Animals[1] = an2;
            Animals[2] = an3;
            Animals[3] = an4;

            Farmers[0] = fa1;
            Farmers[1] = fa2;
            Farmers[2] = fa3;
        }
예제 #4
0
파일: Farm.cs 프로젝트: AndreL2507/ISTA220
        private static void Menu3(int menu)
        {
            int menu3 = Convert.ToInt32(Console.ReadLine());

            if (menu3 == 1)
            {
                Pig pig1 = new Pig();
                pig1.Speak();
                Animal2();
                Menu3(menu);
            }
            else if (menu3 == 2)
            {
                Pig pig1 = new Pig();
                pig1.Eat();
                Animal2();
                Menu3(menu);
            }
            else if (menu3 == 3)
            {
                Pig pig1 = new Pig();
                pig1.Run();
                Animal2();
                Menu3(menu);
            }
            else if (menu3 == 4)
            {
                Pig pig1 = new Pig();
                pig1.Attack();
                Animal2();
                Menu3(menu);
            }
            else
            {
                Menu();
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            string userInput;

            Console.WriteLine
                ("Which animal would you like to meet?");
start:
            Console.WriteLine
                ("\r\n1. Pig\r\n2. Cow\r\n3. Horse\r\n4. Sheep\r\n5. Chicken");
            int userSelect = int.Parse(userInput = Console.ReadLine());

            if (userSelect >= 1 && userSelect <= 5)
            {
                switch (userSelect)
                {
                case 1:
                    Animals animal1 = new Pig();
                    animalInfo(animal1);
                    break;

                case 2:
                    Animals animal2 = new Cow();
                    animalInfo(animal2);
                    break;

                case 3:
                    Animals animal3 = new Horse();
                    animalInfo(animal3);
                    break;

                case 4:
                    Animals animal4 = new Sheep();
                    animalInfo(animal4);
                    break;

                case 5:
                    Animals animal5 = new Chicken();
                    animalInfo(animal5);
                    break;
                }
            }
            else
            {
                Console.WriteLine
                    ("Please enter an integer between 1-5.");
                goto start;
            }

            string userInput1;

            Console.WriteLine
                ("Which crop would you like to explore?");
            Console.WriteLine
                ("1. Corn\r\n2. Soybeans\r\n3. Wheat");
start1:
            int userSelect1 = int.Parse(userInput1 = Console.ReadLine());

            if (userSelect1 >= 1 && userSelect1 <= 3)
            {
                switch (userSelect1)
                {
                case 1:
                    Crops crop1 = new Corn();
                    cropInfo(crop1);
                    break;

                case 2:
                    Crops crop2 = new Soybean();
                    cropInfo(crop2);
                    break;

                case 3:
                    Crops crop3 = new Wheat();
                    cropInfo(crop3);
                    break;
                }
            }
            else
            {
                Console.WriteLine
                    ("Please enter an integer between 1-3.");
                goto start1;
            }
            string userInput2;

            Console.WriteLine
                ("Would you like to visit more of the farm?");
            Console.WriteLine
                ("1. Yes\r\n2. No");
start2:
            int userSelect2 = int.Parse(userInput2 = Console.ReadLine());

            if (userSelect2 >= 1 && userSelect2 <= 2)
            {
                switch (userSelect2)
                {
                case 1:
                    goto start;

                case 2:
                    return;
                }
            }
            else
            {
                Console.WriteLine
                    ("Please enter an integer between 1-2.");
                goto start2;
            }

            void animalInfo(Animals input)
            {
                var animal = input;

                Console.WriteLine
                    ("Your animal type is {0}\r\n" +
                    "Your animal's name is {1}\r\n" +
                    "Your animal's color is {2}\r\n" +
                    "Your animal says \"{3}\"",
                    animal.AnimalType, animal.AnimalName,
                    animal.AnimalColor, animal.AnimalNoise);
                Console.ReadLine();
            }

            void cropInfo(Crops input)
            {
                var crop = input;

                Console.WriteLine
                    ("Your crop type is {0}\r\n" +
                    "Your crop's purpose is {1}\r\n" +
                    "Your crop's color is {2}\r\n",
                    crop.CropType, crop.CropPurpose,
                    crop.CropColor);
                Console.ReadLine();
            }
        }