Exemple #1
0
        public void RegisterDriver(List <string> commandArgs)
        {
            //•	RegisterDriver {type} {name} {hp} {fuelAmount} {tyreType} {tyreHardness}
            //•	RegisterDriver {type} {name} {hp} {fuelAmount} Ultrasoft {tyreHardness} { grip}
            if (commandArgs.Count > 8)
            {
                return;
            }
            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         = null;

            if (commandArgs.Count == 8)
            {
                double grip = double.Parse(commandArgs[7]);
                tyre = tyreFactory.CreateTyre(tyreType, tyreHardness, grip);
            }
            else
            {
                tyre = tyreFactory.CreateTyre(tyreType, tyreHardness);
            }
            if (tyre != null)
            {
                Car car = carFactory.CreateCar(hp, fuelAmount, tyre);
                if (car != null)
                {
                    Driver driver = driverFactory.CreateDriver(type, name, car);
                    drivers.Add(driver);
                }
            }
        }
Exemple #2
0
    public Driver CreateDriver(List <string> args)
    {
        var type       = args[0];
        var driverName = args[1];
        var hp         = int.Parse(args[2]);
        var fuelAmount = double.Parse(args[3]);

        Tyre newTyre;
        Car  newCar;

        switch (type)
        {
        case "Aggressive":
            newTyre = tyreFactory.CreateTyre(args.Skip(4).ToList());
            newCar  = new Car(hp, fuelAmount, newTyre);
            return(new AggressiveDriver(driverName, newCar));

        case "Endurance":
            newTyre = tyreFactory.CreateTyre(args.Skip(4).ToList());
            newCar  = new Car(hp, fuelAmount, newTyre);
            return(new EnduranceDriver(driverName, newCar));

        default:
            throw new InvalidOperationException();
        }
    }
    public Drivers CreateDriver(List <string> commandArgs)
    {
        var type       = commandArgs[0];
        var name       = commandArgs[1];
        var hp         = int.Parse(commandArgs[2]);
        var fuelAmount = double.Parse(commandArgs[3]);

        var tyreArgs = commandArgs.Skip(4).ToList();

        switch (type)
        {
        case "Aggressive":

            Car argCar = new Car(hp, fuelAmount, tyreFactory.CreateTyre(tyreArgs));
            return(new AggressiveDriver(name, argCar));


        case "Endurance":
            Car endurCar = new Car(hp, fuelAmount, tyreFactory.CreateTyre(tyreArgs));
            return(new EnduranceDriver(name, endurCar));

        default:
            throw new ArgumentException("Invalid car type!");
        }
    }
    public void ChangeTyres(List <string> args)
    {
        this.Box();
        Tyre tyre = TyreFactory.CreateTyre(args);

        this.Car.ChangeTyres(tyre);
    }
    public Driver CreateDriver(List <string> arguments)
    {
        TyreFactory tyreFactory = new TyreFactory();

        string driverType = arguments[0];
        string name       = arguments[1];
        int    hp         = int.Parse(arguments[2]);
        double fuelAmount = double.Parse(arguments[3]);


        List <string> tyreArguments = arguments.Skip(4).ToList();

        Tyre tyre = tyreFactory.CreateTyre(tyreArguments);

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

        if (driverType == "Aggressive")
        {
            return(new AggressiveDriver(name, car));
        }
        else if (driverType == "Endurance")
        {
            return(new EnduranceDriver(name, car));
        }
        else
        {
            throw new ArgumentException();
        }
    }
Exemple #6
0
    public void DriverBoxes(List <string> commandArgs)
    {
        var boxReason     = commandArgs[0];
        var driverName    = commandArgs[1];
        var currentDriver = this.drivers.FirstOrDefault(d => d.Name == driverName);

        if (currentDriver.BeenInBox)
        {
            return;
        }

        var beenInBox = false;

        switch (boxReason)
        {
        case "ChangeTyres":
            currentDriver.Car.Tyre = tyreFactory.CreateTyre(commandArgs.Skip(2).ToList());
            beenInBox = true;
            break;

        case "Refuel":
            double fuelAmount = Double.Parse(commandArgs[2]);
            currentDriver.Car.FuelAmount += fuelAmount;
            beenInBox = true;
            break;
        }

        if (beenInBox)
        {
            currentDriver.BeenInBox  = true;
            currentDriver.TotalTime += 20;
        }
    }
    public Driver CreateDriver(List <string> commandArgs)
    {
        string type       = commandArgs[0];
        string name       = commandArgs[1];
        int    hp         = int.Parse(commandArgs[2]);
        double fuelAmount = double.Parse(commandArgs[3]);

        TyreFactory   tf       = new TyreFactory();
        List <string> tyreArgs = commandArgs.Skip(4).ToList();


        Tyre tyre      = tf.CreateTyre(tyreArgs);
        Car  driverCar = new Car(hp, fuelAmount, tyre);


        if (type == "Aggressive")
        {
            return(new AggressiveDriver(name, driverCar));
        }
        else if (type == "Endurance")
        {
            return(new EnduranceDriver(name, driverCar));
        }

        throw new ArgumentException("Invalid Driver Type");
    }
Exemple #8
0
    public static Driver CreateDriver(List <string> arguments)
    {
        string driverType = arguments[0];
        string driverName = arguments[1];
        int    hp         = int.Parse(arguments[2]);
        double fuelAmount = double.Parse(arguments[3]);


        try
        {
            arguments = arguments.Skip(4).Take(3).ToList();
            Tyre tyre = TyreFactory.CreateTyre(arguments);

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

            if (driverType == "Aggressive")
            {
                Driver driver = new AggressiveDriver(driverName, car);
                return(driver);
            }
            else if (driverType == "Endurance")
            {
                Driver driver = new EnduranceDriver(driverName, car);
                return(driver);
            }
            return(null);
        }
        catch (Exception)
        {
            return(null);
        }
    }
Exemple #9
0
    public static Driver CreateDriver(List <string> commandArgs)
    {
        Driver driver;

        var type       = commandArgs[0];
        var name       = commandArgs[1];
        var hp         = int.Parse(commandArgs[2]);
        var fuelAmount = double.Parse(commandArgs[3]);

        var args = commandArgs.Skip(4).ToList();
        var tyre = TyreFactory.CreateTyre(args);

        var car = new Car(hp, fuelAmount, tyre);

        if (type == "Aggressive")
        {
            driver = new AggressiveDriver(name, car);
        }
        else if (type == "Endurance")
        {
            driver = new EnduranceDriver(name, car);
        }
        else
        {
            throw new ArgumentException();
        }

        return(driver);
    }
Exemple #10
0
    public static Driver CreateDriver(List <string> args)
    {
        var type = args[0];
        var name = args[1];

        var hp         = int.Parse(args[2]);
        var fuelAmount = double.Parse(args[3]);

        var tyreArgs = args.Skip(4).ToList();
        var tyre     = TyreFactory.CreateTyre(tyreArgs);

        var car = new Car(hp, fuelAmount, tyre);

        switch (type)
        {
        case "Aggressive":
            return(new AggressiveDriver(name, car));

        case "Endurance":
            return(new EnduranceDriver(name, car));

        default:
            throw new ArgumentException();
        }
    }
    public void RegisterDriver(List <string> commandArgs)
    {
        try
        {
            string type         = commandArgs[0];
            string name         = commandArgs[1];
            int    hp           = int.Parse(commandArgs[2]);
            double fuelAmount   = double.Parse(commandArgs[3]);
            string tyreType     = commandArgs[4];
            double tyreHardness = double.Parse(commandArgs[5]);
            double grip         = 0;

            if (commandArgs.Count > 6)
            {
                grip = double.Parse(commandArgs[6]);
            }

            Tyre   tyre   = tyreFactory.CreateTyre(tyreType, tyreHardness, grip);
            Car    car    = new Car(hp, fuelAmount, tyre);
            Driver driver = driverFactory.CreateDriver(type, name, car);

            racingDrivers.Add(driver);
        }
        catch { }
    }
Exemple #12
0
    public void RegisterDriver(List <string> commandArgs)
    {
        try
        {
            string typeOfDriver = commandArgs[0];
            string nameOfDriver = commandArgs[1];
            int    hp           = int.Parse(commandArgs[2]);
            double fuelAmount   = double.Parse(commandArgs[3]);
            var    tyreArgs     = commandArgs.Skip(4).ToList();

            Tyre   tyre   = tyreFactory.CreateTyre(tyreArgs);
            Car    car    = new Car(hp, fuelAmount, tyre);
            Driver driver = driverFactory.CreateDriver(typeOfDriver, nameOfDriver, car);
            allDrivers.Add(driver);
        }
        catch { }
    }
Exemple #13
0
    public void RegisterDriver(List <string> commandArgs)
    {
        try
        {
            string[] tyreArgs = commandArgs.Skip(4).ToArray();
            Tyre     tyre     = tyreFactory.CreateTyre(tyreArgs);

            int    carHp         = int.Parse(commandArgs[2]);
            double carFuelAmount = double.Parse(commandArgs[3]);
            Car    car           = new Car(carHp, carFuelAmount, tyre);

            string driverType = commandArgs[0];
            string driverName = commandArgs[1];
            Driver driver     = driverFactory.CreateDriver(driverType, driverName, car);

            this.competingDrivers.Add(driver);
        }
        catch { }
    }
Exemple #14
0
    public Car CreateCar(List <string> arguments)
    {
        TyreFactory   tyreFactory = new TyreFactory();
        int           hp          = int.Parse(arguments[0]);
        double        fuelAmount  = double.Parse(arguments[1]);
        List <string> tyreArgs    = arguments.Skip(2).ToList();
        Tyre          tyre        = tyreFactory.CreateTyre(tyreArgs);
        Car           car         = new Car(hp, fuelAmount, tyre);

        return(car);
    }
    public void ChangeTyre(List <string> arguments)
    {
        TyreFactory factory = new TyreFactory();

        try
        {
            this.Tyre = factory.CreateTyre(arguments);
        }
        catch (Exception)
        {
        }
    }
Exemple #16
0
        public void RegisterDriver(List <string> commandArgs)
        {
            try
            {
                string driverType = commandArgs[0];
                string driverName = commandArgs[1];

                int    horsePower  = int.Parse(commandArgs[2]);
                double fuelAmoount = double.Parse(commandArgs[3]);

                string[] tyreArgs = commandArgs.Skip(4).ToArray();

                Tyre tyre = _tyreFactory.CreateTyre(tyreArgs);

                Car car = new Car(horsePower, fuelAmoount, tyre);

                Driver driver = _driverFactory.CreateDriver(driverType, driverName, car);

                _racingDrivers.Add(driver);
            }
            catch { }
        }
Exemple #17
0
    public void DriverBoxes(List <string> commandArgs)
    {
        var reasonToBox = commandArgs[0];
        var driversName = commandArgs[1];

        Drivers currentDriver = drivers.First(n => n.Name == driversName);

        currentDriver.SetTime(20);

        switch (reasonToBox)
        {
        case "ChangeTyres":
            var tyreType     = commandArgs[2];
            var tyreHardness = commandArgs[3];

            var currentDriverTyre = currentDriver.Car.Tyre.Name;

            if (currentDriverTyre == "Ultrasoft")
            {
                var grip = commandArgs[4];
                currentDriver.Car.Tyre = tyreFactory.CreateTyre(new List <string> {
                    tyreType, tyreHardness, grip
                });
            }
            else
            {
                currentDriver.Car.Tyre = tyreFactory.CreateTyre(new List <string> {
                    tyreType, tyreHardness
                });
            }
            break;

        case "Refuel":
            var fuelAmount = double.Parse(commandArgs[2]);
            currentDriver.Car.Refuel(fuelAmount);
            break;
        }
    }
Exemple #18
0
    public static Driver CreateDriver(List <string> args)
    {
        var type          = Type.GetType(args[0] + "Driver");
        var name          = args[1];
        var carHp         = int.Parse(args[2]);
        var carFuelAmount = double.Parse(args[3]);

        var tyre = TyreFactory.CreateTyre(args.Skip(4).ToList());
        var car  = new Car(carHp, carFuelAmount, tyre);

        var driver = Activator.CreateInstance(type, name, car) as Driver;

        return(driver);
    }
Exemple #19
0
 public void Box(List <string> boxData)
 {
     this.TotalTime += 20;
     if (boxData.Count == 1)
     {
         this.Car.Refuel(double.Parse(boxData[0]));
     }
     else
     {
         var tyreFactory = new TyreFactory();
         var newTyre     = tyreFactory.CreateTyre(boxData);
         this.Car.ChangeTyre(newTyre);
     }
 }
    public void RegisterDriver(List <string> commandArgs)
    {
        try
        {
            var tyre   = TyreFactory.CreateTyre(commandArgs.Skip(4).ToArray());
            var car    = CarFactory.CreateCar(commandArgs.Skip(2).ToArray(), tyre);
            var driver = DriverFactory.CreateDriver(commandArgs.Take(2).ToArray(), car);
            this.activeDrivers.Add(driver);
        }

        catch (ArgumentException ae)
        {
        }
    }
Exemple #21
0
 public void RegisterDriver(List <string> commandArgs)
 {
     try
     {
         Tyre   tyre   = TyreFactory.CreateTyre(commandArgs.Skip(4).ToList());
         Car    car    = CarFactory.CreateCar(commandArgs.Skip(2).Take(2).ToList(), tyre);
         Driver driver = DriverFactory.CreateDriver(commandArgs.Take(2).ToList(), car);
         this.drivers.Add(commandArgs[1], driver);
     }
     catch (ArgumentException ae)
     {
         Console.WriteLine(ae.Message);
     }
 }
Exemple #22
0
    public void RegisterDriver(List <string> commandArgs)
    {
        try
        {
            Tyre tyre = TyreFactory.CreateTyre(commandArgs);

            int    hp         = int.Parse(commandArgs[2]);
            double fuelAmount = double.Parse(commandArgs[3]);
            Car    car        = new Car(hp, fuelAmount, tyre);

            Driver driver = DriverFactory.CreateDriver(commandArgs, car);
            drivers.Add(driver);
        }
        catch { }
    }
Exemple #23
0
    public void DriverBoxes(List <string> commandArgs)
    {
        string reason = commandArgs[0];
        Driver driver = this.drivers[commandArgs[1]];

        driver.TotalTime += PitStopTime;
        switch (reason)
        {
        case "ChangeTyres":
            Tyre newTyre = TyreFactory.CreateTyre(commandArgs.Skip(2).ToList());
            driver.Car.ChangeTyres(newTyre);
            break;

        case "Refuel":
            driver.Car.Refuel(double.Parse(commandArgs[2]));
            break;
        }
    }
Exemple #24
0
    public Driver CreateDriver(List <string> driverInfo)
    {
        var type = driverInfo[0];
        var tyre = tyreFactory.CreateTyre(driverInfo.Skip(4).ToList());
        var car  = new Car(int.Parse(driverInfo[2]), Double.Parse(driverInfo[3]), tyre);
        var name = driverInfo[1];

        switch (type)
        {
        case "Aggressive":
            return(new AggressiveDriver(name, car));

        case "Endurance":
            return(new EnduranceDriver(name, car));
        }

        throw new ArgumentException("");
    }
Exemple #25
0
    public void DriverBoxes(List <string> commandArgs)
    {
        string driversName = commandArgs[1];
        Driver driver      = drivers.FirstOrDefault(d => d.Name == driversName);

        if (driver != null)
        {
            if (commandArgs[0] == "Refuel")
            {
                driver.Car.Refull(double.Parse(commandArgs[2]));
            }
            else if (commandArgs[0] == "ChangeTyres")
            {
                Tyre tyre = TyreFactory.CreateTyre(commandArgs.Skip(2).ToList());
                driver.Car.SetNewTyre(tyre);
            }
            driver.AddTime(20);
        }
    }
Exemple #26
0
    public Driver CreateDriver(List <string> args)
    {
        string type       = args[0];
        string name       = args[1];
        int    hp         = int.Parse(args[2]);
        double fuelAmount = double.Parse(args[3]);
        string tyreType   = args[4];
        var    tyreInfo   = args.Skip(5).ToArray();

        Tyre tyre;

        try
        {
            tyre = tyreFactory.CreateTyre(tyreType, tyreInfo);
        }
        catch (NoNullAllowedException)
        {
            return(null);
        }

        Car car;

        try
        {
            car = new Car(hp, fuelAmount, tyre);
        }
        catch (NoNullAllowedException)
        {
            return(null);
        }

        switch (type)
        {
        case "Aggressive":
            return(new AggressiveDriver(name, car));

        case "Endurance":
            return(new EnduranceDriver(name, car));

        default:
            return(null);
        }
    }
Exemple #27
0
    public void DriverBoxes(List <string> commandArgs)
    {
        var reason = commandArgs[0];
        var driver = this.registeredDrivers[commandArgs[1]];

        var arguments = commandArgs.Skip(2).ToList();

        if (reason == "ChangeTyres")
        {
            driver.Car.ChangeTyre(TyreFactory.CreateTyre(arguments));
        }

        else if (reason == "Refuel")
        {
            driver.Car.Refuel(double.Parse(arguments[0]));
        }

        driver.TotalTime += 20;
    }
Exemple #28
0
    public void DriverBoxes(List <string> commandArgs)
    {
        var reasonToBox = commandArgs[0];

        var driver = RegisteredDrivers.FirstOrDefault(d => d.Name == commandArgs[1]);

        driver.Box();


        if (reasonToBox == "Refuel")
        {
            var amount = double.Parse(commandArgs[2]);
            driver.Car.Refuel(amount);
        }
        else
        {
            driver.Car.ChangeTyre(TyreFactory.CreateTyre(commandArgs.Skip(2).ToArray()));
        }
    }
    public void DriverBoxes(List <string> commandArgs)
    {
        var reasonToBox   = commandArgs[0];
        var driverName    = commandArgs[1];
        var currentDriver = sesuccessDrivers.FirstOrDefault(a => a.Name == driverName);

        currentDriver.IncreaseTotalTime(20);
        if (reasonToBox == "Refuel")
        {
            var fuelAmount = double.Parse(commandArgs[2]);
            currentDriver.Car.IncreaseFuelAmount(fuelAmount);
        }
        else
        {
            commandArgs.Insert(0, string.Empty);
            commandArgs.Insert(0, string.Empty);
            currentDriver.Car.ChangeTyre(TyreFactory.CreateTyre(commandArgs));
        }
    }
    public void DriverBoxes(List <string> commandArgs)
    {
        string reasonToBox = commandArgs[0];
        string driverName  = commandArgs[1];
        var    driver      = this.activeDrivers.First(d => d.Name == driverName);

        driver.IncreaseTime(20);

        if (reasonToBox == "ChangeTyres")
        {
            var tyre = TyreFactory.CreateTyre(commandArgs.Skip(2).ToArray());
            driver.Car.ChangeTyres(tyre);
        }

        else if (reasonToBox == "Refuel")
        {
            double fuelAmount = double.Parse(commandArgs[2]);
            driver.Car.Refuel(fuelAmount);
        }
    }