private void CommandParser(string input) { string[] inputArgs = input.Split(); string command = inputArgs[0]; List <string> commandArgs = inputArgs.Skip(1).ToList(); switch (command) { case "RegisterDriver": raceTower.RegisterDriver(commandArgs); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": Console.WriteLine(raceTower.CompleteLaps(commandArgs)); break; case "ChangeWeather": raceTower.ChangeWeather(commandArgs); break; } }
public static void Main() { RaceTower raceTower = new RaceTower(); int numberOfLaps = int.Parse(Console.ReadLine()); int trackLength = int.Parse(Console.ReadLine()); raceTower.SetTrackInfo(numberOfLaps, trackLength); while (raceTower.LapsNumber > raceTower.CurrentLap) { List <string> commandArgs = Console.ReadLine().Split().ToList(); string command = commandArgs[0]; commandArgs.RemoveAt(0); switch (command) { case "CompleteLaps": Console.ForegroundColor = ConsoleColor.Red; string result = raceTower.CompleteLaps(commandArgs); if (!string.IsNullOrWhiteSpace(result)) { Console.WriteLine(result); } Console.ForegroundColor = ConsoleColor.White; break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "RegisterDriver": raceTower.RegisterDriver(commandArgs); break; case "DriverBoxes": raceTower.DriverBoxes(commandArgs); break; case "ChangeWeather": raceTower.ChangeWeather(commandArgs); break; case "Box": raceTower.DriverBoxes(commandArgs); break; } } Driver winner = raceTower.Drivers.OrderBy(d => d.TotalTime).FirstOrDefault(); if (winner == null) { winner = raceTower.FailedDrivers.OrderBy(d => d.TotalTime).First(); } Console.WriteLine($"{winner.Name} wins the race for {winner.TotalTime:f3} seconds."); }
public void Run() { while (this.raceTower.Track.CurrentLap < this.raceTower.Track.CountOfLaps) { var commands = Console.ReadLine().Split(); var tokens = commands.Skip(1).ToList(); var command = commands[0]; try { switch (command) { case "RegisterDriver": { raceTower.RegisterDriver(tokens); } break; case "Leaderboard": { var result = raceTower.GetLeaderboard(); this.Print(result); } break; case "CompleteLaps": { var result = raceTower.CompleteLaps(tokens); if (!string.IsNullOrEmpty(result)) { Print(result); } } break; case "Box": { raceTower.DriverBoxes(tokens); } break; case "ChangeWeather": { raceTower.ChangeWeather(tokens); } break; } } catch (Exception e) { Console.WriteLine(e.Message); } } var winner = this.raceTower.GetWinner(); this.Print(winner); }
public void Run() { var lapsNumber = int.Parse(Console.ReadLine()); var trackLenght = int.Parse(Console.ReadLine()); raceTower.SetTrackInfo(lapsNumber, trackLenght); while (raceTower.IsInProgress) { var input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); var command = input[0]; input = input.Skip(1).ToList(); try { switch (command) { case "RegisterDriver": { raceTower.RegisterDriver(input); break; } case "Leaderboard": { Console.Write(raceTower.GetLeaderboard()); break; } case "CompleteLaps": { Console.Write(raceTower.CompleteLaps(input)); break; } case "Box": { raceTower.DriverBoxes(input); break; } case "ChangeWeather": { raceTower.ChangeWeather(input); break; } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } Console.WriteLine($"{raceTower.Winner.Name} wins the race for {raceTower.Winner.TotalTime:f3} seconds."); }
public void Run() { int lapsNumber = int.Parse(Console.ReadLine()); int trackLength = int.Parse(Console.ReadLine()); RaceTower raceTower = new RaceTower(); raceTower.SetTrackInfo(lapsNumber, trackLength); while (!raceTower.IsRaceOver) { string[] commandArgs = Console.ReadLine().Split(); Command commandType = Enum.Parse <Command>(commandArgs[0]); string result = string.Empty; switch (commandType) { case Command.RegisterDriver: raceTower.RegisterDriver(commandArgs.Skip(1).ToList()); break; case Command.Leaderboard: Console.WriteLine(raceTower.GetLeaderboard()); break; case Command.CompleteLaps: try { result = raceTower.CompleteLaps(commandArgs.Skip(1).ToList()); } catch (RaceException rex) { result = rex.Message; } break; case Command.Box: raceTower.DriverBoxes(commandArgs.Skip(1).ToList()); break; case Command.ChangeWeather: raceTower.ChangeWeather(commandArgs.Skip(1).ToList()); break; } if (result != string.Empty) { Console.WriteLine(result); } } }
static void Main() { var race = new RaceTower(); int count = int.Parse(Console.ReadLine()); int length = int.Parse(Console.ReadLine()); race.SetTrackInfo(count, length); while (true) { var args = Console.ReadLine().Split(); var commandArgs = args.Skip(1).ToList(); switch (args[0]) { case "RegisterDriver": race.RegisterDriver(commandArgs); break; case "Leaderboard": Console.WriteLine(race.GetLeaderboard()); break; case "CompleteLaps": string output = race.CompleteLaps(commandArgs); if (output != String.Empty) { Console.WriteLine(output); } if (race.IsFinished) { Console.WriteLine($"{race.Winner.Name} wins the race for {race.Winner.TotalTime:f3} seconds."); return; } break; case "Box": race.DriverBoxes(commandArgs); break; case "ChangeWeather": race.ChangeWeather(commandArgs); break; default: throw new ArgumentException(); } } }
static void Main() { RaceTower raceTower = new RaceTower(); var numberOfLaps = int.Parse(Console.ReadLine()); var lengthOfTrack = int.Parse(Console.ReadLine()); raceTower.SetTrackInfo(numberOfLaps, lengthOfTrack); string input = Console.ReadLine(); while (true) { var commandArgs = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); var command = commandArgs.First(); commandArgs.RemoveAt(0); switch (command) { case "RegisterDriver": raceTower.RegisterDriver(commandArgs); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": var result = raceTower.CompleteLaps(commandArgs); if (result != string.Empty) { Console.WriteLine(result); } break; case "Box": raceTower.DriverBoxes(commandArgs); break; case "ChangeWeather": raceTower.ChangeWeather(commandArgs); break; } if (raceTower.IsEndOfRace) { Console.WriteLine( $"{raceTower.Winner.Name} wins the race for {raceTower.Winner.TotalTime:F3} seconds."); return; } input = Console.ReadLine(); } }
static void Main(string[] args) { int lapsNumber = int.Parse(Console.ReadLine()); int trackLength = int.Parse(Console.ReadLine()); RaceTower raceTower = new RaceTower(); raceTower.SetTrackInfo(lapsNumber, trackLength); while (true) { string[] tokens = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); switch (tokens[0]) { case "RegisterDriver": raceTower.RegisterDriver(tokens.Skip(1).ToList()); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": try { string text = raceTower.CompleteLaps(tokens.Skip(1).ToList()); if (text != string.Empty) { Console.WriteLine(text); } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } break; case "Box": raceTower.DriverBoxes(tokens.Skip(1).ToList()); break; case "ChangeWeather": raceTower.ChangeWeather(tokens.Skip(1).ToList()); break; } if (raceTower.IsFinishedRace()) { raceTower.Finish(); break; } } }
public void Run() { int numberOfLaps = int.Parse(Console.ReadLine()); int trackLength = int.Parse(Console.ReadLine()); RaceTower raceTower = new RaceTower(); raceTower.SetTrackInfo(numberOfLaps, trackLength); for (int i = 0; i < numberOfLaps; i++) { if (raceTower.LapsLeft == 0) { break; } string[] tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); string command = tokens[0]; if (command == "RegisterDriver") { raceTower.RegisterDriver(tokens.Skip(1).ToList()); } else if (command == "CompleteLaps") { string result = raceTower.CompleteLaps(tokens.Skip(1).ToList()); writer.WriteLine(result); } else if (command == "Leaderboard") { string result = raceTower.GetLeaderboard(); writer.WriteLine(result); } else if (command == "Box") { raceTower.DriverBoxes(tokens.Skip(1).ToList()); } else if (command == "ChangeWeather") { raceTower.ChangeWeather(tokens.Skip(1).ToList()); } } Driver winner = raceTower.GetAllDrivers.OrderByDescending(x => x.TotalTime).FirstOrDefault(); if (winner == null) { winner = raceTower.GetOutOfRaceDrivers.Last(); } writer.WriteLine(string.Format(ConstantMessages.WinnerMessage, winner.Name, winner.TotalTime)); }
public void Run() { StringBuilder sb = new StringBuilder(); string output = ""; while (!raceTower.RaceOver()) { output = ""; string[] command = Console.ReadLine().Split(); string type = command[0]; List <string> commandArgs = command.Skip(1).ToList(); switch (type) { case "RegisterDriver": raceTower.RegisterDriver(commandArgs); break; case "Leaderboard": output = raceTower.GetLeaderboard(); break; case "CompleteLaps": output = raceTower.CompleteLaps(commandArgs); break; case "Box": raceTower.DriverBoxes(commandArgs); break; case "ChangeWeather": raceTower.ChangeWeather(commandArgs); break; default: Console.WriteLine("Invalid command"); break; } if (!string.IsNullOrEmpty(output)) { sb.AppendLine(output); } } sb.AppendLine(raceTower.GetWinner()); Console.WriteLine(sb.ToString().TrimEnd()); }
public void Run() { var numberOfLaps = int.Parse(Console.ReadLine()); var trackLength = int.Parse(Console.ReadLine()); raceTower.SetTrackInfo(numberOfLaps, trackLength); for (int i = 0; i < numberOfLaps; i++) { var input = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray(); var command = input[0]; var args = input.Skip(1).ToList(); switch (command) { case "RegisterDriver": raceTower.RegisterDriver(args); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": string result = raceTower.CompleteLaps(args); if (!string.IsNullOrWhiteSpace(result)) { Console.WriteLine(result); } if (raceTower.IsRaceOver) { Environment.Exit(0); } break; case "Box": raceTower.DriverBoxes(args); break; case "ChangeWeather": raceTower.ChangeWeather(args); break; default: throw new InvalidOperationException(); } } }
public static void StartRace(RaceTower raceTower) { int numberOfLaps = int.Parse(Console.ReadLine()); int lengthOfTrack = int.Parse(Console.ReadLine()); raceTower.SetTrackInfo(numberOfLaps, lengthOfTrack); while (!raceTower.endOfRace) { List <string> args = Console.ReadLine().Split().ToList(); try { string command = args[0]; List <string> arguments = args.Skip(1).ToList(); switch (command) { case "RegisterDriver": raceTower.RegisterDriver(arguments); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": string result = raceTower.CompleteLaps(arguments); if (result.Length != 0) { Console.WriteLine(result); } break; case "Box": raceTower.DriverBoxes(arguments); break; case "ChangeWeather": raceTower.ChangeWeather(arguments); break; } } catch (ArgumentException e) { Console.WriteLine(e.Message); } } }
public static void Main() { int num = int.Parse(Console.ReadLine()); int length = int.Parse(Console.ReadLine()); raceTower.SetTrackInfo(num, length); while (!raceTower.IsThisTheEnd) { var command = Console.ReadLine().Split(' '); var line = command.Skip(1).ToList(); switch (command[0]) { case "RegisterDriver": raceTower.RegisterDriver(line); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": var result = raceTower.CompleteLaps(line); if (result != String.Empty) { Console.WriteLine(result); } if (raceTower.IsThisTheEnd) { Console.WriteLine(raceTower.DisplayWinner()); break; } break; case "Box": raceTower.DriverBoxes(line); break; case "ChangeWeather": raceTower.ChangeWeather(line); break; } } }
public static void Main() { int lapsInRace = int.Parse(Console.ReadLine()); int trackLength = int.Parse(Console.ReadLine()); var raceTower = new RaceTower(); raceTower.SetTrackInfo(lapsInRace, trackLength); while (raceTower.CompletedLaps != lapsInRace) { var input = Console.ReadLine().Split().ToList(); var command = input[0]; var args = input.Skip(1).ToList(); switch (command) { case "RegisterDriver": raceTower.RegisterDriver(args); break; case "CompleteLaps": var output = raceTower.CompleteLaps(args); if (output != "") { Console.WriteLine(output); } break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "Box": raceTower.DriverBoxes(args); break; case "ChangeWeather": raceTower.ChangeWeather(args); break; default: break; } } var winner = raceTower.GetWinner(); Console.WriteLine(winner); }
public static void Main(string[] args) { var rt = new RaceTower(); var numberOfLaps = int.Parse(Console.ReadLine()); var trackLength = int.Parse(Console.ReadLine()); rt.SetTrackInfo(numberOfLaps, trackLength); while (rt.CurrentLap < numberOfLaps) { var input = Console.ReadLine().Split(); var command = input[0]; var arguments = input.Skip(1).ToList(); switch (command) { case "RegisterDriver": rt.RegisterDriver(arguments); break; case "Leaderboard": Console.WriteLine(rt.GetLeaderboard()); break; case "CompleteLaps": var result = rt.CompleteLaps(arguments); if (result.Length > 0) { Console.WriteLine(result); } break; case "Box": rt.DriverBoxes(arguments); break; case "ChangeWeather": rt.ChangeWeather(arguments); break; } } var winner = rt.Winner; Console.WriteLine($"{winner.Name} wins the race for {winner.TotalTime:F3} seconds."); }
public void Run() { var raceTower = new RaceTower(); var laps = int.Parse(Console.ReadLine()); var length = int.Parse(Console.ReadLine()); raceTower.SetTrackInfo(laps, length); while (raceTower.GetCurrentLap != laps) { var tokens = Console.ReadLine().Split().ToList(); var command = tokens[0]; tokens.RemoveAt(0); switch (command) { case "RegisterDriver": raceTower.RegisterDriver(tokens); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": var result = raceTower.CompleteLaps(tokens); if (!string.IsNullOrWhiteSpace(result)) { Console.WriteLine(result); } break; case "Box": raceTower.DriverBoxes(tokens); break; case "ChangeWeather": raceTower.ChangeWeather(tokens); break; } } Console.WriteLine(raceTower.GetWinner()); }
public void Run() { RaceTower rt = new RaceTower(); int numberOfLapsInRace = int.Parse(Console.ReadLine()); int lengthOfTrack = int.Parse(Console.ReadLine()); rt.SetTrackInfo(numberOfLapsInRace, lengthOfTrack); bool raceOver = false; while (true) { string[] input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); switch (input[0]) { case "RegisterDriver": rt.RegisterDriver(input.Skip(1).ToList()); break; case "Leaderboard": Console.WriteLine(rt.GetLeaderboard()); break; case "CompleteLaps": try { Console.WriteLine(rt.CompleteLaps(input.Skip(1).ToList())); } catch (ArgumentException e) { Console.WriteLine(e.Message); } break; case "Box": rt.DriverBoxes(input.Skip(1).ToList()); break; case "ChangeWeather": rt.ChangeWeather(input.Skip(1).ToList()); break; } } }
static void Main(string[] args) { var laps = int.Parse(Console.ReadLine()); var trackLength = int.Parse(Console.ReadLine()); var race = new RaceTower(); race.SetTrackInfo(laps, trackLength); while (!race.IsOver) { var input = Console.ReadLine().Split(); var command = input[0]; var details = input.Skip(1).ToList(); if (command == "RegisterDriver") { race.RegisterDriver(details); } else if (command == "Leaderboard") { Console.WriteLine(race.GetLeaderboard()); } else if (command == "CompleteLaps") { var output = race.CompleteLaps(details); if (output != "") { Console.WriteLine(output); } } else if (command == "Box") { race.DriverBoxes(details); } else if (command == "ChangeWeather") { race.ChangeWeather(details); } } }
static void Main(string[] args) { int numbersOfLaps = int.Parse(Console.ReadLine()); int lengthOfTrack = int.Parse(Console.ReadLine()); RaceTower raceTower = new RaceTower(); raceTower.SetTrackInfo(numbersOfLaps, lengthOfTrack); bool finishTheRace = true; while (finishTheRace) { string[] input = Console.ReadLine().Split(); List <string> commandArgs = input.Skip(1).ToList(); switch (input[0]) { case "RegisterDriver": raceTower.RegisterDriver(commandArgs); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": string result = raceTower.CompleteLaps(commandArgs); Console.WriteLine(result); if (result != null && result.Split().Length > 2 && result.Split()[1] == "wins") { finishTheRace = false; } break; case "Box": raceTower.DriverBoxes(commandArgs); break; case "ChangeWeather": raceTower.ChangeWeather(commandArgs); break; } } }
static void Main(string[] args) { int lapsNumber = int.Parse(Console.ReadLine()); int trackLength = int.Parse(Console.ReadLine()); RaceTower raceTower = new RaceTower(lapsNumber, trackLength); while (!raceTower.IsRaceFinished) { var input = Console.ReadLine().Split(' ').ToList(); switch (input[0]) { case "RegisterDriver": input.RemoveAt(0); raceTower.RegisterDriver(input); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": input.RemoveAt(0); var result = raceTower.CompleteLaps(input); if (!string.IsNullOrWhiteSpace(result)) { Console.WriteLine(result); } break; case "Box": input.RemoveRange(0, 2); raceTower.DriverBoxes(input); break; case "ChangeWeather": input.RemoveAt(0); raceTower.ChangeWeather(input); break; } } Console.WriteLine(raceTower.ResultString); }
public void CommandDistributor(string inputData) { List <string> data = inputData.Split().ToList(); string result = ""; switch (data[0]) { case "RegisterDriver": tower.RegisterDriver(data.Skip(1).ToList()); break; case "Leaderboard": result = tower.GetLeaderboard(); break; case "CompleteLaps": result = tower.CompleteLaps(data.Skip(1).ToList()); break; case "Box": tower.DriverBoxes(data.Skip(1).ToList()); break; case "ChangeWeather": tower.ChangeWeather(data.Skip(1).ToList()); break; default: result = "Invalid input!"; break; } if (!string.IsNullOrWhiteSpace(result)) { Console.WriteLine(result); } if (tower.track.CurrentLap == tower.track.RaceLaps) { Environment.Exit(0); } }
public void Run() { int lapsNumber = int.Parse(Console.ReadLine()); int trackLength = int.Parse(Console.ReadLine()); raceTower.SetTrackInfo(lapsNumber, trackLength); while (raceTower.IsRaceOver == false) { var commandLine = Console.ReadLine().Split(); var command = commandLine[0]; var commandArgs = commandLine.Skip(1).ToList(); switch (command) { case "RegisterDriver": raceTower.RegisterDriver(commandArgs); break; case "Box": raceTower.DriverBoxes(commandArgs); break; case "CompleteLaps": string result = this.raceTower.CompleteLaps(commandArgs); if (!string.IsNullOrWhiteSpace(result)) { Console.WriteLine(result); } break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "ChangeWeather": raceTower.ChangeWeather(commandArgs); break; } } }
internal void Run() { while (!raceTower.raceIsOver) { var commandArgs = Console.ReadLine().Split(); var command = commandArgs[0]; var methodArgs = commandArgs.Skip(1).ToList(); switch (command) { case "RegisterDriver": raceTower.RegisterDriver(methodArgs); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": var result = raceTower.CompleteLaps(methodArgs); if (!string.IsNullOrWhiteSpace(result)) { Console.WriteLine(result); } break; case "Box": raceTower.DriverBoxes(methodArgs); break; case "ChangeWeather": raceTower.ChangeWeather(methodArgs); break; default: Console.WriteLine("Invalid command"); break; } } }
public void Run() { int numberOfTheLaps = int.Parse(Console.ReadLine()); int lengthOfTheTrack = int.Parse(Console.ReadLine()); raceTower.SetTrackInfo(numberOfTheLaps, lengthOfTheTrack); while (numberOfTheLaps > raceTower.currentLaps) { List <string> command = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList(); List <string> commandArgs = command.Skip(1).ToList(); switch (command[0]) { case "RegisterDriver": raceTower.RegisterDriver(commandArgs); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": PrintOutput(raceTower.CompleteLaps(commandArgs)); break; case "Box": raceTower.DriverBoxes(commandArgs); break; case "ChangeWeather": raceTower.ChangeWeather(commandArgs); break; } } PrintOutput(raceTower.PrintWinner()); }
static void Main(string[] args) { RaceTower raceTower = new RaceTower(); int laps = int.Parse(Console.ReadLine()); int lengthTrack = int.Parse(Console.ReadLine()); raceTower.SetTrackInfo(laps, lengthTrack); List <string> input; while (true) { input = Console.ReadLine().Split().ToList(); if (input[0] == "RegisterDriver") { input = input.Skip(1).Take(10).ToList(); raceTower.RegisterDriver(input); } else { break; } } do { switch (input[0]) { case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "CompleteLaps": input = input.Skip(1).ToList(); string result = raceTower.CompleteLaps(input); if (!string.IsNullOrEmpty(result)) { Console.WriteLine(result.Trim()); } break; case "Box": input = input.Skip(1).ToList(); raceTower.DriverBoxes(input); break; case "ChangeWeather": input = input.Skip(1).ToList(); raceTower.ChangeWeather(input); break; default: break; } if (raceTower.CurrentLap < laps) { input = Console.ReadLine().Split().ToList(); } } while (raceTower.CurrentLap < laps); Driver driver = raceTower.Drivers.OrderBy(d => d.TotalTime).First(); Console.WriteLine($"{driver.Name} wins the race for {driver.TotalTime:f3} seconds."); }