示例#1
0
        private static void FluentWay()
        {
            var character = new Character();

            Consolefy
            .Initialize()
            .WriteLine("Welcome to character creation:")
            .Write("Name:")
            .ReadLine((name) => character.Name = name)
            .Write("Age:")
            .ReadLineAsInt((age) => character.Age = age, retryText: "Invalid number, please retry")
            .WriteLine("Are you a [color:Blue](J)edi[/color] or a [color:Red](S)ith[/color]?")
            .ReadKeyWithOptions()
            .If(ConsoleKey.J, (_, fluentConsole) =>
            {
                character.Alignment = Alignment.Jedi;
                fluentConsole.WithBackgroundColor(ConsoleColor.Blue);
            })
            .If(ConsoleKey.S, (_, fluentConsole) =>
            {
                character.Alignment = Alignment.Sith;
                fluentConsole.WithBackgroundColor(ConsoleColor.Red);
            })
            .ElseRetry(retryText: "Invalid option, please try again.")
            .DoWithLoading(() => DoComplexLogic(), loadingText: "Loading")
            .WriteLine($"Welcome to the game {character.Name}!");
        }
示例#2
0
 private static void Main()
 {
     while (true)
     {
         Consolefy
         .Initialize()
         .SetupQuittingBehavior((consolefy) => consolefy.WriteLine("Quitting"))
         .WriteLine("1. Default Wayt")
         .WriteLine("2. Fluent")
         .WriteLine("Q. Quit")
         .ReadKeyLineWithOptions()
         .If(ConsoleKey.D1, DefaultWay)
         .If(ConsoleKey.D2, FluentWay)
         .If(ConsoleKey.Q, (_, consolefy) => consolefy.Quit())
         .ElseRetry();
     }
 }