示例#1
0
    public void RegisterDriver(List <string> commandArgs)
    {
        try
        {
            var hp         = int.Parse(commandArgs[2]);
            var fuelAmount = double.Parse(commandArgs[3]);

            Tyre tyre = TyreFactory.Get(commandArgs.Skip(4).Take(3).ToList());

            if (tyre == null)
            {
                throw new ArgumentException();
            }

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

            if (car == null)
            {
                throw new ArgumentException();
            }

            Driver driver = DriverFactory.Get(commandArgs.Take(2).ToList(), car);

            if (driver == null)
            {
                throw new ArgumentException();
            }

            this.drivers.Add(driver);
        }
        catch
        {
        }
    }
示例#2
0
    public void DriverBoxes(List <string> commandArgs)
    {
        var reason     = commandArgs[0];
        var driverName = commandArgs[1];

        var driver = this.drivers.SingleOrDefault(x => x.Name == driverName);

        driver.ChangeTotalTime(20);

        if (reason == "ChangeTyres")
        {
            var tyreType     = commandArgs[2];
            var tyreHardness = double.Parse(commandArgs[3]);

            var tyre = TyreFactory.Get(commandArgs.Skip(2).Take(3).ToList());

            if (tyre != null)
            {
                driver.Car.ChangeTyre(tyre);
            }
        }

        if (reason == "Refuel")
        {
            var amount = double.Parse(commandArgs[2]);
            driver.Car.Refuel(amount);
        }
    }
    public void ChangeTyres(List <string> args)
    {
        this.Box();
        Tyre tyre = TyreFactory.CreateTyre(args);

        this.Car.ChangeTyres(tyre);
    }
示例#4
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);
        }
    }
示例#5
0
 public RaceTower()
 {
     this.driverFactory = new DriverFactory();
     this.drivers       = new List <Driver>();
     this.falledDrivers = new Stack <Driver>();
     this.tyreFactory   = new TyreFactory();
 }
示例#6
0
 public RaceTower()
 {
     _tyreFactory   = new TyreFactory();
     _driverFactory = new DriveFactory();
     _racingDrivers = new List <Driver>();
     _failedDrivers = new Stack <Driver>();
 }
示例#7
0
 public RaceTower()
 {
     this.racingDrivers = new Dictionary <string, Driver>();
     this.dnfDrivers    = new List <Driver>();
     this.tyreFactory   = new TyreFactory();
     this.driverFactory = new DriverFactory();
 }
    public Driver CreateDriver(List <string> args)
    {
        var    driverType = args[0];
        var    driverName = args[1];
        int    carHP      = int.Parse(args[2]);
        double fuelAmount = double.Parse(args[3]);
        Tyre   tyre       = new TyreFactory().CreateTyre(args.Skip(4).ToList());
        Car    car        = new Car(carHP, fuelAmount, tyre);

        switch (args[0])
        {
        case "Aggressive":
        {
            return(new AggressiveDriver(driverName, car));
        }

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

        default:
            return(null);
        }
    }
    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();
        }
    }
示例#10
0
    public void RegisterDriver(List <string> commandArgs)
    {
        try
        {
            var    driverType   = commandArgs[0];
            var    driverName   = commandArgs[1];
            var    hp           = int.Parse(commandArgs[2]);
            var    fuelAmount   = double.Parse(commandArgs[3]);
            var    tyreType     = commandArgs[4];
            var    tyreHardness = double.Parse(commandArgs[5]);
            var    grip         = 0.0;
            Driver driver       = null;
            Car    car          = null;
            Tyre   tyre         = null;
            if (tyreType == "Ultrasoft")
            {
                grip = double.Parse(commandArgs[6]);
                tyre = TyreFactory.CreateUltraSoft(tyreHardness, grip);
            }
            else if (tyreType == "Hard")
            {
                tyre = TyreFactory.CreateHard(tyreHardness);
            }

            car    = CarFactory.CreateCar(hp, fuelAmount, tyre);
            driver = DriverFactory.CreateDriver(driverType, driverName, car);

            this.drivers.Add(driver);
        }
        catch
        {
        }
    }
示例#11
0
 public RaceTower()
 {
     drivers       = new List <Driver>();
     driverFactory = new DriverFactory();
     tyreFactory   = new TyreFactory();
     dnfDrivers    = new List <Driver>();
 }
示例#12
0
 public Car(int hp, double fuelAmount, string tyreType, double tyreHardness)
 {
     this.tyreFactory = new TyreFactory();
     this.HP          = hp;
     this.FuelAmount  = fuelAmount;
     this.Tyre        = tyreFactory.Create(tyreType, tyreHardness);
 }
示例#13
0
    public Driver GetDriver(string[] arr)
    {
        string type       = arr[0];
        string name       = arr[1];
        int    hp         = int.Parse(arr[2]);
        double fuelAmount = double.Parse(arr[3]);

        string[] tyreArr = arr.Skip(4).ToArray();

        TyreFactory tyre = new TyreFactory();
        Driver      driver;

        switch (type)
        {
        case "Aggressive":
            driver = new AggressiveDriver(name, new Car(hp, fuelAmount, tyre.GetTyre(tyreArr)));
            break;

        case "Endurance":
            driver = new EnduranceDriver(name, new Car(hp, fuelAmount, tyre.GetTyre(tyreArr)));
            break;

        default:
            return(null);
        }

        return(driver);
    }
示例#14
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);
    }
示例#15
0
 public Car(int hp, double fuelAmount, Tyre tyre)
 {
     Hp               = hp;
     FuelAmount       = fuelAmount;
     Tyre             = tyre;
     this.tyreFactory = new TyreFactory();
 }
示例#16
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();
        }
    }
示例#17
0
    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");
    }
示例#18
0
    public void DriverBoxes(List <string> commandArgs)
    {
        string reason = commandArgs[0];
        string name   = commandArgs[1];

        if (activeDrivers.ContainsKey(name))
        {
            var driver = activeDrivers[name];

            driver.IncreaseTime(20);

            if (reason == "ChangeTyres")
            {
                Tyre tyre = TyreFactory.Create(commandArgs.Skip(2).ToList());

                driver.Car.ChangeTyres(tyre);
            }
            else if (reason == "Refuel")
            {
                double fuel = double.Parse(commandArgs[2]);

                driver.Car.Refuel(fuel);
            }
        }
    }
    public void DriverBoxes(List <string> commandArgs)
    {
        string reasonToBox = commandArgs[0];
        string driversName = commandArgs[1];

        Driver boxingDriver = Drivers.Find(d => d.Name == driversName);

        string tyreTypeOrFuelAmount = commandArgs[2];

        if (reasonToBox == "ChangeTyres")
        {
            List <string> tyreFactoryArgs = new List <string>
            {
                tyreTypeOrFuelAmount
            };

            string tyreHardness = commandArgs[3];
            tyreFactoryArgs.Add(tyreHardness);

            if (tyreTypeOrFuelAmount == "Ultrasoft")
            {
                string grip = commandArgs[4];
                tyreFactoryArgs.Add(grip);
            }

            boxingDriver.Car.ReplaceTyre(TyreFactory.CreateInstance(tyreFactoryArgs));
        }
        else
        {
            boxingDriver.Car.Refuel(double.Parse(tyreTypeOrFuelAmount));
        }
    }
示例#20
0
 public RaceTower()
 {
     this.racingDrivers  = new List <Driver>();
     this.tyreFactory    = new TyreFactory();
     this.driverFactory  = new DriverFactory();
     this.currentWeather = Weather.Sunny;
     this.crashedDrivers = new Stack <Driver>();
 }
示例#21
0
 public RaceTower()
 {
     this.drivers       = new List <Driver>();
     this.dnfDrivers    = new Stack <Driver>();
     this.weather       = "Sunny";
     this.tyreFactory   = new TyreFactory();
     this.driverFactory = new DriverFactory();
 }
示例#22
0
 public RaceTower()
 {
     this.currentWeather    = "Sunny";
     this.activeDrivers     = new List <Driver>();
     this.eliminatedDrivers = new List <string>();
     this.driverFactory     = new DriverFactory();
     this.tyreFactory       = new TyreFactory();
 }
示例#23
0
 public RaceTower()
 {
     this.driverFactory = new DriverFactory();
     this.tyreFactory   = new TyreFactory();
     this.drivers       = new List <Driver>();
     this.stringBuilder = new StringBuilder();
     totalLaps          = 0;
 }
示例#24
0
 public RaceTower()
 {
     this.tyreFactory      = new TyreFactory();
     this.driverFactory    = new DriverFactory();
     this.competingDrivers = new List <Driver>();
     this.failedDrivers    = new List <Driver>();
     this.weather          = Weather.Sunny;
 }
示例#25
0
 public RaceTower()
 {
     this.HasWinner         = false;
     this.track             = new Track();
     this.driverFactory     = new DriverFactory();
     this.tyreFactory       = new TyreFactory();
     this.registeredDrivers = new Dictionary <string, Driver>();
     this.unfinishedDrivers = new Dictionary <Driver, string>();
 }
示例#26
0
 public RaceTower()
 {
     this.driverFactory = new DriverFactory();
     this.tyreFactory   = new TyreFactory();
     this.drivers       = new List <Drivers>();
     this.trackInfo     = new double[2];
     this.whetherMode   = "Sunny";
     currentLab         = 0;
 }
示例#27
0
 public RaceTower()
 {
     this.driverFactory = new DriverFactory();
     this.tyreFactory   = new TyreFactory();
     this.drivers       = new Dictionary <string, Driver>();
     this.dnf           = new Dictionary <string, string>();
     this.CurrentLap    = 0;
     this.weather       = "Sunny";
 }
 public RaceTower()
 {
     this.currentLapNumber      = 0;
     this.weather               = Weather.Sunny;
     this.racingDriverByName    = new Dictionary <string, IDriver>();
     this.failureReasonByDriver = new Dictionary <IDriver, string>();
     this.tyreFactory           = new TyreFactory();
     this.driverFactory         = new DriverFactory();
 }
示例#29
0
 public RaceTower()
 {
     this.Drivers        = new Dictionary <string, Driver>();
     this.CrashedDrivers = new List <Driver>();
     this.Weather        = "Sunny";
     this.DriverFactory  = new DriverFactory();
     this.TyreFactory    = new TyreFactory();
     this.SortedDrivers  = new List <Driver>();
 }
示例#30
0
 public RaceTower()
 {
     this.tyreFactory   = new TyreFactory();
     this.driverFactory = new DriverFactory();
     this.allDrivers    = new List <Driver>();
     this.failedDrivers = new List <Driver>();
     this.weather       = "Sunny";
     this.raceIsOver    = false;
 }