예제 #1
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            //AbstractEngine bmwEngine = new BMWEngine("Diesel",3.0);
            //bmwEngine.GetInfo();
            //AbstractEngine audiEngine = new AudiEngine("Diesel", 2.0);
            //audiEngine.GetInfo();
            //AbstractEngine MBngine = new MercedesEngine("Diesel", 3.2);
            //MBngine.GetInfo();

            AbstractEngine.AbstractEngine   audiEngine  = new AudiEngine("Diesel", 2.0);
            AbstractBody.AudiBody           audiBody    = new AudiBody("Universal", "Red", 5);
            AbstractWheels.AbstractWheels   audiWheels  = new AudiWheels();
            AbstractFactory.AbstractFactory audiFactory = new AudiFactory();
            AbstractCar.AbstractCar         audi        = audiFactory.CreateCar(audiBody, audiEngine, audiWheels);
            audi.GetInfo();

            AbstractEngine.AbstractEngine   BMWEngine  = new BMWEngine("Diesel", 3.0);
            AbstractBody.BMWBody            BMWBody    = new BMWBody("Sedan", "Black", 5);
            AbstractWheels.AbstractWheels   BMWWheels  = new BMWWheels();
            AbstractFactory.AbstractFactory BMWFactory = new BMWFactory();
            AbstractCar.AbstractCar         BMW        = BMWFactory.CreateCar(BMWBody, BMWEngine, BMWWheels);
            BMW.GetInfo();

            Console.ReadLine();
        }
예제 #2
0
        static void Main()
        {
            var inputBrand = "Audi";

            IFactory factory;

            switch (inputBrand)
            {
            case "Audi":
                factory = new AudiFactory();
                break;

            default:
                factory = new BMWFactory();
                break;
            }

            var car        = factory.CreateCar();
            var motorCycle = factory.CreateMotorCycle();
        }
예제 #3
0
        static void Main(string[] args)
        {
            List<string> menusList = new List<string>();
            menusList.Add("-Add new car");
            menusList.Add("---Get drive");
            menusList.Add("--------Exit");

            List<string> subMenusList = new List<string>();
            subMenusList.Add("---BMW car");
            subMenusList.Add("---Zaz car");

            List<string> subSubMenusList = new List<string>();
            subSubMenusList.Add("Изменить скорость");
            subSubMenusList.Add("Изменить направление");
            subSubMenusList.Add("Переключить Фары");
            subSubMenusList.Add("Показания приборов");

            List<AbstractCar> CarsList = new List<AbstractCar>();

            bool exitCondition = true;

            ZazFactory zaz = new ZazFactory();
            BMWFactory bmw = new BMWFactory();

            CarsList.Add(zaz.CreateCar("Lanos"));
            CarsList.Add(bmw.CreateCar("-X5-"));

            do
            {
                try
                {
                    switch (MenusFunc(menusList))
                    {
                        case 1:
                            Console.WriteLine("Чей автомобиль хотите создать? (de / ua)");
                            if (MenusFunc(subMenusList) == 1)
                            {
                                Console.WriteLine("Введите модель авто:");
                                CarsList.Add(bmw.CreateCar(Console.ReadLine()));
                            }
                            else
                            {
                                Console.WriteLine("Введите модель авто:");
                                CarsList.Add(zaz.CreateCar(Console.ReadLine()));
                            }
                            break;

                        case 2:
                            Console.WriteLine("На каком авто будем кататься?");
                            AbstractCar ChosenCar = CarsList[MenusFunc(
                                CarsList.Select(x => x.model).ToList<string>()) - 1];
                            do
                            {
                                switch (MenusFunc(subSubMenusList))
                                {
                                    case 1: ChosenCar.Speed += int.Parse(Console.ReadLine());
                                        break;
                                    case 2: ChosenCar.Direction += int.Parse(Console.ReadLine());
                                        break;
                                    case 3: ChosenCar.Light = !ChosenCar.Light;
                                        break;
                                    case 4:
                                        Console.WriteLine("Скорость {0}", ChosenCar.Speed);
                                        Console.WriteLine("Направление {0}", ChosenCar.Direction);
                                        Console.WriteLine("Фары {0}", ChosenCar.Light);
                                        break;
                                    default:
                                        break;
                                }

                            } while (ChosenCar.Speed > 0);
                            break;

                        default:
                            exitCondition = !exitCondition;
                            break;
                    }
                }
                catch
                {
                    Console.WriteLine("Проверте формат вводимой строки!...");
                }
            } while (exitCondition);
        }