public void Save() { List <string> output = new List <string>(); output.AddRange(SeedHarvester.Export()); output.AddRange(Composter.Export()); output.AddRange(EggGatherer.Export()); output.AddRange(MeatProcessor.Export()); output.AddRange(FeatherGatherer.Export()); Facilities.ForEach(fac => output.Add(fac.Export())); FileHandler.SaveData(output); }
public Farm() { FileHandler = new FileHandler(); SeedHarvester = new SeedHarvester(FileHandler); Composter = new Composter(FileHandler); MeatProcessor = new MeatProcessor(FileHandler); FeatherGatherer = new FeatherGatherer(FileHandler); EggGatherer = new EggGatherer(FileHandler); FileHandler.Facilities.ForEach(fac => { IFacility newFacility = null; string[] facilityData = fac.Split(":"); string type = facilityData[0]; string name = facilityData[1]; string data = facilityData[2]; switch (type) { case "Chicken House": newFacility = new ChickenHouse(name, data); break; case "Duck House": newFacility = new DuckHouse(name, data); break; case "Grazing Field": newFacility = new GrazingField(name, data); break; case "Plowed Field": newFacility = new PlowedField(name, data); break; case "Natural Field": newFacility = new NaturalField(name, data); break; default: throw new Exception("Invalid data"); } Facilities.Add(newFacility); }); }
private static IGathering SelectHouse(EggGatherer eg) { List <string> options = new List <string>(); _facilities.ForEach(fac => { if (fac is ChickenHouse && eg.Capacity >= 7) { options.Add($"{fac.Name} ({fac.NumAnimals} chickens)"); } else if (fac is DuckHouse && eg.Capacity >= 6) { options.Add($"{fac.Name} ({fac.NumAnimals} ducks)"); } else if (fac is GrazingField gf && eg.Capacity >= 3) { options.Add($"{fac.Name} ({gf.NumOstriches} ostriches)"); }
// Methods public double Process(EggGatherer x) { return(_eggsProduced); }