Ejemplo n.º 1
0
 public void streight(Сar car)
 {
     if (car.speed == 0)
     {
         throw new Exception("Car is stoped! Can't ride!");
     }
     throw new Exception("Car is allready riding stright!");
 }
Ejemplo n.º 2
0
 public void streight(Сar car)
 {
     if (car.speed == 0)
     {
         throw new Exception("Car is stoped! Cant right!");
     }
     car.xchange     = 0;
     car.fuelper100 -= 0.1;
     car.ChangeDirection(Front.ReturnStatus);
 }
Ejemplo n.º 3
0
 public void Stop(Сar car)
 {
     if (car.speed == 0)
     {
         car.isMotorOn = false;
         car.ChangeState(MotorOff.ReturnStatus);
     }
     else
     {
         throw new Exception($"Beffore stopping the car, make its speed being 0! Now speed is {car.speed}.");
     }
 }
Ejemplo n.º 4
0
 public void turn(Сar car, int x)
 {
     if (car.speed == 0)
     {
         throw new Exception("Car is stoped! Cant turn!");
     }
     if (car.xchange == x)
     {
         throw new Exception("Car's direction is already this!");
     }
     else
     {
         throw new Exception("Cant turn from one side to another! Driver should align the car first!");
     }
 }
Ejemplo n.º 5
0
 public void turn(Сar car, int x)
 {
     if (car.speed == 0)
     {
         throw new Exception("Car is stoped! Cant turn!");
     }
     if (car.xchange == x)
     {
         throw new Exception("Car's direction is already this!");
     }
     else
     {
         car.xchange = x;
         car.ChangeDirection(Turn.ReturnStatus);
         car.fuelper100 += 0.1;
     }
 }
Ejemplo n.º 6
0
 public void Speed(Сar car, double speed)
 {
     if (speed >= 0)
     {
         car.speed = speed;
         if (speed == 0)
         {
             car.fuelper100 = 0;
         }
         else
         {
             car.fuelper100 = 6 + (Math.Abs(100 - speed) * 0.01);
         }
     }
     else
     {
         throw new Exception("Speed is not changed. It can't be less then 0.");
     }
 }
Ejemplo n.º 7
0
 public void Start(Сar car)
 {
     throw new Exception("Motor is already working!");
 }
Ejemplo n.º 8
0
 public void Speed(Сar c, double speed)
 {
     throw new Exception("Car is not riding at the moment, speed can't be changed!");
 }
Ejemplo n.º 9
0
 public void Stop(Сar c)
 {
     throw new Exception("Car is already stoped!");
 }
Ejemplo n.º 10
0
 public void Start(Сar car)
 {
     car.isMotorOn = true;
     car.ChangeState(MotorOn.ReturnStatus);
 }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            Сar    mycar = new Сar();
            String cond;
            bool   cicle = true;

            Console.WriteLine("-------------Menu----------------");
            Console.WriteLine("1.On the motor.");
            Console.WriteLine("2.Off the motor.");
            Console.WriteLine("3.Turn.");
            Console.WriteLine("4.Ride streight.");
            Console.WriteLine("5.Change speed.");
            Console.WriteLine("6.Close.");
            Console.Write("Input function num: ");
            cond = Console.ReadLine();
            while (cicle == true)
            {
                if (cond == "1")
                {
                    try
                    {
                        mycar.OnMotor();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                if (cond == "2")
                {
                    try
                    {
                        mycar.OffMotor();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                if (cond == "3")
                {
                    String turncond;
                    Console.Write("Input direction. 1 for left, 2 for right: ");
                    turncond = Console.ReadLine();

                    try
                    {
                        if (turncond == "1")
                        {
                            mycar.TurnLeft();
                        }
                        else
                        {
                            mycar.TurnRight();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                if (cond == "4")
                {
                    try
                    {
                        mycar.RideStreight();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                if (cond == "5")
                {
                    double speed;
                    Console.Write("Input speed: ");
                    speed = double.Parse(Console.ReadLine());
                    try
                    {
                        mycar.ChangeSpeed(speed);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                if (cond == "6")
                {
                    if (mycar.Exit() == true)
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Before exiting turn off the motor!");
                    }
                }
                Console.WriteLine(mycar.CarInfo());
                Console.Write("Input function num: ");
                cond = Console.ReadLine();
            }
        }