Пример #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!");
 }
Пример #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);
 }
Пример #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}.");
     }
 }
Пример #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!");
     }
 }
Пример #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;
     }
 }
Пример #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.");
     }
 }
Пример #7
0
 public void Start(Сar car)
 {
     throw new Exception("Motor is already working!");
 }
Пример #8
0
 public void Speed(Сar c, double speed)
 {
     throw new Exception("Car is not riding at the moment, speed can't be changed!");
 }
Пример #9
0
 public void Stop(Сar c)
 {
     throw new Exception("Car is already stoped!");
 }
Пример #10
0
 public void Start(Сar car)
 {
     car.isMotorOn = true;
     car.ChangeState(MotorOn.ReturnStatus);
 }
Пример #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();
            }
        }