private string ProcessCommand(string line) { string output = string.Empty; List <string> args = line.Split().ToList(); string command = args[0]; switch (command) { case "RegisterDriver": raceTower.RegisterDriver(args); break; case "CompleteLaps": output = raceTower.CompleteLaps(args); break; case "Box": raceTower.DriverBoxes(args); break; case "Leaderboard": output = raceTower.GetLeaderboard(); break; } currentLap = raceTower.CurrentLap; return(output); }
public void Run() { this.isRunning = true; int lapsNumber = int.Parse(Console.ReadLine()); int trackLength = int.Parse(Console.ReadLine()); raceTower.SetTrackInfo(lapsNumber, trackLength); while (this.isRunning) { if (raceTower.CurrentLap >= raceTower.LapsNumber) { this.isRunning = false; } try { string input = Console.ReadLine(); List <string> tokens = input.Split(" ").ToList(); string command = tokens[0]; List <string> commandArgs = tokens.Skip(1).ToList(); string output = ""; switch (command) { 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; } Console.WriteLine(output); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } } }
public void Run() { List <string> line = Console.ReadLine().Split().ToList(); while (true) { switch (line[0]) { case "RegisterDriver": cm.RegisterDriver(line.Skip(1).ToList()); break; case "Leaderboard": Console.WriteLine(cm.GetLeaderboard()); break; case "CompleteLaps": try { var get = cm.CompleteLaps(line.Skip(1).ToList()); if (!String.IsNullOrWhiteSpace(get)) { Console.WriteLine(get); } } catch (ArgumentException e) { Console.WriteLine(e.Message); } break; case "Box": cm.DriverBoxes(line.Skip(1).ToList()); break; default: break; } if (cm.IsFinished == true) { cm.Finich(); break; } line = Console.ReadLine().Split().ToList(); } }
static void Main(string[] args) { Console.WriteLine("INPUT:"); var standartOutput = Console.Out; var standartError = Console.Error; var bufferOutput = new StringWriter(); Console.SetOut(bufferOutput); Console.SetError(bufferOutput); Console.WriteLine(); Console.WriteLine("OUTPUT:"); try { int lapsNumber = int.Parse(Console.ReadLine()); int trackLenght = int.Parse(Console.ReadLine()); RaceTower raceTower = new RaceTower(); raceTower.SetTrackInfo(lapsNumber, trackLenght); while (true) { List <string> command = Console.ReadLine().Split(' ').ToList(); List <string> commandArgs = command.Skip(1).ToList(); //string result=""; try { switch (command.First()) { case "RegisterDriver": raceTower.RegisterDriver(commandArgs); break; case "Leaderboard": Console.WriteLine(raceTower.GetLeaderboard()); break; case "Box": raceTower.DriverBoxes(commandArgs); break; case "CompleteLaps": var result = raceTower.CompleteLaps(commandArgs); if (!string.IsNullOrEmpty(result)) { Console.WriteLine(result); return; } break; default: break; } } catch (Exception e) { Console.WriteLine(e.Message); } } } finally { Console.SetOut(standartOutput); Console.SetError(standartError); Console.Write(bufferOutput.ToString()); } }