public void AddEndurancePart(IPart endurancePart) { if (endurancePart is EndurancePart) { IHitPointsModifyingPart hitPointsModifyingPart = (IHitPointsModifyingPart)endurancePart; this.enduranceParts.Add(hitPointsModifyingPart); } }
public IPart CreatePart(string partType, string model, double weight, decimal price, int additionalParameter) { var partTypeReflaction = Assembly.GetCallingAssembly().GetTypes().FirstOrDefault(x => x.Name == partType); switch (partType) { case "Arsenal": IAttackModifyingPart vehicleInstace = (IAttackModifyingPart)Activator.CreateInstance(partTypeReflaction, new object[] { model, weight, price, additionalParameter }); // if parameters use new Object return(vehicleInstace); case "Shell": IDefenseModifyingPart vehicleInstacee = (IDefenseModifyingPart)Activator.CreateInstance(partTypeReflaction, new object[] { model, weight, price, additionalParameter }); // if parameters use new Object return(vehicleInstacee); case "Endurance": IHitPointsModifyingPart vehicleInstaceee = (IHitPointsModifyingPart)Activator.CreateInstance(partTypeReflaction, new object[] { model, weight, price, additionalParameter }); // if parameters use new Object return(vehicleInstaceee); default: return(null); } }