Exemplo n.º 1
0
        public void DriveEconomically(int distance)
        {
            int distanceToAccelerate = 0;

            _engine.TurnOn();
            Console.WriteLine("Turning on the engine");
            CurrentSpeed = RPMToSpeed(_engine.RPM);
            Console.WriteLine($"Starting speed: {CurrentSpeed}");
            if (FuelTank > 0)
            {
                while (distance > 0)
                {
                    distance -= CurrentSpeed;
                    FuelTank -= _engine.Consumption;
                    Console.WriteLine($"\t Fuel left: {FuelTank}");
                    if (FuelTank <= 0)
                    {
                        Console.WriteLine("OUT OF FUEL");
                        break;
                    }
                    if (distance - distanceToAccelerate <= 0)
                    {
                        _engine.Decelerate();
                        CurrentSpeed = RPMToSpeed(_engine.RPM);
                        Console.WriteLine($"Decelerating to {CurrentSpeed}");
                    }
                    else if (_engine.RPM < 2000)
                    {
                        distanceToAccelerate += CurrentSpeed;
                        _engine.Accelerate();
                        CurrentSpeed = RPMToSpeed(_engine.RPM);
                        Console.WriteLine($"Accelerating to {CurrentSpeed}");
                    }
                    else
                    {
                        Console.WriteLine($"Maintaining speed {CurrentSpeed}");
                    }
                }
            }
            _engine.TurnOff();
            Console.WriteLine("Turning off the engine");
        }
Exemplo n.º 2
0
        public void LiftCargo(int weight, int height)
        {
            int RPMneeded = WeightToRPM(weight);

            if (RPMneeded > _engine.MaxRPM)
            {
                Console.WriteLine("Engine isnt good enough");
                return;
            }
            int currentHeight = 0;

            _engine.TurnOn();
            Console.WriteLine("Turning on the engine");
            if (FuelTank > 0)
            {
                while (height > currentHeight)
                {
                    FuelTank -= _engine.Consumption;
                    Console.WriteLine($"\t Fuel left: {FuelTank}");
                    if (FuelTank <= 0)
                    {
                        Console.WriteLine("OUT OF FUEL");
                        break;
                    }
                    if (_engine.RPM < RPMneeded)
                    {
                        _engine.Accelerate();
                        Console.WriteLine($"Accelerating to {_engine.RPM} RPM");
                    }
                    else
                    {
                        currentHeight += LiftingSpeed;
                        Console.WriteLine($"Lifting cargo. Height = {currentHeight}");
                    }
                }
            }
            if (FuelTank > 0)
            {
                while (_engine.RPM > 1000)
                {
                    _engine.Decelerate();
                    Console.WriteLine($"Decelerating to {_engine.RPM} RPM");
                }
            }
            _engine.TurnOff();
            Console.WriteLine("Turning off the engine");
        }
Exemplo n.º 3
0
 public void Drive()
 {
     indicators.RightTurnOn();
     engine.Accelerate();
     indicators.RightTurnOff();
 }
Exemplo n.º 4
0
 public void Accelerate()
 {
     _engine.Accelerate();
 }