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 = (StartMenuOption)((int)(CurrentOption + 1) % NumberOfOptions); HighlightOption(CurrentOption); } break; case ConsoleKey.UpArrow: case ConsoleKey.W: { RemoveHighlight(CurrentOption); CurrentOption = CurrentOption - 1 < 0 ? StartMenuOption.Back : (StartMenuOption)(CurrentOption - 1); HighlightOption(CurrentOption); } break; } key = Console.ReadKey(true).Key; } }
private static void HighlightOption(StartMenuOption option) { if (option == StartMenuOption.LoadGame) { Console.SetCursorPosition(OptionsX, OptionsY); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(new string(' ', (SelectLength - "Load Game".Length) / 2) + "Load Game" + new string(' ', (SelectLength - "Load Game".Length) / 2 + (SelectLength - "Load Game".Length) % 2)); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; } if (option == StartMenuOption.NewGame) { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.SetCursorPosition(OptionsX, OptionsY + 1); Console.WriteLine(new string(' ', (SelectLength - "New Game".Length) / 2) + "New Game" + new string(' ', (SelectLength - "New Game".Length) / 2 + (SelectLength - "New Game".Length) % 2)); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; } if (option == StartMenuOption.Back) { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.SetCursorPosition(OptionsX, OptionsY + 2); Console.WriteLine(new string(' ', (SelectLength - "Back".Length) / 2) + "Back" + new string(' ', (SelectLength - "Back".Length) / 2 + (SelectLength - "Back".Length) % 2)); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; } }
public virtual Task <StartMenuOption> GetStartOption() { OutputProgramHeader(); Console.WriteLine("\n\nWelcome to planning poker. Please choose from the options below."); Console.WriteLine("\n1. Start new poker session\n2. Join an existing poker session\nEnter option: "); StartMenuOption selectedOption = StartMenuOption.StartSession; var optionNotChosen = true; while (optionNotChosen) { var key = Console.ReadKey(true); switch (key.KeyChar) { case '1': selectedOption = StartMenuOption.StartSession; optionNotChosen = false; break; case '2': selectedOption = StartMenuOption.JoinSession; optionNotChosen = false; break; default: Console.WriteLine("Selected option is invalid. Please chose a valid option"); break; } } return(Task.FromResult(selectedOption)); }
private static void RemoveHighlight(StartMenuOption option) { if (option == StartMenuOption.LoadGame) { Console.SetCursorPosition(OptionsX, OptionsY); Console.WriteLine(new string(' ', (SelectLength - "Load Game".Length) / 2) + "Load Game" + new string(' ', (SelectLength - "Load Game".Length) / 2 + (SelectLength - "Load Game".Length) % 2)); } if (option == StartMenuOption.NewGame) { Console.SetCursorPosition(OptionsX, OptionsY + 1); Console.WriteLine(new string(' ', (SelectLength - "New Game".Length) / 2) + "New Game" + new string(' ', (SelectLength - "New Game".Length) / 2 + (SelectLength - "New Game".Length) % 2)); } if (option == StartMenuOption.Back) { Console.SetCursorPosition(OptionsX, OptionsY + 2); Console.WriteLine(new string(' ', (SelectLength - "Back".Length) / 2) + "Back" + new string(' ', (SelectLength - "Back".Length) / 2 + (SelectLength - "Back".Length) % 2)); } }