public void DriverBoxes(List <string> commandArgs) { string action = commandArgs[0]; string name = commandArgs[1]; Driver driver = racingDrivers.FirstOrDefault(d => d.Name == name); driver.AddTime(BOX_TIME); if (action == "Refuel") { double fuel = double.Parse(commandArgs[2]); driver.Car.Refuel(fuel); } else if (action == "ChangeTyres") { double hardness = double.Parse(commandArgs[3]); switch (commandArgs[2]) { case "Hard": HardTyre hardTyre = new HardTyre(hardness); driver.Car.ChangeTyre(hardTyre); break; case "Ultrasoft": double grip = double.Parse(commandArgs[4]); UltrasoftTyre softTyre = new UltrasoftTyre(hardness, grip); driver.Car.ChangeTyre(softTyre); break; } } }
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); } }
public string CompleteLaps(List <string> commandArgs) { StringBuilder sb = new StringBuilder(); int numbersOfLap = int.Parse(commandArgs[0]); if (numbersOfLap - currentLap > track.LapsNumber) { throw new ArgumentException($"There is no time! On lap {currentLap}."); } for (int i = 0; i < numbersOfLap; i++) { foreach (var driver in drivers) { driver.CompleteLap(track.LapLenght); if (driver.IsRacing == false) { dnfDrivers.Add(driver); } } RemoveDnf(); currentLap++; drivers = drivers.OrderBy(t => t.TotalTime).ToList(); for (int j = 0; j < drivers.Count - 1; j++) { Driver frontDriver = drivers[j]; Driver behindDriver = drivers[j + 1]; var diffrence = Math.Abs(frontDriver.TotalTime - behindDriver.TotalTime); if (diffrence > 3 || !frontDriver.IsRacing || !behindDriver.IsRacing) { continue; } if (frontDriver.GetType().Name == "AgressiveDriver" && frontDriver.Car.Tyre.GetType().Name == "UltrasoftTyre" && currentWeather == "Foggy" && diffrence <= 3) { frontDriver.Crash(); dnfDrivers.Add(frontDriver); continue; } if (frontDriver.GetType().Name == "EnduranceDriver" && frontDriver.Car.Tyre.GetType().Name == "HardTyre" && currentWeather == "Rainy" && diffrence <= 3) { frontDriver.Crash(); dnfDrivers.Add(frontDriver); continue; } if (diffrence < 2) { sb.AppendLine($"{behindDriver.Name} has overtaken {frontDriver.Name} on lap {currentLap}."); frontDriver.AddTime(2); behindDriver.AddTime(-2); } } RemoveDnf(); if (currentLap == track.LapsNumber) { HasEnd = true; } } return(sb.ToString().TrimEnd()); }