Example #1
0
        static void Main(string[] args)
        {
            var raceTower = new RaceTower();
            var engine    = new Engine(raceTower);

            engine.Start();
        }
Example #2
0
    public static void Main()
    {
        var raceTower = new RaceTower();
        var engine    = new Engine(raceTower);

        engine.Start();
    }
Example #3
0
    public static void Main()
    {
        var RaceTower = new RaceTower();
        var engine    = new Engine(RaceTower);

        engine.Run();
    }
Example #4
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.");
    }
    private void InitilizeRaceTower()
    {
        int lapsNumber  = int.Parse(this.reader.ReadLine());
        int trackLength = int.Parse(this.reader.ReadLine());

        this.raceTower = new RaceTower();
        this.raceTower.SetTrackInfo(lapsNumber, trackLength);
    }
Example #6
0
    public static void Main()
    {
        RaceTower raceTower = new RaceTower();

        Engine.StartRace(raceTower);

        raceTower.PrintWinner();
    }
Example #7
0
    public static void Main(string[] args)
    {
        var raceTower       = new RaceTower();
        var commandExecutor = new CommandExecuter(raceTower);

        var engine = new Engine(commandExecutor, raceTower);

        engine.Run();
    }
Example #8
0
    public static void Main()
    {
        //    var carFactory = new CarFactory();
        //    var tyreFactory = new TyreFactory();
        //    var driverFactory = new DriverFactory();
        var raceTower = new RaceTower();
        var engine    = new Engine(raceTower);

        engine.Start();
    }
    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);
            }
        }
    }
Example #10
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();
            }
        }
    }
Example #11
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();
        }
    }
    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();
    }
Example #13
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();
    }
    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();
    }
Example #15
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();
    }
Example #16
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;
            }
        }
    }
Example #17
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));
    }
    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);
            }
        }
    }
Example #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);
    }
Example #20
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.");
    }
    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;
            }
        }
    }
Example #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());
    }
Example #23
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"
            };
        }
Example #24
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);
            }
        }
    }
Example #25
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;
            }
        }
    }
Example #26
0
    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 Engine(RaceTower tower)
 {
     this.tower = tower;
 }
Example #28
0
 public Engine(RaceTower raceTower)
 {
     this.raceTower = raceTower;
 }
Example #29
0
 public Engine(RaceTower raceTower)
 {
     this.raceTower     = raceTower;
     this.outputMessage = new StringBuilder();
 }
 public Engine()
 {
     this.raceTower = new RaceTower();
 }