Example #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
Example #2
0
        public void DriverBoxes(List <string> commandArgs)
        {
            string reason = commandArgs[0];
            string name   = commandArgs[1];
            Driver driver = this.DriversLis.First(se => se.Name == name);

            driver.TotalTime += 20;
            if (reason == "Refuel")
            {
                driver.Refuel(double.Parse(commandArgs[2]));
            }
            else
            {
                if (commandArgs[2] == "Ultrasoft")
                {
                    double grip    = double.Parse(commandArgs[3]);
                    double hardnes = double.Parse(commandArgs[2]);
                    Tyre   tyre    = new UltrasoftTyre(hardnes, grip);
                    driver.ChangeTyre(tyre);
                }
                else
                {
                    double hardnes = double.Parse(commandArgs[2]);
                    Tyre   tyre    = new HardTyre(hardnes);
                    driver.ChangeTyre(tyre);
                }
            }
        }
Example #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)
            {
                ;
            }
        }
Example #4
0
        private Tyre GetTyre(IList <string> tyreArgs)
        {
            string tyreType     = tyreArgs[0];
            double tyreHardness = double.Parse(tyreArgs[1]);

            if (tyreType == "Hard")
            {
                Tyre curr = new HardTyre(tyreHardness);
                return(curr);
            }
            else if (tyreType == "Ultrasoft")
            {
                double tyreGrip = double.Parse(tyreArgs[2]);
                Tyre   curr     = new UltrasoftTyre(tyreHardness, tyreGrip);
                return(curr);
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Example #5
0
        } // done

        public void DriverBoxes(List <string> commandArgs)// done
        {
            string reasonToBox = commandArgs[1];
            string driversName = commandArgs[2];

            drivers[driversName].TotalTime += 20;

            if (reasonToBox == "Refuel")
            {
                double fuelAmount = double.Parse(commandArgs[3]);

                if (drivers[driversName].Car.FuelAmount + fuelAmount > 160)
                {
                    drivers[driversName].Car.FuelAmount = 160;
                }
                else
                {
                    drivers[driversName].Car.FuelAmount += fuelAmount;
                }
            }
            else if (reasonToBox == "ChangeTyres")
            {
                string tyreType = commandArgs[3];
                double hardness = double.Parse(commandArgs[4]);

                if (tyreType == "Ultrasoft")
                {
                    double grip = double.Parse(commandArgs[5]);
                    Tyre   tyre = new UltrasoftTyre(hardness, grip);
                    drivers[driversName].Car.Tyre = tyre;
                }
                else if (tyreType == "Hard")
                {
                    Tyre tyre = new HardTyre(hardness);
                    drivers[driversName].Car.Tyre = tyre;
                }
            }
        }
Example #6
0
        public void DriverBoxes(List <string> commandArgs)
        {
            // вземаме информацията от входните данни
            string reasonToBox = commandArgs[0];
            string driverName  = commandArgs[1];
            Driver driverInBox = registeredDrivers[driverName];

            if (driverInBox == null)
            {
                return;
            }
            driverInBox.TotalTime += 20;

            if (reasonToBox == "ChangeTyres")
            {
                string tyreType     = commandArgs[2];
                double tyreHardness = double.Parse(commandArgs[3]);
                Tyre   newTyre      = null;
                if (tyreType == "Ultrasoft")
                {
                    double tyreGrip = double.Parse(commandArgs[4]);
                    newTyre = new UltrasoftTyre(tyreHardness, tyreGrip);
                }
                else if (tyreType == "Hard")
                {
                    newTyre = new HardTyre(tyreHardness);
                }
                // извършваме указаните промени
                driverInBox.Car.Tyre = newTyre;
            }
            else if (reasonToBox == "Refuel")
            {
                double fuelAmount = double.Parse(commandArgs[2]);
                // извършваме указаните промени
                driverInBox.Car.FuelAmount += fuelAmount;
            }
        }
        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);
        }