Пример #1
0
        static void Main(string[] args)
        {
            //Driver bob = new Driver("Bob", 7);
            //Driver jill = new Driver("Jill", 4);
            //Driver greg = new Driver("Greg", 9);
            //Driver anne = new Driver("Anne", 7);

            //Car hyundai = new Car("Hyundai", 75);
            //Car mazda = new Car("Mazda", 125);
            //Car ferrari = new Car("Ferrari", 450);
            //Car porche = new Car("Porche", 370);
            //hyundai.SetDriver(anne);
            //mazda.SetDriver(greg);
            Car[] cars = new Car[4]
            {
                new Car("Hyundai", 75),
                new Car("Mazda", 125),
                new Car("Ferrari", 450),
                new Car("Porche", 370)
            };
            Driver[] drivers = new Driver[4]
            {
                new Driver("Bob", 7),
                new Driver("Jill", 4),
                new Driver("Greg", 9),
                new Driver("Anne", 7)
            };


            Console.WriteLine("Pick First Car");
            int firstCarIndex = SelectCar(cars);

            Console.WriteLine("Pick Second Car");
            int secondCarIndex = SelectCar(cars);

            while (firstCarIndex == secondCarIndex)
            {
                Console.WriteLine("You can't pick a same car twice");
                Console.WriteLine("Pick First Car");
                firstCarIndex = SelectCar(cars);
                Console.WriteLine("Pick Second Car");
                secondCarIndex = SelectCar(cars);
            }
            Console.WriteLine($"Pick Driver For the {cars[firstCarIndex].Model}");
            int firstDriverIndex = SelectDriver(drivers);

            Console.WriteLine($"Pick a Driver for the {cars[secondCarIndex].Model}");
            int secondDriverIndex = SelectDriver(drivers);

            while (firstDriverIndex == secondDriverIndex)
            {
                Console.WriteLine("You cant pick the same driver twice");
                Console.WriteLine($"Pick Driver For the {cars[firstCarIndex]}");
                firstDriverIndex = SelectDriver(drivers);
                Console.WriteLine($"Pick a Driver for the {cars[secondCarIndex]}");
                secondDriverIndex = SelectDriver(drivers);
            }

            Car    firstCar    = cars[firstCarIndex];
            Driver firstDriver = drivers[firstDriverIndex];

            firstCar.SetDriver(firstDriver);

            Car    secondCar    = cars[secondCarIndex];
            Driver secondDriver = drivers[secondDriverIndex];

            secondCar.SetDriver(secondDriver);
            Console.WriteLine(RaceCars(firstCar, secondCar));
        }