Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        public void Run()
        {
            Isrunning = true;

            StringBuilder sb = new StringBuilder();

            totalLaps   = int.Parse(Console.ReadLine());
            trackLength = int.Parse(Console.ReadLine());
            raceTower.SetTrackInfo(totalLaps, trackLength);

            currentLap = 0;

            string output;

            while (Isrunning)
            {
                if (currentLap <= totalLaps)
                {
                    if (raceTower.CurrentLap == totalLaps)
                    {
                        Isrunning = false;
                        sb.AppendLine(raceTower.Winner().Trim());
                        Console.WriteLine(sb.ToString().Trim());
                    }

                    try
                    {
                        string line = Console.ReadLine();
                        output = ProcessCommand(line);
                    }
                    catch (InvalidOperationException e)
                    {
                        output = $"Error: {e.Message}";
                    }

                    sb.AppendLine(output);
                }
            }
        }
Ejemplo n.º 3
0
        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());
            }
        }
Ejemplo n.º 4
0
 public void CreateTower(int i, int r)
 {
     cm.SetTrackInfo(i, r);
 }