コード例 #1
0
        static void Main(string[] args)
        {
            Shelter shelter = new Shelter();

            Pet pet = new Pet();

            List <Pet> ListOfPets = new List <Pet>();

            Console.WriteLine("Hello! Welcome to Virtual Pets\n");

            bool petChoice = true;

            while (petChoice)
            {
                Console.WriteLine("What would you like to do?");
                Console.WriteLine("NOTE: If you do not have a pet, please create one!");
                Console.WriteLine("1. Create a new organic pet");
                Console.WriteLine("2. Create a new robotic pet");
                Console.WriteLine("3. Display each pet status");
                Console.WriteLine("4. Feed your Pet");
                Console.WriteLine("5. Play with your Pet");
                Console.WriteLine("6. Attend To Pet Health");
                Console.WriteLine("7. Quit");

                string menuChoice = Console.ReadLine();
                switch (menuChoice)
                {
                case "1":
                    Console.WriteLine("What is the name for your organic pet?");
                    string name = Console.ReadLine();
                    Console.WriteLine("What species is your organic pet?");
                    string species = Console.ReadLine();
                    pet = new Organic(name, species);
                    shelter.AddPet(pet);
                    Console.ReadKey();
                    break;

                case "2":
                    Console.WriteLine("What is the name of your robotic pet?");
                    name    = Console.ReadLine();
                    species = "Robot";
                    pet     = new Robotic(name, species);
                    shelter.AddPet(pet);
                    Console.ReadKey();
                    break;

                case "3":
                    foreach (Pet selectedPet in shelter.ListOfPets)
                    {
                        selectedPet.DisplayStatus();
                    }
                    Console.ReadKey();
                    break;

                case "4":
                    pet = shelter.SelectPet();
                    pet.Feed();
                    Console.WriteLine($"You fed/oiled {pet.GetName()}.");
                    pet.Tick();
                    break;

                case "5":
                    pet = shelter.SelectPet();
                    pet.Play();
                    Console.WriteLine($"You and {pet.GetName()} played in the meadow together!");
                    pet.Tick();
                    break;

                case "6":
                    pet = shelter.SelectPet();
                    pet.AttendToPetHealth();
                    Console.WriteLine($"You took {pet.GetName()} to the vet/mechanic for their health.");
                    pet.Tick();
                    break;

                case "7":
                    petChoice = false;
                    break;

                default:
                    Console.WriteLine("Invalid entry.");
                    break;
                }
                Console.WriteLine("Press Enter to continue.");
                Console.ReadKey();
                Console.Clear();
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello! Welcome to Virtual Pets");
            Pet     userPet    = new Pet();
            Shelter myShelter  = new Shelter();
            Organic organicPet = new Organic();
            Robotic roboticPet = new Robotic();

            Console.WriteLine("Would you like your pet to be ...");
            Console.WriteLine("1. An organic pet.");
            Console.WriteLine("2. A robotic pet.");
            string petTypeChoice = Console.ReadLine();

            switch (petTypeChoice)
            {
            case "1":
                organicPet.MakeNewPet();
                userPet = new Organic(organicPet.GetName(), organicPet.GetSpecies());
                myShelter.AddPet(userPet);
                break;

            case "2":
                roboticPet.MakeNewPet();
                userPet = new Robotic(roboticPet.GetName(), roboticPet.GetSpecies());
                myShelter.AddPet(userPet);
                break;

            default:
                Console.WriteLine("Invalid input.");
                break;
            }


            bool playingGame = true;

            while (playingGame)
            {
                Console.Clear();

                foreach (Pet pet in myShelter.ListOfPets)
                {
                    pet.GiveStats();
                    Console.WriteLine();
                    Console.ReadLine();
                }

                userPet = myShelter.SelectPet();
                userPet.MenuOptions();

                string menuChoice = Console.ReadLine();

                switch (menuChoice)
                {
                case "1":
                    userPet.Feed();
                    break;

                case "2":
                    userPet.QuenchThirst();
                    break;

                case "3":
                    userPet.Play();
                    break;

                case "4":
                    userPet.SeeDoctor();
                    break;

                case "5":
                    Console.WriteLine($"You did nothing.");
                    break;

                case "6":
                    playingGame = false;
                    Console.WriteLine("Thanks for playing!");
                    break;

                default:
                    Console.WriteLine("Invalid input.");
                    break;
                }

                userPet.Tick();
                organicPet.CheckHealth();
                organicPet.CheckHunger();
                organicPet.CheckThirst();
                userPet.CheckBoredom();
                Console.WriteLine("Press any key to continue.");
                Console.ReadKey();
            }

            Console.ReadLine();
        }