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 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 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()); }