Ejemplo n.º 1
0
 public override void ProcessResources()
 {
     Resources.ForEach(animal => {
         IEggProducing resource = (IEggProducing)animal;
         System.Console.WriteLine($"{resource.Gather()} eggs were produced");
     });
 }
Ejemplo n.º 2
0
        public static void CollectInput(Farm farm, IEggProducing animal)
        {
            Utils.Clear();
            Console.WriteLine($"Place the animal where?");

            while (true)
            {
                try
                {
        public static void CollectInput(Farm farm, IEggProducing animal)
        {
            Utils.Clear();

            bool Placed = false;

            while (Placed == false)
            {
                for (int i = 0; i < farm.DuckHouses.Count; i++)
                {
                    Console.WriteLine(farm.DuckHouses[i].Capacity == farm.DuckHouses[i].ducksInDuckHouse
                        ? $"{i + 1}. Duck House (Full)"
                        : $"{i + 1}. Duck House ({farm.DuckHouses[i].ducksInDuckHouse} Ducks)");
                }

                Console.WriteLine();

                Console.WriteLine($"Where would you like to place the {animal.GetType().Name}?");

                Console.Write("> ");

                try
                {
                    int choice = Int32.Parse(Console.ReadLine());

                    if (farm.DuckHouses[choice - 1].ducksInDuckHouse == farm.DuckHouses[choice - 1].Capacity)
                    {
                        Console.WriteLine("**** That facility is not large enough ****");
                        Console.WriteLine("****     Please choose another one      ****");
                        choice = Int32.Parse(Console.ReadLine());
                    }

                    else
                    {
                        farm.DuckHouses[choice - 1].AddResource(animal);
                        Placed = true;
                        Console.WriteLine("Break Point");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Please enter only numbers");
                }
            }
        }
Ejemplo n.º 4
0
        public void ProcessResults(List <IResource> resProcessed)
        {
            Dictionary <string, double> eggsProduced = new Dictionary <string, double>();

            resProcessed.ForEach(animal => {
                IEggProducing resource = (IEggProducing)animal;
                try
                {
                    eggsProduced.Add(resource.GetType().Name, resource.CollectEggs());
                }
                catch (Exception)
                {
                    eggsProduced[resource.GetType().Name] += resource.CollectEggs();
                }
            });
            foreach (KeyValuePair <string, double> animal in eggsProduced)
            {
                System.Console.WriteLine($"{animal.Value} {animal.Key} eggs were collected");
            }
        }
Ejemplo n.º 5
0
                    static void chickenHouseSelect(Farm farm, IEggProducing animal)
                    {
                        var filteredChickenHouses = farm.ChickenHomes.Where(home => home.Capacity > home.AnimalCount).ToList();

                        if (filteredChickenHouses.Count() == 0)
                        {
                            Console.WriteLine("No houses are avaliable. Please add another house...");
                            Console.ReadLine();
                        }
                        else
                        {
                            for (int i = 0; i < filteredChickenHouses.Count(); i++)
                            {
                                Console.Write($"{i+1}. Chicken House {filteredChickenHouses[i].ShortId} has {filteredChickenHouses[i].AnimalCount} chickens");

                                Console.WriteLine();
                            }

                            int choice = Int32.Parse(Console.ReadLine());
                            filteredChickenHouses[choice - 1].AddResource(animal);
                        }
                    }
 public void GatheredAnimals(IEggProducing animal)
 {
     _animalsUsed.Add(animal);
 }
Ejemplo n.º 7
0
        public static bool CollectInput(List <IResource> resourceList, List <IResource> discardList, double spaceAvailable, IEquipment equipment)
        {
            Console.Clear();

            var plantResources = new List <string>();

            resourceList.OfType <Plant>().ToList().ForEach(pl => plantResources.Add(pl.Type));

            List <ResourceType> resourceTypeTotals = (from resource in resourceList
                                                      group resource by resource.GetType().Name into resourceType
                                                      select new ResourceType {
                Type = resourceType.Key, Total = resourceType.Count()
            }).ToList();

            int rNum = 1;

            Console.WriteLine("Select a resource to process:");
            foreach (var resourceType in resourceTypeTotals)
            {
                if (plantResources.Contains(resourceType.Type))
                {
                    Console.WriteLine($"{rNum}. {resourceType.Type} ({resourceType.Total} rows available)");
                }
                else
                {
                    Console.WriteLine($"{rNum}. {resourceType.Type} ({resourceType.Total} available)");
                }
                rNum++;
            }
            Console.Write(">");

            int resourceTypeIndex = Int32.Parse(Console.ReadLine()) - 1;

            var selectedResource = resourceTypeTotals[resourceTypeIndex];

            if (plantResources.Contains(selectedResource.Type))
            {
                Console.WriteLine($"There are {selectedResource.Total} {selectedResource.Type} rows. How many do you want to process?");
            }
            else
            {
                Console.WriteLine($"There are {selectedResource.Total} {selectedResource.Type}s. How many do you want to process?");
            }
            Console.Write(">");
            int numSelected = Int32.Parse(Console.ReadLine());

            if (numSelected > selectedResource.Total)
            {
                Console.WriteLine($"There are not that many {selectedResource.Type}s available");
                Console.WriteLine("Press enter to return to list of facilities");
                Console.ReadLine();
                return(false);
            }
            else
            {
                //find animals in availableResourcesList that match the type of animal that was selected and limit the number to the number of animals the user wants to process
                var processThese = (from animal in resourceList
                                    where animal.GetType().Name == selectedResource.Type
                                    select animal
                                    ).Take(numSelected).ToList();
                //add them to discardList
                int numToAdd = numSelected;

                if (equipment.Name == "Egg Gatherer" && (processThese[0] is IEggProducing))
                {
                    IEggProducing eggResource     = (IEggProducing)processThese[0];
                    int           eggsPerResource = eggResource.CollectEggs();
                    numToAdd = numSelected * eggsPerResource;
                }


                if (numToAdd > spaceAvailable)
                {
                    Console.WriteLine("You have exceeded the maximum number of resources that this processor can handle");
                    Console.WriteLine("Press enter to return to list of facilities");
                    Console.ReadLine();
                    return(false);
                }
                else
                {
                    discardList.AddRange(processThese);
                    Console.WriteLine("Ready to process? (Y/n)");
                    var processYN = Console.ReadLine();
                    if (processYN.ToLower() == "y")
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 internal void AddResource(IEggProducing animal)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 9
0
        public static void CollectInput(List <Facility> facilityList, IEquipment equipment)
        {
            bool            readyToProcess      = false;
            List <Facility> availableFacilities = facilityList;
            var             equipmentCapacity   = equipment.Capacity;

            do
            {
                Console.Clear();
                var resourceCount = ChooseEquipment._discardList.Count;

                if (equipment.Name == "Egg Gatherer")
                {
                    resourceCount = 0;
                    ChooseEquipment._discardList.ForEach(resource => {
                        IEggProducing eggRes = (IEggProducing)resource;
                        resourceCount       += eggRes.CollectEggs();
                    });
                }

                if (resourceCount >= equipmentCapacity)
                {
                    Console.WriteLine("You have reached the maximum number that can be processed at one time");
                    Console.WriteLine("Press enter to process resources");
                    Console.ReadLine();
                    readyToProcess = true;
                }
                else
                {
                    Console.Clear();
                    if (ChooseEquipment.selectedFacility == null && equipment.Name == "Composter")
                    {
                        Composter compostEquipment = (Composter)equipment;
                        Console.WriteLine($"The {equipment.Name} can process either {equipmentCapacity} plant resources or {compostEquipment.CapacityGoat} animal resources at one time.");
                    }
                    else
                    {
                        Console.WriteLine($"The {equipment.Name} can process {equipmentCapacity} resources at one time.");
                    }
                    Console.WriteLine($"You have currently selected {resourceCount} resources to process.");
                    Console.WriteLine();

                    //if the equipment type is composter then if the discardList has resources in it, only show facilities that contain that resource, else show all the facilities
                    if (equipment.Name == "Composter" && resourceCount != 0)
                    {
                        if (ChooseEquipment.selectedFacility.Type == "Grazing Field")
                        {
                            availableFacilities = facilityList.Where(facility => facility.Type == "Grazing Field").ToList();
                        }
                        else
                        {
                            availableFacilities = facilityList.Where(facility => facility.Type != "Grazing Field").ToList();
                        }
                    }
                    if (resourceCount != 0)
                    {
                        Console.WriteLine("0. Ready to process resources");
                    }
                    for (var i = 0; i < availableFacilities.Count; i++)
                    {
                        var currentFacility = availableFacilities[i];
                        Console.WriteLine($"{i + 1}. {currentFacility.Type} ({currentFacility.Total} {currentFacility.Category})");
                    }

                    Console.WriteLine();
                    Console.WriteLine("Choose facility to process resources from.");

                    Console.Write("> ");

                    int facilityIndex = Int32.Parse(Console.ReadLine()) - 1;
                    if (facilityIndex == -1)
                    {
                        readyToProcess = true;
                    }
                    else
                    {
                        var facilityChoosen = availableFacilities[facilityIndex];

                        if (equipment.Name == "Composter" && resourceCount == 0)
                        {
                            ChooseEquipment.selectedFacility = facilityChoosen;
                            Composter compostEquipment = (Composter)equipment;
                            if (ChooseEquipment.selectedFacility.Type == "Grazing Field")
                            {
                                equipmentCapacity = compostEquipment.CapacityGoat;
                            }
                            else
                            {
                                equipmentCapacity = compostEquipment.Capacity;
                            }
                        }

                        Console.Clear();


                        //add only resources that the equipment can process and that have not already been selected to discard to availableResourcesList
                        List <IResource> availableResourcesList = equipment.GetFacilityResources(facilityChoosen.Resources).Where(resource => !ChooseEquipment._discardList.Contains(resource)).ToList();

                        if (availableResourcesList.Count == 0)
                        {
                            Console.WriteLine("This facility does not have any resources that can be processed");
                            Console.ReadLine();
                        }
                        else
                        {
                            var availableSpace = equipmentCapacity - resourceCount;
                            readyToProcess = ChooseResource.CollectInput(availableResourcesList, ChooseEquipment._discardList, availableSpace, equipment);
                        }
                    }
                }
            }while(!readyToProcess);

            equipment.ProcessResources(ChooseEquipment._discardList, availableFacilities);
            ChooseEquipment._discardList     = new List <IResource>();
            ChooseEquipment.selectedFacility = null;

            Console.WriteLine();
            Console.WriteLine("Please press enter to return to main menu");
            Console.ReadLine();
        }