示例#1
0
    internal void Run()
    {
        int numberOflaps  = int.Parse(Console.ReadLine());
        int lengthOfTrack = int.Parse(Console.ReadLine());


        while (true)
        {
            string input = Console.ReadLine();

            try
            {
                raceTower.SetTrackInfo(numberOflaps, lengthOfTrack);
                CommandParser(input);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }

            if (raceTower.HasEnd)
            {
                break;
            }
        }

        Driver winer = raceTower.GetWiner();

        Console.WriteLine($"{winer.Name} wins the race for {winer.TotalTime:f3} seconds.");
    }
示例#2
0
    public void Run()
    {
        int totalLaps        = int.Parse(Console.ReadLine());
        int lengthOfTheTrack = int.Parse(Console.ReadLine());

        raceTower.SetTrackInfo(totalLaps, lengthOfTheTrack);

        while (raceTower.IsEndOfRace != true)
        {
            List <string> inputCommandOfArg = Console.ReadLine()
                                              .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                              .ToList();

            string        command      = inputCommandOfArg[0];
            List <string> commandOfArg = inputCommandOfArg.Skip(1).ToList();
            CompliteCommand(totalLaps, lengthOfTheTrack, command, commandOfArg);
        }

        if (this.raceTower.IsEndOfRace)
        {
            Console.WriteLine(
                $"{this.raceTower.Winner.Name} wins the race for {this.raceTower.Winner.TotalTime:F3} seconds.");
            Environment.Exit(0);
        }
    }
示例#3
0
    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.");
    }
示例#4
0
    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);
            }
        }
    }
示例#6
0
    public void Run()
    {
        int lapsNumber  = int.Parse(Console.ReadLine());
        int trackLength = int.Parse(Console.ReadLine());

        raceTower.SetTrackInfo(lapsNumber, trackLength);

        while (raceTower.CurrentLap != lapsNumber)
        {
            string[] commandTokens = Console.ReadLine().Split();

            switch (commandTokens[0])
            {
            case "RegisterDriver":
                this.raceTower.RegisterDriver(commandTokens.Skip(1).ToList());
                break;

            case "Leaderboard":
                Console.WriteLine(this.raceTower.GetLeaderboard());
                break;

            case "CompleteLaps":
                try
                {
                    string lapsResult = this.raceTower.CompleteLaps(commandTokens.Skip(1).ToList());
                    if (lapsResult != String.Empty)
                    {
                        Console.WriteLine(lapsResult);
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }

                break;

            case "Box":
                this.raceTower.DriverBoxes(commandTokens.Skip(1).ToList());
                break;

            case "ChangeWeather":
                this.raceTower.ChangeWeather(commandTokens.Skip(1).ToList());
                break;

            default:
                break;
            }
        }

        Driver winner = this.raceTower.ActiveDrivers.OrderByDescending(d => d.TotalTime).FirstOrDefault();

        Console.WriteLine($"{winner.Name} wins the race for {winner.TotalTime:f3} seconds.");
    }
示例#7
0
    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();
            }
        }
    }
示例#8
0
    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();
        }
    }
    public void Run()
    {
        var numberOfLaps = int.Parse(Console.ReadLine());
        var trackLength  = int.Parse(Console.ReadLine());

        raceTower.SetTrackInfo(numberOfLaps, trackLength);

        while (true)
        {
            var args    = Console.ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
            var command = args[0];
            args = args.Skip(1).ToList();

            try
            {
                switch (command)
                {
                case "RegisterDriver":
                    this.raceTower.RegisterDriver(args);
                    break;

                case "Leaderboard":
                    Console.WriteLine(this.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":
                    this.raceTower.DriverBoxes(args);
                    break;

                case "ChangeWeather":
                    this.raceTower.ChangeWeather(args);
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
    static void Main(string[] args)
    {
        int numberOfLaps = int.Parse(Console.ReadLine());
        int truckLength  = int.Parse(Console.ReadLine());

        RaceTower raceTower = new RaceTower();

        raceTower.SetTrackInfo(numberOfLaps, truckLength);

        Engine engine = new Engine(raceTower);

        engine.Run();
    }
示例#11
0
    public void Run()
    {
        int raceLaps  = int.Parse(Console.ReadLine());
        int lapLength = int.Parse(Console.ReadLine());

        tower.SetTrackInfo(raceLaps, lapLength);

        while (true)
        {
            string inputData = Console.ReadLine();
            CommandDistributor(inputData);
        }
    }
    public static void Main()
    {
        var countOfLaps = int.Parse(Console.ReadLine());
        var trackLength = int.Parse(Console.ReadLine());

        RaceTower race = new RaceTower();

        race.SetTrackInfo(countOfLaps, trackLength);

        Engine engine = new Engine(race);

        engine.Run();
    }
示例#13
0
    public static void Main()
    {
        var numberOfLaps = int.Parse(Console.ReadLine());
        var trackLength  = int.Parse(Console.ReadLine());

        var raceTower = new RaceTower();

        raceTower.SetTrackInfo(numberOfLaps, trackLength);

        var engine = new Engine(raceTower);

        engine.Run();
    }
示例#14
0
    static void Main()
    {
        int laps        = int.Parse(Console.ReadLine());
        int trackLength = int.Parse(Console.ReadLine());

        RaceTower tower = new RaceTower();

        tower.SetTrackInfo(laps, trackLength);

        Engine engine = new Engine(tower);

        engine.Run();
    }
示例#15
0
    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;
            }
        }
    }
示例#16
0
    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));
    }
示例#17
0
    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);
            }
        }
    }
示例#19
0
    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);
    }
示例#20
0
    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;
            }
        }
    }
示例#21
0
    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.");
    }
示例#22
0
    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;
            }
        }
    }
示例#24
0
        public void Init()
        {
            raceTower = new RaceTower();
            raceTower.SetTrackInfo(10, 20);

            aggressiveDriverSoftTires = new List <string> {
                "Aggressive", "Bob", "500", "160", "Ultrasoft", "5", "5"
            };
            enduranceDriverHardTires = new List <string> {
                "Endurance", "Bob", "500", "150", "Ultrasoft", "5", "5"
            };
            tooMuchFuelDriverSoftTires = new List <string> {
                "Endurance", "Bob", "500", "5000", "Ultrasoft", "5", "5"
            };
            fastDegradationEnduranceDriverSoftTires = new List <string> {
                "Endurance", "Bob", "500", "160", "Ultrasoft", "10", "10"
            };
        }
示例#25
0
    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);
            }
        }
    }
示例#26
0
    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;
            }
        }
    }
示例#27
0
    public void Run()
    {
        int lapsNumber  = int.Parse(Console.ReadLine());
        int trackLength = int.Parse(Console.ReadLine());

        raceTower.SetTrackInfo(lapsNumber, trackLength);

        while (!this.raceTower.IsRaceOver)
        {
            var    commandArgs = Console.ReadLine().Split().ToList();
            string command     = commandArgs[0];
            var    methodArgs  = commandArgs.Skip(1).ToList();

            switch (command)
            {
            case "RegisterDriver":
                this.raceTower.RegisterDriver(methodArgs);
                break;

            case "Leaderboard":
                Console.WriteLine(this.raceTower.GetLeaderboard());
                break;

            case "CompleteLaps":
                string result = this.raceTower.CompleteLaps(methodArgs);

                if (!string.IsNullOrWhiteSpace(result))
                {
                    Console.WriteLine(result);
                }
                break;

            case "Box":
                this.raceTower.DriverBoxes(methodArgs);
                break;

            case "ChangeWeather":
                this.raceTower.ChangeWeather(methodArgs);
                break;
            }
        }
    }
示例#28
0
    internal void Run()
    {
        int numberOflaps  = int.Parse(Console.ReadLine());
        int lengthOfTrack = int.Parse(Console.ReadLine());

        while (numberOflaps-- > 0)
        {
            string input = Console.ReadLine();

            try
            {
                raceTower.SetTrackInfo(numberOflaps, lengthOfTrack);
                CommandParser(input);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
    }
    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());
    }
示例#30
0
    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.");
    }