/// <summary> /// Display the main menu /// </summary> /// <returns></returns> public MainMenuOption DisplayMainMenu() { MainMenuOption mainMenuOption = MainMenuOption.None; int userOptionChoice = 1; bool playerConfirm = false; List <int> availableOptions = new List <int>(); Console.CursorVisible = false; //loop until player presses enter while (!playerConfirm) { //draw header ConsoleUtil.HeaderText = "Main Menu"; ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("Please Select an Option Below!"); Console.WriteLine(); //loop through enum options foreach (MainMenuOption option in Enum.GetValues(typeof(MainMenuOption))) { //add option int value to list availableOptions.Add((int)option); //ignore menu option none if (option != MainMenuOption.None) { //draw single line based on if it is the current selected option if (userOptionChoice == ((int)option)) { Console.Write("\t"); Console.BackgroundColor = ConsoleColor.DarkBlue; Console.WriteLine($"{(int)option}. {option}"); Console.BackgroundColor = ConsoleColor.Black; } else { Console.WriteLine($"\t{(int)option}. {option}"); } } } //read key var input = GetKey(); switch (input.Key) //Switch on Key { case ConsoleKey.UpArrow: userOptionChoice -= 1; //check to see if the userOptionChoice is at the top if (userOptionChoice == (availableOptions.Min())) { userOptionChoice = availableOptions.Max(); } break; case ConsoleKey.DownArrow: userOptionChoice += 1; //check to see if the userOptionChoice is at the bottom if (userOptionChoice == (availableOptions.Max() + 1)) { userOptionChoice = availableOptions.Min() + 1; } break; case ConsoleKey.Enter: playerConfirm = true; mainMenuOption = (MainMenuOption)userOptionChoice; break; } } return(mainMenuOption); }
/// <summary> /// Display the game rules /// </summary> public void DisplayGameRules() { ConsoleUtil.HeaderText = "Game Rules"; ConsoleUtil.DisplayReset(); StringBuilder sb = new StringBuilder(); sb.AppendFormat("Game Objective:"); ConsoleUtil.DisplayMessage(sb.ToString()); Console.WriteLine(); sb.Clear(); sb.AppendFormat("Be the first player to connect four of your game pieces horizontally, vertically, or diagonally."); ConsoleUtil.DisplayMessage(sb.ToString()); Console.WriteLine(); Console.WriteLine(); sb.Clear(); sb.AppendFormat("Game Rules:"); ConsoleUtil.DisplayMessage(sb.ToString()); Console.WriteLine(); sb.Clear(); sb.AppendFormat("- Players alternate dropping one of their game pieces into a column on the game board"); ConsoleUtil.DisplayMessage(sb.ToString()); sb.Clear(); sb.AppendFormat("- The game ends when four of the same pieces are connected horizontally, vertically, or diagonally"); ConsoleUtil.DisplayMessage(sb.ToString()); sb.Clear(); sb.AppendFormat("- If all of the positions on the game board are filled, the round is counted as a draw"); ConsoleUtil.DisplayMessage(sb.ToString()); sb.Clear(); sb.AppendFormat("- If the game is ended early, the round is counted as a draw"); ConsoleUtil.DisplayMessage(sb.ToString()); sb.Clear(); sb.AppendFormat("- If the game is ended while selecting the starting player, the round isn't counted"); ConsoleUtil.DisplayMessage(sb.ToString()); Console.WriteLine(); Console.WriteLine(); sb.Clear(); sb.AppendFormat("Keyboard Usage:"); ConsoleUtil.DisplayMessage(sb.ToString()); Console.WriteLine(); sb.Clear(); sb.AppendFormat("Up & Down arrow keys: Selecting the First Player to Start"); ConsoleUtil.DisplayMessage(sb.ToString()); sb.Clear(); sb.AppendFormat("Left & Right arrow keys: Selecting a column on the Gameboard to drop a piece"); ConsoleUtil.DisplayMessage(sb.ToString()); sb.Clear(); sb.AppendFormat("Enter Key: Submitting your selection"); ConsoleUtil.DisplayMessage(sb.ToString()); sb.Clear(); sb.AppendFormat("Escape Key: End the ConnectFour round to return to the Main Menu"); ConsoleUtil.DisplayMessage(sb.ToString()); sb.Clear(); sb.AppendFormat("H Key: Display the Game Rules Menu"); ConsoleUtil.DisplayMessage(sb.ToString()); sb.Clear(); Console.WriteLine(); DisplayContinuePrompt("Press any key to exit this Menu."); }
/// <summary> /// get the menu choice from the user /// </summary> public MenuOption DisplayGetUserMenuChoice() { MenuOption userMenuChoice = MenuOption.None; bool usingMenu = true; // // TODO enable each application function separately and test // while (usingMenu) { // // set up display area // ConsoleUtil.DisplayReset(); Console.CursorVisible = false; // // display the menu // ConsoleUtil.DisplayMessage("Please type the number of your menu choice."); Console.WriteLine(); Console.WriteLine( "\t" + "1. Play New Round" + Environment.NewLine + "\t" + "2. View the rules" + Environment.NewLine + "\t" + "3. View current game stats" + Environment.NewLine + "\t" + "E. Exit" + Environment.NewLine); ConsoleKeyInfo userResponse = Console.ReadKey(true); switch (userResponse.KeyChar) { case '1': userMenuChoice = MenuOption.PlayNewRound; usingMenu = false; break; case '2': userMenuChoice = MenuOption.ViewRules; usingMenu = false; break; case '3': userMenuChoice = MenuOption.ViewCurrentGameResults; usingMenu = false; break; case 'E': case 'e': userMenuChoice = MenuOption.Quit; usingMenu = false; break; default: Console.WriteLine( "It appears you have selected an incorrect choice." + Environment.NewLine + "Press any key to continue or the ESC key to quit the application."); userResponse = Console.ReadKey(true); if (userResponse.Key == ConsoleKey.Escape) { usingMenu = false; } break; } } Console.CursorVisible = true; return(userMenuChoice); }