Ejemplo n.º 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
Ejemplo n.º 2
0
        public void RegisterDriver(List <string> commandArgs)
        {
            try
            {
                string driverType = commandArgs[0];
                string name       = commandArgs[1];
                int    hp         = int.Parse(commandArgs[2]);
                double fuelAmount = double.Parse(commandArgs[3]);

                Tyre   tyre = this.GetTyre(commandArgs.Skip(4).ToList());
                Car    car  = new Car(hp, fuelAmount, tyre);
                Driver driver;
                if (driverType == "Aggressive")
                {
                    driver = new AggressiveDriver(name, car);
                }
                if (driverType == "Endurance")
                {
                    driver = new AggressiveDriver(name, car);
                }
                else
                {
                    throw new ArgumentException();
                }
                this.racingDriversDic.Add(name, driver);
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 3
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)
            {
                ;
            }
        }
Ejemplo n.º 4
0
        private Driver CreateDriver(List <string> commandArgs)
        {
            Driver driver     = null;
            Car    car        = null;
            Tyre   tyre       = null;
            string driverType = commandArgs[0];
            string tyreType   = commandArgs[4];

            switch (driverType)
            {
            case "Aggressive":
                switch (tyreType)
                {
                case "Ultrasoft":
                    double tyreHardness = double.Parse(commandArgs[5]);
                    double tyreGrip     = double.Parse(commandArgs[6]);
                    tyre = new UltrasoftTyre(tyreHardness, tyreGrip);
                    int    carHp         = int.Parse(commandArgs[2]);
                    double carFuelAmount = double.Parse(commandArgs[3]);
                    car = new Car(carHp, carFuelAmount, tyre);
                    string driverName = commandArgs[1];
                    driver = new AggressiveDriver(driverName, car);
                    break;

                case "Hard":
                    double tyreHardness_ = double.Parse(commandArgs[5]);
                    tyre = new HardTyre(tyreHardness_);
                    int    carHp_         = int.Parse(commandArgs[2]);
                    double carFuelAmount_ = double.Parse(commandArgs[3]);
                    car = new Car(carHp_, carFuelAmount_, tyre);
                    string driverName_ = commandArgs[1];
                    driver = new AggressiveDriver(driverName_, car);
                    break;
                }
                break;

            case "Endurance":
                switch (tyreType)
                {
                case "Ultrasoft":
                    double tyreHardness = double.Parse(commandArgs[5]);
                    double tyreGrip     = double.Parse(commandArgs[6]);
                    tyre = new UltrasoftTyre(tyreHardness, tyreGrip);
                    int    carHp         = int.Parse(commandArgs[2]);
                    double carFuelAmount = double.Parse(commandArgs[3]);
                    car = new Car(carHp, carFuelAmount, tyre);
                    string driverName = commandArgs[1];
                    driver = new AggressiveDriver(driverName, car);
                    break;

                case "Hard":
                    double tyreHardness_ = double.Parse(commandArgs[5]);
                    tyre = new HardTyre(tyreHardness_);
                    int    carHp_         = int.Parse(commandArgs[2]);
                    double carFuelAmount_ = double.Parse(commandArgs[3]);
                    car = new Car(carHp_, carFuelAmount_, tyre);
                    string driverName_ = commandArgs[1];
                    driver = new AggressiveDriver(driverName_, car);
                    break;
                }
                break;
            }

            return(driver);
        }