/// <summary> /// Display a Yes or No prompt with a message /// </summary> /// <param name="promptMessage">prompt message</param> /// <returns>bool where true = yes</returns> private bool DisplayGetYesNoPrompt(string promptMessage) { bool yesNoChoice = false; bool validResponse = false; string userResponse; ConsoleUtil.DisplayPromptMessage(promptMessage + "(yes/no)"); userResponse = Console.ReadLine(); while (!validResponse) { ConsoleUtil.DisplayReset(); if (userResponse.ToUpper() == "YES") { validResponse = true; yesNoChoice = true; } else if (userResponse.ToUpper() == "NO") { validResponse = true; yesNoChoice = false; break; } else { ConsoleUtil.DisplayMessage( "It appears that you have entered an incorrect response." + " Please enter either \"yes\" or \"no\"." ); DisplayContinuePrompt(); } } return(yesNoChoice); }
/// <summary> /// display the welcome screen /// </summary> public void DisplayWelcomeScreen() { StringBuilder sb = new StringBuilder(); ConsoleUtil.HeaderText = "The Tic-tac-toe Game"; ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("Written by Courtney, Stacy, Gabe, and Bruce"); ConsoleUtil.DisplayMessage("Northwestern Michigan College"); Console.WriteLine(); sb.Clear(); sb.AppendFormat("This application is designed to allow two players to play "); sb.AppendFormat("a game of tic-tac-toe. The rules are standard, but the board is 4x4. To win, you still have to get 3 in a row. "); sb.AppendFormat("Each player gets to take a turn."); ConsoleUtil.DisplayMessage(sb.ToString()); Console.WriteLine(); ConsoleUtil.DisplayMessage("Press Q to quit at any time, if you get bored and don't to play the game anymore."); Console.WriteLine(); DisplayContinuePrompt(); }
/// <summary> /// display the welcome screen /// </summary> public void DisplayWelcomeScreen() { StringBuilder sb = new StringBuilder(); ConsoleUtil.HeaderText = "The Tic-tac-toe Game"; ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("Written by John Velis"); ConsoleUtil.DisplayMessage("Northwestern Michigan College"); Console.WriteLine(); sb.Clear(); sb.AppendFormat("This application is designed to allow two players to play "); sb.AppendFormat("a game of tic-tac-toe. The rules are the standard rules for the "); sb.AppendFormat("game with each player taking a turn."); ConsoleUtil.DisplayMessage(sb.ToString()); Console.WriteLine(); sb.Clear(); sb.AppendFormat("Your first task will be to set up your account details."); ConsoleUtil.DisplayMessage(sb.ToString()); DisplayContinuePrompt(); }
/// <summary> /// Display a Yes or No prompt with a message /// </summary> /// <param name="promptMessage">prompt message</param> /// <returns>bool where true = yes</returns> private bool DisplayGetYesNoPrompt(string promptMessage) { bool yesNoChoice = false; bool validResponse = false; string userResponse; while (!validResponse) { ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayPromptMessage(promptMessage + "(y/n)"); userResponse = Console.ReadLine(); if (userResponse.ToUpper() == "Y") { validResponse = true; yesNoChoice = true; } else if (userResponse.ToUpper() == "N") { validResponse = true; yesNoChoice = false; } else { Console.ForegroundColor = ConsoleColor.Red; ConsoleUtil.DisplayMessage( "It appears that you have entered an incorrect response." + " Please enter either \"y\" or \"n\"." ); DisplayContinuePrompt(); } } return yesNoChoice; }
public void InputPlayerName() { ConsoleUtil.HeaderText = "Play a New Round"; ConsoleUtil.DisplayReset(); //Checks if players already have names if (Player1.playerName == null || Player2.playerName == null) { Console.WriteLine("Welcome, You have chosen Play a New Round !!!"); Console.Write("\nEnter the first player name: "); string x = Console.ReadLine(); //Checks to see if user has named the player while (x == "") { Console.WriteLine("\nSorry, but the name must contain something. Please try again."); x = Console.ReadLine(); } Player1.playerName = x; Console.Write("\nEnter the second player name: "); x = Console.ReadLine(); //Checks to see if user has named the player while (x == "") { Console.WriteLine("\nSorry, but the name must contain something. Please try again."); x = Console.ReadLine(); } Player2.playerName = x; Console.WriteLine("\nChoose the starting player: "); x = Console.ReadLine(); //Checks to see if there is a player with that name. while (x != Player1.playerName && x != Player2.playerName) { Console.WriteLine("\nSorry, but the name you chose to start did not match any of the names given."); Console.WriteLine("\nPlease try again."); x = Console.ReadLine(); } //Gives the player their game piece if (Player1.playerName == x) { Player1.startingFirst = true; Player1.GamePiece = "X"; Player2.GamePiece = "O"; } else if (Player2.playerName == x) { Player2.startingFirst = true; Player2.GamePiece = "X"; Player1.GamePiece = "O"; } } else { //Message displayed if players already have names. Console.WriteLine("\nThe Players are already named. Thank you for playing again!"); Console.WriteLine("\nIf you would like to rename the players, please restart the "); Console.WriteLine("\napplication.\n"); } Console.WriteLine("\nThank you {0} and {1}", Player1.playerName, Player2.playerName + "." + " Enjoy the game!!!"); Console.WriteLine("\nPress any key to continue"); Console.ReadLine(); }
public MenuOption DisplayGetMenuChoice() { MenuOption playerMenuChoice = MenuOption.None; bool usingMenu = true; while (usingMenu) { ConsoleUtil.DisplayReset(); ConsoleUtil.HeaderText = "Menu Choice"; Console.CursorVisible = true; //Display the Menu// Console.WriteLine(); Console.WriteLine( "\t" + "******************************" + Environment.NewLine + "\t" + "Menu Choices" + Environment.NewLine + "\t" + "******************************" + Environment.NewLine + "\t" + "1. Play New Round" + Environment.NewLine + "\t" + "2. Game Rules" + Environment.NewLine + "\t" + "3. View Current Game Stats" + Environment.NewLine + "\t" + "4. View Historic Game Stats" + Environment.NewLine + "\t" + "5. Save Game" + Environment.NewLine + "\t" + "6. Quit" + Environment.NewLine); Console.WriteLine(); Console.WriteLine(); ConsoleUtil.DisplayPromptMessage("What would you like to do? (Type Letter)"); //Get User Response// ConsoleKeyInfo userResponse = Console.ReadKey(true); switch (userResponse.KeyChar) { case '1': playerMenuChoice = MenuOption.PlayNewRound; InputPlayerName(); usingMenu = false; break; case '2': playerMenuChoice = MenuOption.GameRules; usingMenu = false; break; case '3': playerMenuChoice = MenuOption.ViewCurrentGameStats; usingMenu = false; break; case '4': playerMenuChoice = MenuOption.ViewHistoricGameStats; usingMenu = false; break; case '5': playerMenuChoice = MenuOption.SaveGameResults; usingMenu = false; break; case '6': playerMenuChoice = MenuOption.Quit; usingMenu = false; break; default: Console.WriteLine("It appears you have selected an incorrect choice."); Console.WriteLine(); Console.WriteLine("Press any key to continue or the ESC key to quit the game."); userResponse = Console.ReadKey(true); if (userResponse.Key == ConsoleKey.Escape) { usingMenu = false; Environment.Exit(1); } break; } } Console.CursorVisible = true; return(playerMenuChoice); }
/// <summary> /// Displays the menu /// </summary> public void DisplayMenu(int roundsPlayed, int playerXWins, int playerOWins, int catsGames) { bool inMenu = true; while (inMenu == true) { string menuChoice; ConsoleUtil.HeaderText = "Main Menu"; ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("Main Menu"); Console.WriteLine(); ConsoleUtil.DisplayMessage("1: Play New Round"); ConsoleUtil.DisplayMessage("2: Game Results"); ConsoleUtil.DisplayMessage("3: Quit"); Console.WriteLine(); ConsoleUtil.DisplayPromptMessage("Please enter your menu choice: "); menuChoice = Console.ReadLine(); switch (menuChoice) { case "1": menuChoice = "1"; DisplayViewRules(); inMenu = false; break; case "2": menuChoice = "2"; if (roundsPlayed < 1) { ConsoleUtil.HeaderText = "Main Menu"; ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("You must play at least one round to view game results."); Console.WriteLine(); DisplayContinuePrompt(); break; } else { DisplayCurrentGameStatus(roundsPlayed, playerXWins, playerOWins, catsGames); inMenu = false; break; } case "3": menuChoice = "3"; DisplayExitPrompt(); inMenu = false; break; default: ConsoleUtil.HeaderText = "Main Menu"; ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage("Please use only 1, 2, or 3 for your choice"); Console.WriteLine(); DisplayContinuePrompt(); break; } } }
/// <summary> /// Displays the Main Menu /// </summary> /// <returns>enum</returns> public MenuOption DisplayGetMenuChoice() { string shifty = new String(' ', 34); MenuOption menuChoice = MenuOption.None; Console.WriteLine(); ConsoleUtil.DisplayReset(); ConsoleUtil.HeaderText = "Main Menu"; ; Console.CursorVisible = true; //Display the Menu// Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine("*******************************************************************************"); Console.WriteLine(shifty + " Main Menu "); Console.WriteLine("*******************************************************************************"); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine( "\t" + "1. Create Account" + Environment.NewLine); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine( "\t" + "2. Sign In " + Environment.NewLine); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine( "\t" + "3. Rules" + Environment.NewLine); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine( "\t" + "4. Play Round" + Environment.NewLine); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine( "\t" + "5. View Current Game Results" + Environment.NewLine); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine( "\t" + "6. View Past Game Results " + Environment.NewLine); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine( "\t" + "7. Quit" + Environment.NewLine); Console.WriteLine(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; ConsoleUtil.DisplayPromptMessage("Select a menu option by number:"); ConsoleKeyInfo userChoice = Console.ReadKey(true); switch (userChoice.KeyChar) { case '1': menuChoice = MenuOption.CreateAccount; break; case '2': menuChoice = MenuOption.SignIn; break; case '3': menuChoice = MenuOption.GameRules; break; case '4': menuChoice = MenuOption.PlayNewRound; break; case '5': menuChoice = MenuOption.ViewCurrentGameResults; break; case '6': menuChoice = MenuOption.ViewCurrentGameResults; break; case '7': menuChoice = MenuOption.Quit; break; default: break; } return menuChoice; }