Beispiel #1
0
        } // done

        public void RegisterDriver(List <string> commandArgs)
        {
            string type         = commandArgs[1];
            string name         = commandArgs[2];
            int    hp           = int.Parse(commandArgs[3]);
            double fuelAmount   = double.Parse(commandArgs[4]);
            string tyreType     = commandArgs[5];
            double tyreHardness = double.Parse(commandArgs[6]);
            Tyre   tyre;

            if (tyreType == "Ultrasoft")
            {
                double grip = double.Parse(commandArgs[7]);
                tyre = new UltrasoftTyre(tyreHardness, grip);
            }
            else
            {
                tyre = new HardTyre(tyreHardness);
            }

            Car    car = new Car(hp, fuelAmount, tyre);
            Driver driver;

            if (type == "Aggressive")
            {
                driver = new AggressiveDriver(name, 0, car);
                drivers.Add(driver.Name, driver);
            }
            else if (type == "Endurance")
            {
                driver = new EnduranceDriver(name, 0, car);
                drivers.Add(driver.Name, driver);
            }
        } // done
Beispiel #2
0
        public void RegisterDriver(List <string> commandArgs)
        {
            try
            {
                // вземаме информацията от входните данни
                string driverType    = commandArgs[0];
                string driverName    = commandArgs[1];
                int    carHP         = int.Parse(commandArgs[2]);
                double carFuelAmount = double.Parse(commandArgs[3]);
                string tyreType      = commandArgs[4];
                double tyreHardness  = double.Parse(commandArgs[5]);

                // създаваме подходящите обекти
                Tyre newTyre = null;
                if (tyreType == "Ultrasoft")
                {
                    double tyreGrip = double.Parse(commandArgs[6]);
                    newTyre = new UltrasoftTyre(tyreHardness, tyreGrip);
                }
                else if (tyreType == "Hard")
                {
                    newTyre = new HardTyre(tyreHardness);
                }
                Car    newCar    = new Car(carHP, carFuelAmount, newTyre);
                Driver newDriver = null;
                if (driverType == "Aggressive")
                {
                    newDriver = new AggressiveDriver(newCar, driverName);
                }
                else if (driverType == "Endurance")
                {
                    newDriver = new EnduranceDriver(newCar, driverName);
                }

                // добавяме го в списъка
                registeredDrivers.Add(driverName, newDriver);
            }
            catch (Exception)
            {
                ;
            }
        }