예제 #1
0
파일: Garage.cs 프로젝트: drimoch/Garage
        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");
            }
        }
예제 #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;
        }