public string AddPart(IList <string> arguments) { string vehicleModel = arguments[0]; string partType = arguments[1]; string model = arguments[2]; double weight = double.Parse(arguments[3]); decimal price = decimal.Parse(arguments[4]); int additionalParameter = int.Parse(arguments[5]); IPart part = partFactory.CreatePart(partType, model, weight, price, additionalParameter); //switch (partType) //{ // case "Arsenal": // part = new ArsenalPart(model, weight, price, additionalParameter); // break; // case "Shell": // part = new ShellPart(model, weight, price, additionalParameter); // break; // case "Endurance": // part = new EndurancePart(model, weight, price, additionalParameter); // break; //} AddPartToVehicle(part, vehicleModel); //this.vehicles[vehicleModel].AddEndurancePart(part); this.parts.Add(part.Model, part); return(string.Format( GlobalConstants.PartSuccessMessage, partType, part.Model, vehicleModel)); }
public string AddPart(IList <string> arguments) { // Part SA-203 Arsenal Cannon-KA2 300 500 450 string vehicleModel = arguments[0]; string partType = arguments[1]; string modelPart = arguments[2]; double weight = double.Parse(arguments[3]); decimal price = decimal.Parse(arguments[4]); int additionalParameter = int.Parse(arguments[5]); IPart part = partFactory.CreatePart(partType, modelPart, weight, price, additionalParameter); switch (partType) { case "Arsenal": this.vehicles[vehicleModel].AddArsenalPart(part); break; case "Shell": this.vehicles[vehicleModel].AddShellPart(part); break; case "Endurance": this.vehicles[vehicleModel].AddEndurancePart(part); break; } return(string.Format(GlobalConstants.PartSuccessMessage, partType, part.Model, vehicleModel)); }
public string AddPart(IList <string> arguments) { string vehicleModel = arguments[0]; string partType = arguments[1]; string model = arguments[2]; double weight = double.Parse(arguments[3]); decimal price = decimal.Parse(arguments[4]); int additionalParameter = int.Parse(arguments[5]); IPart part = partFactory.CreatePart(partType, model, weight, price, additionalParameter); if (part is IAttackModifyingPart) { this.vehicles[vehicleModel].AddArsenalPart(part); } else if (part is IDefenseModifyingPart) { this.vehicles[vehicleModel].AddShellPart(part); } else { this.vehicles[vehicleModel].AddEndurancePart(part); } this.parts.Add(part.Model, part); return(string.Format( GlobalConstants.PartSuccessMessage, partType, part.Model, vehicleModel)); }
public string AddPart(IList <string> arguments) { string vehicleModel = arguments[0]; string partType = arguments[1]; string model = arguments[2]; double weight = double.Parse(arguments[3]); decimal price = decimal.Parse(arguments[4]); int additionalParameter = int.Parse(arguments[5]); IPart part = partFactory.CreatePart(partType, model, weight, price, additionalParameter); if (part != null) { this.parts.Add(part.Model, part); string methodName = "Add" + partType + "Part"; this.vehicles[vehicleModel].GetType().GetMethod(methodName).Invoke(this.vehicles[vehicleModel], new object[] { part }); } return(string.Format( GlobalConstants.PartSuccessMessage, partType, part.Model, vehicleModel)); }
public string AddPart(IList <string> arguments) { string vehicleModel = arguments[0]; string partType = arguments[1]; string model = arguments[2]; double weight = double.Parse(arguments[3]); decimal price = decimal.Parse(arguments[4]); int additionalParameter = int.Parse(arguments[5]); IPart part = partFactory .CreatePart(partType, model, weight, price, additionalParameter); if (!parts.ContainsKey(part.Model)) { parts.Add(part.Model, part); var method = vehicles[vehicleModel].GetType() .GetMethods().FirstOrDefault(m => m.Name == "Add" + partType + "Part"); method?.Invoke(vehicles[vehicleModel], new object[] { part }); } return(string.Format( GlobalConstants.PartSuccessMessage, partType, part.Model, vehicleModel)); }
public string AddPart(IList <string> arguments) { string vehicleModel = arguments[0]; string partType = arguments[1]; string model = arguments[2]; double weight = double.Parse(arguments[3]); decimal price = decimal.Parse(arguments[4]); int additionalParameter = int.Parse(arguments[5]); IPart part = null; part = partFactory.CreatePart(partType, model, weight, price, additionalParameter); //TODO: If needed, try to do this by reflection switch (partType) { case "Arsenal": this.vehicles[vehicleModel].AddArsenalPart(part); break; case "Shell": this.vehicles[vehicleModel].AddShellPart(part); break; case "Endurance": this.vehicles[vehicleModel].AddEndurancePart(part); break; } //TODO: parts are being added to collection, it is ...possible... that they may not have to be added if (part != null) { this.parts.Add(part.Model, part); } return(string.Format( GlobalConstants.PartSuccessMessage, partType, part.Model, vehicleModel)); }