public static void Show() { while (true) { GuideMenu selectedMenu = null; if (!TryGetSelectedMenu(out selectedMenu)) { WaitAndClearScreen(); continue; } Console.Clear(); Console.WriteLine(selectedMenu.Tips); Console.WriteLine("-------------------------------------------------------------"); while (!selectedMenu.Do(Console.ReadLine())) { } WaitAndClearScreen(); } }
private static bool TryGetSelectedMenu(out GuideMenu selectedMenu) { var menus = new GuideMenu[] { new InputDataFromFileMenu(), new InputDataFromConsoleMenu(), new ExitMenu() }; var contents = ToContents(menus); Console.WriteLine("--------------------- Guide To Galaxy ----------------------"); Console.WriteLine(contents); Console.WriteLine("-------------------------------------------------------------"); var input = Console.ReadLine(); int id; selectedMenu = int.TryParse(input, out id) && id <= menus.Count() ? menus[id - 1] : null; if (selectedMenu == null) { Console.WriteLine("Please input valid menu number."); return(false); } else { return(true); } }