public static void SelectOption() { ConsoleKey key = Console.ReadKey(true).Key; while (key != ConsoleKey.Enter) { switch (key) { case ConsoleKey.DownArrow: case ConsoleKey.S: { RemoveHighlight(CurrentOption); CurrentOption = (TitleScreenOption)((int)(CurrentOption + 1) % NumberOfOptions); HighlightOption(CurrentOption); } break; case ConsoleKey.UpArrow: case ConsoleKey.W: { RemoveHighlight(CurrentOption); CurrentOption = CurrentOption - 1 < 0 ? TitleScreenOption.Exit : (TitleScreenOption)(CurrentOption - 1); HighlightOption(CurrentOption); } break; } key = Console.ReadKey(true).Key; } }
private static void RemoveHighlight(TitleScreenOption option) { if (option == TitleScreenOption.Start) { Console.SetCursorPosition(OptionsX, OptionsY); Console.WriteLine(new string(' ', (SelectLength - "Start".Length) / 2) + "Start" + new string(' ', (SelectLength - "Start".Length) / 2 + (SelectLength - "Start".Length) % 2)); } if (option == TitleScreenOption.Help) { Console.SetCursorPosition(OptionsX, OptionsY + 1); Console.WriteLine(new string(' ', (SelectLength - "Help".Length) / 2) + "Help" + new string(' ', (SelectLength - "Help".Length) / 2 + (SelectLength - "Help".Length) % 2)); } if (option == TitleScreenOption.Credits) { Console.SetCursorPosition(OptionsX, OptionsY + 2); Console.WriteLine(new string(' ', (SelectLength - "Credits".Length) / 2) + "Credits" + new string(' ', (SelectLength - "Credits".Length) / 2 + (SelectLength - "Credits".Length) % 2)); } if (option == TitleScreenOption.Exit) { Console.SetCursorPosition(OptionsX, OptionsY + 3); Console.WriteLine(new string(' ', (SelectLength - "Exit".Length) / 2) + "Exit" + new string(' ', (SelectLength - "Exit".Length) / 2 + (SelectLength - "Exit".Length) % 2)); } }
private static void HighlightOption(TitleScreenOption option) { if (option == TitleScreenOption.Start) { Console.SetCursorPosition(OptionsX, OptionsY); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(new string(' ', (SelectLength - "Start".Length) / 2) + "Start" + new string(' ', (SelectLength - "Start".Length) / 2 + (SelectLength - "Start".Length) % 2)); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; } if (option == TitleScreenOption.Help) { Console.SetCursorPosition(OptionsX, OptionsY + 1); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(new string(' ', (SelectLength - "Help".Length) / 2) + "Help" + new string(' ', (SelectLength - "Help".Length) / 2 + (SelectLength - "Hepl".Length) % 2)); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; } if (option == TitleScreenOption.Credits) { Console.SetCursorPosition(OptionsX, OptionsY + 2); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(new string(' ', (SelectLength - "Credits".Length) / 2) + "Credits" + new string(' ', (SelectLength - "Credits".Length) / 2 + (SelectLength - "Credits".Length) % 2)); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; } if (option == TitleScreenOption.Exit) { Console.SetCursorPosition(OptionsX, OptionsY + 3); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(new string(' ', (SelectLength - "Exit".Length) / 2) + "Exit" + new string(' ', (SelectLength - "Exit".Length) / 2 + (SelectLength - "Exit".Length) % 2)); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; } }