Example #1
0
        public static void CollectInput(Farm farm)
        {
            Console.WriteLine("1. Sesame");
            Console.WriteLine("2. SunFlower");
            Console.WriteLine("3. WildFlower");

            Console.WriteLine();
            Console.WriteLine("What are you buying today?");

            Console.Write("> ");
            string choice = Console.ReadLine();

            switch (Int32.Parse(choice))
            {
            case 1:
                ChoosePlowedField.CollectInput(farm, new Sesame());
                break;

            case 2:
                ChooseSunflowerField.CollectInput(farm, new SunFlower());
                break;

            case 3:
                ChooseNaturalField.CollectInput(farm, new WildFlower());
                break;

            default:
                break;
            }
        }
        public static void CollectInput(Farm farm)
        {
            Console.WriteLine("1. Sesame");
            Console.WriteLine("2. Sunflower");
            Console.WriteLine("3. Wildflower");


            Console.WriteLine();
            Console.WriteLine("What are you buying today?");

            Console.Write("> ");
            string choice = Console.ReadLine();

            switch (choice)
            {
            case "1":
                ChoosePlowedField.CollectInput(farm, new Sesame());
                break;

            case "2":
                ChooseSunflowerField.CollectInput(farm, new Sunflower());

                break;

            case "3":
                ChooseNaturalField.CollectInput(farm, new Wildflower());
                break;

            default:
                Console.WriteLine($"Invalid option");
                Console.WriteLine();
                break;
            }
        }
        public static void CollectInput(Farm farm)
        {
            Console.WriteLine("1. Sesame");
            Console.WriteLine("2. Sunflower");
            Console.WriteLine("3. Wildflower");

            Console.WriteLine();
            Console.WriteLine("What are you buying today?");

            Console.Write("> ");
            string choice = Console.ReadLine();

            try
            {
                if (int.Parse(choice) <= 3 && int.Parse(choice) >= 1)
                {
                    switch (Int32.Parse(choice))
                    {
                    case 1:
                        ChoosePlowedField.CollectInput(farm, new Sesame());
                        break;

                    case 2:
                        ChooseSunflowerField <Sunflower> .CollectInput(farm, new Sunflower());

                        break;

                    case 3:
                        ChooseNaturalField.CollectInput(farm, new Wildflower());
                        break;

                    default:
                        Console.WriteLine("Invalid option. Redirecting to main menu.");
                        Thread.Sleep(2000);
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Invalid option. Please try again.");
                    Thread.Sleep(2000);
                    DisplayBanner();
                    PurchaseSeed.CollectInput(farm);
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("Invalid option. Please try again.");
                Thread.Sleep(2000);
                DisplayBanner();
                PurchaseSeed.CollectInput(farm);
            }
        }
        public static void CollectInput(Farm farm)
        {
            Console.WriteLine(" 1. Sesame");
            Console.WriteLine(" 2. Sunflower");
            Console.WriteLine(" 3. Wildflower");

            Console.WriteLine();
            if (ThereIsNoRoomForTheSeedBeingPurchased)
            {
                Console.WriteLine("Sorry, but you don't have anywhere to put that seed. Please make a different selection.");
            }

            Console.WriteLine("  Choose seed to purchase");

            Console.Write("> ");
            string seedChoice = Console.ReadLine();

            if (seedChoice == "1")
            {
                seedChoice = "Sesame";
            }

            if (seedChoice == "2")
            {
                seedChoice = "Sunflower";
            }

            if (seedChoice == "3")
            {
                seedChoice = "Wildflower";
            }

            Console.WriteLine($"  How many {seedChoice} would you like to plant?");

            int amountChoice = Int32.Parse(Console.ReadLine());

            if (seedChoice == "Sesame")
            {
                ChoosePlowedField.CollectInput(farm, seedChoice, amountChoice);
            }
            if (seedChoice == "Sunflower")
            {
                ChooseSunflowerField.CollectInput(farm, seedChoice, amountChoice);
            }
            if (seedChoice == "Wildflower")
            {
                ChooseNaturalField.CollectInput(farm, seedChoice, amountChoice);
            }
        }
        public static void CollectInput(Farm farm)
        {
            try
            {
                Console.WriteLine("1. Sunflower");
                Console.WriteLine("2. Wildflower");
                Console.WriteLine("3. Sesame");

                Console.WriteLine();
                Console.WriteLine("What are you buying today?");

                Console.Write("> ");
                string choice = Console.ReadLine();

                switch (Int32.Parse(choice))
                {
                case 1:
                    ChooseSunflowerField.CollectInput(farm, new Sunflower());
                    break;

                case 2:
                    ChooseNaturalField.CollectInput(farm, new Wildflower());
                    break;

                case 3:
                    ChoosePlowedField.CollectInput(farm, new Sesame());
                    break;

                default:
                    Console.WriteLine("Please enter a valid selction.");
                    Thread.Sleep(1000);
                    Utils.Clear();
                    CollectInput(farm);
                    break;
                }
            }
            catch
            {
                Console.WriteLine("Please enter a valid selection.");
                Thread.Sleep(1000);
                Utils.Clear();
                CollectInput(farm);
            }
        }
Example #6
0
        public static void CollectInput(Farm farm, string seedChoice, int amountChoice)
        {
            Console.Clear();

            //     //anything that is of type object can be put in this list
            //     List<object> sunflowerFields = new List<object>();

            //     farm.PlowedFields.ForEach(pf => {

            //     //cast from type PlowedField to type object
            //     object transformedField = pf as object;
            //     sunflowerFields.Add(transformedField);
            //     });

            //   farm.NaturalFields.ForEach(nf => {

            //     //cast from type PlowedField to type object
            //     object transformedField = nf as object;
            //     sunflowerFields.Add(transformedField);
            //     });



            NaturalField anyNaturalFieldWithRoom = farm.NaturalFields.Find(nf => (nf.MaxCapacity - nf.CurrentCapacity) >= amountChoice);
            PlowedField  anyPlowedFieldWithRoom  = farm.PlowedFields.Find(pf => (pf.MaxCapacity - pf.CurrentCapacity) >= amountChoice);

            if (anyNaturalFieldWithRoom != null || anyPlowedFieldWithRoom != null)
            {
                for (int i = 0; i < farm.NaturalFields.Count; i++)
                {
                    NaturalField currentField = farm.NaturalFields[i];
                    if (currentField.MaxCapacity - currentField.CurrentCapacity >= amountChoice)
                    {
                        Console.WriteLine($"{i + 1}. Natural field - {currentField.CurrentCapacity} of {currentField.MaxCapacity} rows of plants\n");
                    }
                }

                for (int i = 0; i < farm.PlowedFields.Count; i++)
                {
                    PlowedField currentField = farm.PlowedFields[i];
                    //this allows the plowed fields to be displayed after the available natural fields
                    if (currentField.MaxCapacity - currentField.CurrentCapacity >= amountChoice)
                    {
                        Console.WriteLine($"{i + farm.NaturalFields.Count + 1}. Plowed field - {currentField.CurrentCapacity} of {currentField.MaxCapacity} rows of plants\n");
                    }
                }

                Console.WriteLine();

                // How can I output the type of plant chosen here?
                if (UserTriedToSelectAFullFacility)
                {
                    Console.WriteLine("That field does not have enough room.");
                }
                Console.WriteLine($"Place the plants where?");

                Console.Write("> ");
                int choice = Int32.Parse(Console.ReadLine());

                //user is buying multiple seeds so we need a list holding however many they want, then adding the list of resources to field which is on the farm

                //if their choice is a number greater than Natural Fields count, then they are choosing a plowed field
                if (choice > farm.NaturalFields.Count)
                {
                    List <ISeedProducing> plants = new List <ISeedProducing>();

                    //determine which type of plant they want and then with for loop adding the appropriate amount(amountChoice parameter) to list of plants

                    for (int i = 0; i < amountChoice; i++)
                    {
                        plants.Add(new Sunflower());
                    }



                    //now we're adding the list of plants to the specific field that the user chose from the menu
                    //choice(user input) - farm.NaturalFields.Count (number of natural fields listed) - 1 (bc index starts from 0 not 1)
                    PlowedField target = farm.PlowedFields[choice - farm.NaturalFields.Count - 1];

                    if (target.MaxCapacity - target.CurrentCapacity >= amountChoice)
                    {
                        farm.PlowedFields[choice - 1 - farm.NaturalFields.Count].AddResource(farm, plants);
                        ChooseSunflowerField.UserTriedToSelectAFullFacility = false;
                    }
                    else
                    {
                        UserTriedToSelectAFullFacility = true;
                        ChooseSunflowerField.CollectInput(farm, seedChoice, amountChoice);
                    }

                    //make sure that this variable is set to false, in case user was previous directed
                    PurchaseSeed.ThereIsNoRoomForTheSeedBeingPurchased = false;
                }
                else
                {
                    List <ICompostProducing> plants = new List <ICompostProducing>();

                    //determine which type of plant they want and then with for loop adding the appropriate amount(amountChoice parameter) to list of plants

                    NaturalField target = farm.NaturalFields[choice - 1];
                    if (target.MaxCapacity - target.CurrentCapacity >= amountChoice)
                    {
                        for (int i = 0; i < amountChoice; i++)
                        {
                            plants.Add(new Sunflower());
                        }



                        //now we're adding the list of plants to the specific field that the user chose from the menu
                        //choice(user input) - 1 (bc index starts from 0 not 1)
                        target.AddResource(farm, plants);

                        //make sure that this variable is set to false, in case user was previous directed
                        PurchaseSeed.ThereIsNoRoomForTheSeedBeingPurchased = false;
                        UserTriedToSelectAFullFacility = false;
                    }
                    else
                    {
                        UserTriedToSelectAFullFacility = true;
                        ChooseSunflowerField.CollectInput(farm, seedChoice, amountChoice);
                    }
                }

                /*
                 *  Couldn't get this to work. Can you?
                 *  Stretch goal. Only if the app is fully functional.
                 */
                // farm.PurchaseResource<IGrazing>(animal, choice);
            } //else if there isn't room for all the plants the user is trying to add, this else statement notifies user and takes to previous menu
            else
            {
                PurchaseSeed.ThereIsNoRoomForTheSeedBeingPurchased = true;
                Program.DisplayBanner();
                PurchaseSeed.CollectInput(farm);
            }
        }