public void RefuelVehicl(float i_EnergyAmount, int i_EngineType, string i_LicenseNumber) { if (r_AllVehiclesInfo != null && r_AllVehiclesInfo.ContainsKey(i_LicenseNumber)) { FuelEngine fuelEngine = r_AllVehiclesInfo[i_LicenseNumber].OwenersVehicle.Engine as FuelEngine; if (fuelEngine != null) { eEngineType engineType = (eEngineType)i_EngineType; if (engineType == fuelEngine.CurrentEngineType) { r_AllVehiclesInfo[i_LicenseNumber].OwenersVehicle.Engine.AddEnergy(engineType, i_EnergyAmount); } else { throw new ArgumentException(string.Format("This vehicle cannot refuel by {0}", engineType.ToString())); } } else { throw new ArgumentException("This vehicle does not have a fuel engine"); } } else { throw new ArgumentException("This vehicle is not in our garage"); } }
public object CreateGarageObject(object[] i_Parameters, Type i_Type, Type i_VehicleType) { object obj; Enums.eVehicleType vehicleType = (Enums.eVehicleType)Enum.Parse(typeof(Enums.eVehicleType), i_VehicleType.Name); if (i_Type == typeof(Wheel)) { float maxEnergy = (float)VehiclesDefualtConfigurations.sr_DefaultDictionary[vehicleType]["Maximum Air Pressure"]; ConstructorInfo ci = i_Type.GetConstructors()[0]; i_Parameters[i_Parameters.Length - 1] = maxEnergy; obj = new Wheel((string)i_Parameters[0], (float)i_Parameters[1], (float)i_Parameters[2]); } if (i_Type == typeof(ElectricEngine)) { float maxEnergy = (float)VehiclesDefualtConfigurations.sr_DefaultDictionary[vehicleType]["Maximum Energy"]; ConstructorInfo ci = i_Type.GetConstructors()[0]; i_Parameters[i_Parameters.Length - 1] = maxEnergy; obj = new ElectricEngine((float)i_Parameters[0], (float)i_Parameters[1]); } else if (i_Type == typeof(FuelEngine)) { Enums.eFuelTypes fuelType = (Enums.eFuelTypes)VehiclesDefualtConfigurations.sr_DefaultDictionary[vehicleType]["Fuel Type"]; float maxEnergy = (float)VehiclesDefualtConfigurations.sr_DefaultDictionary[vehicleType]["Maximum Energy"]; ConstructorInfo ci = i_Type.GetConstructors()[0]; i_Parameters[i_Parameters.Length - 2] = maxEnergy; i_Parameters[i_Parameters.Length - 1] = fuelType; obj = new FuelEngine((float)i_Parameters[0], (float)i_Parameters[1], (Enums.eFuelTypes)i_Parameters[2]); } else { ConstructorInfo ci = i_Type.GetConstructors()[0]; obj = ci.Invoke(i_Parameters); } return(obj); }
internal FuelCar(string i_LicenseNumber, string i_ModelType, string i_ManufacturerName) : base(i_LicenseNumber, i_ModelType, i_ManufacturerName) { m_TypeEngine = new FuelEngine(m_FuleType, k_MaxAmountOfFuel); }