From e9cc632c7b0b884783218d6950820c3b8efbe32f Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 12:15:13 +0100 Subject: [PATCH] Better keyboard, cosmetics --- 20_Buzzword/csharp/Program.cs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index dcfdcd38..3506cc5e 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -13,15 +13,17 @@ namespace Buzzword Console.WriteLine(); } + static string keys = "type a 'Y' for another phrase or 'N' to quit"; + static void Instructions() { Console.WriteLine("This program prints highly acceptable phrases in\n" + "'Educator-speak'that you can work into reports\n" + "and speeches. Whenever a question mark is printed,\n" - + "type a 'Y' for another phrase or 'N' to quit."); + + $"{keys}."); Console.WriteLine(); Console.WriteLine(); - Console.WriteLine("Here's the first phrase:"); + Console.Write("Here's the first phrase:"); } static string[] Phrases = new[] @@ -50,7 +52,21 @@ namespace Buzzword { return $"{Capitalize(Phrases[(int)(13 * rnd.NextDouble() + 1) % Phrases.Length])} " + $"{Phrases[(int)(13 * rnd.NextDouble() + 14) % Phrases.Length]} " - + $"{Phrases[(int)(13 * rnd.NextDouble() + 27) % Phrases.Length]}."; + + $"{Phrases[(int)(13 * rnd.NextDouble() + 27) % Phrases.Length]}"; + } + + static bool Decision() + { + while (true) + { + var answer = Console.ReadKey(); + if (answer.Key == ConsoleKey.Y) + return true; + else if (answer.Key == ConsoleKey.N) + return false; + else + Console.WriteLine($"\n{keys}"); + } } static void Main(string[] args) @@ -62,11 +78,13 @@ namespace Buzzword { Console.WriteLine(); Console.WriteLine(GeneratePhrase()); + Console.WriteLine(); - var answer = Console.ReadKey(); - if (answer.Key == ConsoleKey.N) + if (!Decision()) break; } + + Console.WriteLine("\nCome back when you need help with another report!"); } } }