Ejemplo n.º 1
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.º 2
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.º 3
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();
        }