/// <summary> /// Constructor for the Start command. /// </summary> /// <param name="engine">Curent game engine.</param> /// <param name="matrix">Current game matrix.</param> /// <param name="player">Current game player.</param> /// <param name="matrixDirector">Matrix director constructing the matrix.</param> /// <param name="matrixBuilder">Matrix builder used by matrix director.</param> /// <param name="printer">Current game printer.</param> public StartCommand(MinesweeperEngine engine, Matrix matrix, Player player, MatrixDirector matrixDirector, MatrixBuilder matrixBuilder, Printer printer) : base(matrix, player, printer) { this.engine = engine; this.director = matrixDirector; this.builder = matrixBuilder; }
/// <summary> /// Process the set choice from MAIN MENU and retrieves the result from it /// </summary> /// <param name="inputChoice">takes the set choice from the user as argument</param> /// <param name="game">imports the game engine</param> public static void ProcessMainMenu(int inputChoice, MinesweeperEngine game) { if (inputChoice == 0) { Console.Clear(); PrintLogo.Print(); Console.SetCursorPosition((CustomizeConsole.Width / 2) - 10, 10); Console.WriteLine("- CHOOSE GAME DIFFICULTY -\n\n\n"); Navigation.GameDifficultyNavigation(game, new MatrixTypes()); } else if (inputChoice == 1) { Console.Clear(); PrintLogo.Print(); Console.SetCursorPosition((CustomizeConsole.Width / 2) - 10, 10); Console.WriteLine("- HIGH SCORES -\n\n\n"); game.ExecuteCommand("highscore"); Navigation.ReturnExitNavigation(game, new SecondMenuOptions()); } else if (inputChoice == 2) { Console.Clear(); PrintLogo.Print(); Console.SetCursorPosition((CustomizeConsole.Width / 2) - 10, 10); Console.WriteLine("- CHOOSE MODE TO PLAY -\n\n\n"); Navigation.GameModeNavigation(game, new ModeOptions()); Navigation.ReturnExitNavigation(game, new SecondMenuOptions()); } else if (inputChoice == 3) { Console.Clear(); PrintLogo.Print(); Console.SetCursorPosition(20, 9); Console.WriteLine(" - HOW TO PLAY - \n\n\n"); Console.WriteLine(" * Enter 'turn row col' (where row and col are numbers) to open a new field"); Console.WriteLine(" * Enter 'exit' to Exit the game"); Console.WriteLine(" * Enter 'save' to Save the current state of the game"); Console.WriteLine(" * Enter 'load' to Load previously saved game"); Console.WriteLine(" * Enter 'menu' to return to Main Menu"); Console.WriteLine(" * Enter 'highscore' to review the highscores table"); Navigation.ReturnExitNavigation(game, new SecondMenuOptions()); } else if (inputChoice == 4) { game.ExecuteCommand("exit"); } }
/// <summary> /// Process the set choice from LIGHT/DARK MENU and retrieves the result from it /// </summary> /// <param name="currentChoice">takes the set choice from the user as argument</param> /// <param name="game">imports the game engine</param> public static void ProcessGameMode(int currentChoice, MinesweeperEngine game) { switch (currentChoice) { case 0: game.ExecuteCommand("mode light"); break; case 1: game.ExecuteCommand("mode dark"); break; } Navigation.ReturnExitNavigation(game, new SecondMenuOptions()); }
/// <summary> /// Process the set choice from GAMEDIFFICULTY MENU and retrieves the result from it /// </summary> /// <param name="currentChoice">takes the set choice from the user as argument</param> /// <param name="game">imports the game engine</param> public static void ProcessGameDifficulty(int currentChoice, MinesweeperEngine game) { switch (currentChoice) { case 0: game.ExecuteCommand("start small"); break; case 1: game.ExecuteCommand("start medium"); break; case 2: game.ExecuteCommand("start big"); break; } }
/// <summary> /// Constructor for the turn command /// </summary> /// <param name="engine">Current game engine.</param> /// <param name="matrix">Currentgame matrix.</param> /// <param name="player">Current game player.</param> /// <param name="printer">Current game printer.</param> public TurnCommand(MinesweeperEngine engine, Matrix matrix, Player player, Printer printer) : base(matrix, player, printer) { this.engine = engine; }
/// <summary> /// Set the navigation logic and colors for the horizontal menu /// </summary> /// <param name="game">Import the game engine</param> /// <param name="e">Import the desired enumeration, which will be used for the navigation</param> /// <returns>Returns the selected choice, in order to be further processed</returns> internal static int HorizontalOfMenus(MinesweeperEngine game, Enum e) { string[] secMenuItems = new string[Enum.GetNames(e.GetType()).Length]; var indexer = 0; foreach (var option in Enum.GetValues(e.GetType())) { secMenuItems[indexer] = option.ToString(); indexer++; } while (true) { for (int i = 0; i < secMenuItems.Length; i++) { if (currentChoice == i) { if (Console.BackgroundColor == ConsoleColor.White) { Console.ForegroundColor = ConsoleColor.DarkGreen; } else { Console.ForegroundColor = ConsoleColor.Green; } } else { if (Console.BackgroundColor == ConsoleColor.White) { Console.ForegroundColor = ConsoleColor.DarkGray; } else { Console.ForegroundColor = ConsoleColor.Gray; } } Console.SetCursorPosition(25 + (10 * i), 27); Console.WriteLine(secMenuItems[i]); } if (Console.KeyAvailable) { for (int i = 0; i < secMenuItems.Length; i++) { if (currentChoice == i) { if (Console.BackgroundColor == ConsoleColor.White) { Console.ForegroundColor = ConsoleColor.DarkGreen; } else { Console.ForegroundColor = ConsoleColor.Green; } } else { if (Console.BackgroundColor == ConsoleColor.White) { Console.ForegroundColor = ConsoleColor.DarkGray; } else { Console.ForegroundColor = ConsoleColor.Gray; } } Console.SetCursorPosition(25 + (10 * i), 27); Console.WriteLine(secMenuItems[i]); } ConsoleKeyInfo pressedKey = Console.ReadKey(); if (pressedKey.Key == ConsoleKey.LeftArrow) { currentChoice = (currentChoice - 1 + secMenuItems.Length) % secMenuItems.Length; } if (pressedKey.Key == ConsoleKey.RightArrow) { currentChoice = (currentChoice + 1) % secMenuItems.Length; } if (pressedKey.Key == ConsoleKey.Enter) { break; } } } return currentChoice; }
/// <summary> /// Set the navigation logic and colors for the vertical menu /// </summary> /// <param name="game">Import the game engine</param> /// <param name="e">Import the desired enumeration, which will be used for the navigation</param> /// <returns>Returns the selected choice, in order to be further processed</returns> internal static int VerticalOrientation(MinesweeperEngine game, Enum e) { string[] menuItems = new string[Enum.GetNames(e.GetType()).Length]; var indexer = 0; foreach (var option in Enum.GetValues(e.GetType())) { menuItems[indexer] = option.ToString(); indexer++; } while (true) { for (int i = 0; i < menuItems.Length; i++) { Console.SetCursorPosition((CustomizeConsole.Width / 2) - (menuItems[i].Length / 2), 10 + i + 1); if (currentChoice == i) { if (Console.BackgroundColor == ConsoleColor.White) { Console.ForegroundColor = ConsoleColor.DarkGreen; } else { Console.ForegroundColor = ConsoleColor.Green; } } else { if (Console.BackgroundColor == ConsoleColor.White) { Console.ForegroundColor = ConsoleColor.DarkGray; } else { Console.ForegroundColor = ConsoleColor.Gray; } } Console.WriteLine(menuItems[i]); } if (Console.KeyAvailable) { for (int i = 0; i < menuItems.Length; i++) { Console.SetCursorPosition((CustomizeConsole.Width / 2) - (menuItems[i].Length / 2), 10 + i + 1); if (currentChoice == i) { if (Console.BackgroundColor == ConsoleColor.White) { Console.ForegroundColor = ConsoleColor.DarkGreen; } else { Console.ForegroundColor = ConsoleColor.Green; } } else { if (Console.BackgroundColor == ConsoleColor.White) { Console.ForegroundColor = ConsoleColor.Black; } else { Console.ForegroundColor = ConsoleColor.White; } } Console.WriteLine(menuItems[i]); } ConsoleKeyInfo choice = Console.ReadKey(); if (choice.Key == ConsoleKey.DownArrow) { currentChoice = (currentChoice + 1) % menuItems.Length; } if (choice.Key == ConsoleKey.UpArrow) { currentChoice = (currentChoice - 1 + menuItems.Length) % menuItems.Length; } if (choice.Key == ConsoleKey.Enter) { break; } } } return currentChoice; }
/// <summary> /// Process the request for the RETURN/EXIT MENU from the navigation to the class that will retrieve it /// </summary> /// <param name="game">Import the game engine</param> /// <param name="e">Takes the desired enumeration for processing the navigation</param> internal static void ReturnExitNavigation(MinesweeperEngine game, Enum e) { currentChoice = MenuOrientation.HorizontalOfMenus(game, e); ProcessInput.ProcessSecondMenu(currentChoice, game); }
/// <summary> /// Process the request for LIGHT/DARK MODE MENU from the navigation to the class that will retrieve it /// </summary> /// <param name="game">Import the game engine</param> /// <param name="e">Takes the desired enumeration for processing the navigation</param> internal static void GameModeNavigation(MinesweeperEngine game, Enum e) { currentChoice = MenuOrientation.VerticalOrientation(game, e); ProcessInput.ProcessGameMode(currentChoice, game); }
/// <summary> /// Process the request for the MAIN MENU from the navigation to the class that will retrieve it /// </summary> /// /// <param name="game">Import the game engine</param> /// <param name="e">Takes the desired enumeration for processing the navigation</param> public static void MainMenuNavigation(MinesweeperEngine game, Enum e) { currentChoice = MenuOrientation.VerticalOrientation(game, e); ProcessInput.ProcessMainMenu(currentChoice, game); }
/// <summary> /// Process the set choice from RETURN/EXIT MENU and retrieves the result from it /// </summary> /// <param name="currentChoice">takes the set choice from the user as argument</param> /// <param name="game">imports the game engine</param> public static void ProcessSecondMenu(int currentChoice, MinesweeperEngine game) { switch (currentChoice) { case 0: Console.Clear(); PrintLogo.Print(); MainMenu.PrintMenu(game); break; case 1: game.ExecuteCommand("exit"); break; } }