コード例 #1
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);
    }
コード例 #2
0
ファイル: CarFactory.cs プロジェクト: AlShandor/SoftUni
    public Car GetCar(List<string> carArgs)
    {
        int hp = int.Parse(carArgs[0]);
        double fuelAmount = double.Parse(carArgs[1]);
        Tyre tyre = tyreFactory.GetTyre(carArgs.Skip(2).ToList());

        return new Car(hp, fuelAmount, tyre);
    }
コード例 #3
0
    public Car GetCar(List <string> inputLine)
    {
        int         hp;
        double      fuelAmount;
        Tyre        tyre;
        TyreFactory tyreFactory;

        tyreFactory = new TyreFactory();
        hp          = int.Parse(inputLine[0]);
        fuelAmount  = double.Parse(inputLine[1]);
        tyre        = tyreFactory.GetTyre(inputLine.Skip(4).ToList());

        return(new Car(hp, fuelAmount, tyre));
    }
コード例 #4
0
    public void DriverBoxes(List <string> commandArgs)
    {
        string driverName = commandArgs[1];
        Driver driver     = activeDrivers.FirstOrDefault(d => d.Name == driverName);

        driver.TotalTime += 20;

        if (commandArgs[0] == "Refuel")
        {
            driver.Car.FuelAmount += double.Parse(commandArgs[2]);
        }

        if (commandArgs[0] == "ChangeTyres")
        {
            driver.Car.Tyre = tyreFactory.GetTyre(commandArgs.Skip(2).ToList());
        }
    }
コード例 #5
0
    public void DriverBoxes(List <string> commandArgs)
    {
        string boxReason  = commandArgs[0];
        string driverName = commandArgs[1];

        Driver driver = this.racingDrivers
                        .FirstOrDefault(d => d.Name == driverName);

        string[] methodArgs = commandArgs.Skip(2).ToArray();

        if (boxReason == "Refuel")
        {
            driver.Refuel(methodArgs);
        }
        else if (boxReason == "ChangeTyres")
        {
            Tyre tyre = TyreFactory.GetTyre(methodArgs);
            driver.ChangeTyres(tyre);
        }
    }
コード例 #6
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.GetTyre(tyreArgs);

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

            Driver driver = DriverFactory.GetDriver(driverType, driverName, car);

            this.racingDrivers.Add(driver);
        }
        catch { }
    }