예제 #1
0
        /// <summary>
        /// Entry point method. Starts the program.
        /// </summary>
        /// <param name="args">An <see cref="string"/> array with the command line arguments (unused).</param>
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            var railwaySystemBuilder = new RailwaySystemBuilder();

            try
            {
                ConsoleWriter.WriteColoredLine("Welcome to Kiwiland Railway System!\n", ConsoleColor.Green);
                ConsoleWriter.WriteColoredLine("Select an option to continue:", ConsoleColor.Magenta);
                ConsoleWriter.WriteColoredLine($"1) Use sample input {SampleInput}.", ConsoleColor.Magenta);
                ConsoleWriter.WriteColoredLine("2) Use custom input.", ConsoleColor.Magenta);
                while (true)
                {
                    ConsoleWriter.WriteColored("\nEnter option: ", ConsoleColor.Yellow);
                    var option = Console.ReadLine();
                    if (option == "1")
                    {
                        var railwaySystem = railwaySystemBuilder.Build(SampleInput);
                        WriteOutput(railwaySystem);
                    }
                    else if (option == "2")
                    {
                        ConsoleWriter.WriteColoredLine("\nRoutes are represented by the origin and destination town, as well as the distance between them.", ConsoleColor.Yellow);
                        ConsoleWriter.WriteColoredLine("For example, a route between two towns (A to B) with a distance of 5 is represented as AB5.", ConsoleColor.Yellow);
                        ConsoleWriter.WriteColored("Please input a comma-separated set of routes: ", ConsoleColor.Yellow);
                        var railwaySystem = railwaySystemBuilder.Build(Console.ReadLine()?.Replace(" ", string.Empty));
                        WriteOutput(railwaySystem);
                    }
                    else
                    {
                        ConsoleWriter.WriteColoredLine($"{option} is not a valid option. Please try again.", ConsoleColor.Red);
                        continue;
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                ConsoleWriter.WriteColoredLine($"An unexpected exception occurred: {e}", ConsoleColor.Red);
            }

            ConsoleWriter.WriteColoredLine("\nPress any key to close the program.", ConsoleColor.Yellow);
            Console.ReadKey();
        }
예제 #2
0
 public RailwaySystemBuilderUnitTests()
 {
     Builder = new RailwaySystemBuilder();
 }