Exemple #1
0
        //The buying and tracking of animals
        public static void PickAnimal()
        {
            Console.Clear();
            int animalChoice;

            Console.Write($"\nGreat! We have ");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write($"${farmMoney}");
            Console.ResetColor();
            Console.WriteLine(" to spend on animals");
            if (farmMoney < costOfChicken)
            {
                NotEnoughMoney();
            }
            Console.WriteLine("\nHere is a list of the Animals and their cost:");
            Console.WriteLine("\n#\tAnimal\t\tCost");
            Console.WriteLine("---------------------------");
            Console.WriteLine($"1)\tHorse\t\t{costOfHorse}");
            Console.WriteLine($"2)\tCow\t\t{costOfCow}");
            Console.WriteLine($"3)\tChicken\t\t{costOfChicken}");
            Console.WriteLine($"4)\tPig\t\t{costOfPig}");
            Console.WriteLine("5)\tPlay with the animals");

            Console.WriteLine("\nHere is your current Farm:\n");
            Console.WriteLine("Animal\t\t# on Farm");
            Console.WriteLine("---------------------------");
            Console.WriteLine($"Horse\t\t{Horse.numOfHorses}");
            Console.WriteLine($"Cow\t\t{Cow.numOfCows}");
            Console.WriteLine($"Chicken\t\t{Chicken.numOfChickens}");
            Console.WriteLine($"Pig\t\t{Pig.numOfPigs}");
            Console.Write("\nWhat animal should we add to the farm? [1-5]: ");
            try
            {
                animalChoice = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception)
            {
                animalChoice = -1;
            }
            switch (animalChoice)
            {
            case 1:     //Horse
            {
                if ((farmMoney - costOfHorse) < 0)
                {
                    NotEnoughMoney();
                }
                farmMoney -= costOfHorse;
                Horse mrEd = new Horse();
                animalsOnFarm += "1";
                //BuyOrPlay();
                break;
            }

            case 2:     //Cow
            {
                if ((farmMoney - costOfCow) < 0)
                {
                    NotEnoughMoney();
                }
                farmMoney -= costOfCow;
                Cow hershey = new Cow();
                animalsOnFarm += "2";
                // BuyOrPlay();
                break;
            }

            case 3:     //Chicken
            {
                if ((farmMoney - costOfChicken) < 0)
                {
                    NotEnoughMoney();
                }
                farmMoney -= costOfChicken;
                Chicken rooster = new Chicken();
                animalsOnFarm += "3";
                //BuyOrPlay();
                break;
            }

            case 4:     //Pig
            {
                if ((farmMoney - costOfPig) < 0)
                {
                    NotEnoughMoney();
                }
                farmMoney -= costOfPig;
                Pig porkey = new Pig();
                animalsOnFarm += "4";
                //BuyOrPlay();

                break;
            }

            case 5:     //Makes sure there is at least 1 animal bought
            {
                if (Horse.numOfHorses + Cow.numOfCows + Pig.numOfPigs + Chicken.numOfChickens == 0)
                {
                    Console.WriteLine("\nYou need to buy at least one animal first!");
                    Continue();
                    PickAnimal();
                }
                TimeToPlay();
                break;
            }

            default:
            {
                Console.WriteLine("\nThat type of animal is not for sale yet");
                Continue();
                //PickAnimal();
                break;
            }
            }
            PickAnimal();
        }
Exemple #2
0
        //Action selection for the animal chosen
        public static void Activity(int animalNum)
        {
            Horse   mrEd    = new Horse("Mr. Ed");
            Pig     porky   = new Pig("Porky");
            Chicken rooster = new Chicken("Mr. Clucks");
            Cow     hershey = new Cow("Hershey");

            Console.Clear();
            int actionNum = 0;

            Console.WriteLine("\n#\tAction");
            Console.WriteLine("---------------");
            Console.WriteLine("1)\tSpeak");
            Console.WriteLine("2)\tWalk");
            Console.WriteLine("3)\tEat");
            Console.WriteLine("4)\tSleep");
            Console.WriteLine("5)\tBacon");
            Console.WriteLine("6)\tPick a different animal");
            Console.WriteLine("7)\tLeave the Farm");
            Console.Write("\nWhat would you like to do with your ");
            switch (animalNum)
            {
            case 1:
                Console.Write("Horse?");
                break;

            case 2:
                Console.Write("Cow?");
                break;

            case 3:
                Console.Write("Chicken?");
                break;

            case 4:
                Console.Write("Pig?");
                break;

            default:
                Console.WriteLine("That is not something the animals know how to do!?");
                Console.WriteLine("Lets make sure we have the right animal.");
                Continue();
                TimeToPlay();
                break;
            }
            Console.Write(" [1-7]: ");
            try
            {
                actionNum = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception)
            {
                Console.WriteLine("\nThat is not something the animals know how to do!?");
                Console.WriteLine("Lets make sure we have the right animal.");
                Continue();
                TimeToPlay();
            }
            Console.WriteLine("");
            switch (10 * animalNum + actionNum)
            {
            //Horse cases
            case 11:
                mrEd.Speak();
                break;

            case 12:
                mrEd.walk();
                break;

            case 13:
                mrEd.eat();
                break;

            case 14:
                mrEd.sleep();
                break;

            case 15:
            case 25:
            case 35:
                Console.WriteLine("\nThis action is only for pigs...");
                break;

            //Cow Cases
            case 21:
                hershey.Speak();
                break;

            case 22:
                hershey.walk();
                break;

            case 23:
                hershey.eat();
                break;

            case 24:
                hershey.sleep();
                break;

            //Chicken cases
            case 31:
                rooster.Speak();
                break;

            case 32:
                rooster.walk();
                break;

            case 33:
                rooster.eat();
                break;

            case 34:
                rooster.sleep();
                break;

            //Pig Cases
            case 41:
                porky.Speak();
                break;

            case 42:
                porky.walk();
                break;

            case 43:
                porky.eat();
                break;

            case 44:
                porky.sleep();
                break;

            case 45:
                porky.Bacon();
                break;

            //Pick a different animal cases
            case 16:
            case 26:
            case 36:
            case 46:
                TimeToPlay();
                break;

            //Leave the Famr cases
            case 17:
            case 27:
            case 37:
            case 47:
                Farewell();
                break;
            }
            Continue();
            TimeToPlay();
        }