Ejemplo n.º 1
0
        public static void ChargeElectricVehicle(string i_LicsenseNumber, float i_NumOfMinutesToCharge)
        {
            Engine         engine         = getVehicleByLicenseNumber(i_LicsenseNumber).Vehicle.Engine;
            ElectricEngine electricEngine = engine as ElectricEngine;

            if (electricEngine != null)
            {
                electricEngine.Charge(i_NumOfMinutesToCharge);
            }
            else
            {
                throw new ArgumentException("Vehicle has a fuel engine");
            }
        }
Ejemplo n.º 2
0
        public static void InitEngine(eVehicleType i_Type, float i_CurrentEnergy, out Engine o_Engine, Vehicle i_Vehicle)
        {
            float    maxEnergy;
            eGasType gasType = k_EnumDefault;

            switch (i_Type)
            {
            case eVehicleType.ElectricCar:
                maxEnergy = k_MaxTimeElectricCar;
                break;

            case eVehicleType.ElectricMotorcycle:
                maxEnergy = k_MaxTimeElectricMotorcycle;
                break;

            case eVehicleType.FuelCar:
                maxEnergy = k_MaxFuelCar;
                gasType   = k_CarGas;
                break;

            case eVehicleType.FuelMotorcycle:
                maxEnergy = k_MaxFuelMotorcycle;
                gasType   = k_MotorcycleGas;
                break;

            case eVehicleType.Truck:
                maxEnergy = k_MaxFuelTruck;
                gasType   = k_TruckGas;
                break;

            default:
                throw new FormatException("Invalid Vehicle Type");
            }

            if (i_Type == eVehicleType.ElectricCar || i_Type == eVehicleType.ElectricMotorcycle)
            {
                o_Engine = new ElectricEngine(i_CurrentEnergy, maxEnergy);
            }
            else
            {
                o_Engine = new FuelEngine(gasType, i_CurrentEnergy, maxEnergy);
            }

            i_Vehicle.Engine = o_Engine;
        }