public string RegisterHarvester(List <string> arguments) { var toReturn = string.Empty; try { if (arguments[0] == "Sonic") { Harvester harvester = new SonicHarvester(arguments[1], double.Parse(arguments[2]), double.Parse(arguments[3]), int.Parse(arguments[4])); Harvesters.Add(harvester); toReturn = $"Successfully registered Sonic Harvester - {arguments[1]}"; } else { Harvester harvester = new HammerHarvester(arguments[1], double.Parse(arguments[2]), double.Parse(arguments[3])); Harvesters.Add(harvester); toReturn = $"Successfully registered Hammer Harvester - {arguments[1]}"; } } catch (ArgumentException e) { toReturn = e.Message; } return(toReturn); }
public string RegisterHarvester(List <string> arguments) { Harvester harvester; var type = arguments[0]; var id = arguments[1]; var oreOutput = double.Parse(arguments[2]); var energyRequirement = double.Parse(arguments[3]); if (CheckIdUniqueness("harvester", id)) { if (type == "Sonic") { var sonicFactor = int.Parse(arguments[4]); try { harvester = HarvesterFactory.CreateSonic(id, oreOutput, energyRequirement, sonicFactor); } catch (Exception e) { return(e.Message); } } else { try { harvester = HarvesterFactory.CreateHammer(id, oreOutput, energyRequirement); } catch (Exception e) { return(e.Message); } } Harvesters.Add(harvester); return($"Successfully registered {type} Harvester - {id}"); } return("Harvester is not registered, because of it's id"); }