public void ShowGameRound(string category, string word, IReadOnlyCollection <char> foundLetters,
                                  int leftAttempts)
        {
            _consoleWrapper.Clear();

            ShowCategory(category);
            ShowWord(word, foundLetters);
            ShowHangman(leftAttempts, "Your progress:");
            ShowInputPrompt();
        }
        public void DrawBoard(IGameBoard board, IPlayer player)
        {
            _consoleWrapper.Clear();
            DrawYLabels(board.YLabels.Values.AsEnumerable());

            DrawGameBoard(board, player);
        }
        public async Task Run(string[] args)
        {
            _console.Clear();
            _logger.LogInformation("Starting Application.");

            await DisplayMenu().ConfigureAwait(false);

            _logger.LogInformation("All done!");
        }
        public void ProgramLoop(string puzzleDirectory)
        {
            ConsoleColor foregroundColor = ConsoleColor.Gray;
            ConsoleColor backgroundColor = ConsoleColor.Black;

            _programHelper.SetConsoleColors(foregroundColor, backgroundColor);

            string[] puzzleFilePaths = _programHelper.GetPuzzleFilePathsFromPuzzleDirectory(puzzleDirectory, 9);

            MenuSelection menuSelection = MenuSelection.NoSelection;

            //main loop for selecting puzzle files
            do
            {
                _programHelper.WriteTitle();

                _programHelper.WriteNumberedFileNamesToConsole(puzzleFilePaths);

                short fileListNumber = _programHelper.ReadFileNumberFromConsole(puzzleFilePaths.Count());

                var(searchWords, grid) = _programHelper.ConvertPuzzleFileToSearchWordsAndGrid(puzzleFilePaths[fileListNumber - 1]);

                IGridManager gridManager = new GridManager(grid);

                _consoleWrapper.Clear();

                _consoleWrapper.WriteLine(searchWords);

                _consoleWrapper.WriteLine();

                _programHelper.WriteGridToConsole(gridManager.Grid, foregroundColor, backgroundColor);

                //loop for selecting menu actions (solve puzzle, search for a word, go back to main loop, exit program)
                do
                {
                    _consoleWrapper.WriteLine();

                    menuSelection = _programHelper.PromptForMenuSelection();

                    switch (menuSelection)
                    {
                    case MenuSelection.ShowSolution:
                        _programHelper.ShowPuzzleSolution(searchWords, gridManager, foregroundColor, backgroundColor);
                        break;

                    case MenuSelection.EnterSearchWord:
                        _programHelper.ShowSolutionForEnteredWords(searchWords, gridManager, foregroundColor, backgroundColor);
                        break;

                    default:
                        break;
                    }
                } while (menuSelection != MenuSelection.SelectAnotherFile && menuSelection != MenuSelection.Exit);
            } while (menuSelection != MenuSelection.Exit);
        }
Example #5
0
 public void Clear()
 {
     if (_parentWrapper != null)
     {
         _parentWrapper.Clear();
     }
     else
     {
         Console.Clear();
     }
 }
        public async Task ShowMenuWithActions <T>(T actionsHolder, bool isMainMenu)
        {
            var menuActions = GetActions(actionsHolder);

            while (true)
            {
                var actionToExecute = ShowMenuAndGetAction(menuActions, isMainMenu);

                if (actionToExecute == null)
                {
                    return;
                }

                _userOutput($"{Constants.Nl}Launching `{actionToExecute.Name}` command", LogLevel.Trace);

                bool isSuccessful = false;

                try
                {
                    isSuccessful = await actionToExecute.Action();
                }
                catch (GameAbortException)
                {
                    _consoleWrapper.Clear();
                    _userOutput("User aborted the game.");
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error occurred on action execution");
                }

                var result = isSuccessful ? "success" : "failure";

                _userOutput(
                    $"Action finished with {result}{Constants.Nl}",
                    LogLevel.Trace);
                _userOutput(Constants.PressEnterCont);

                _userOutput("");
                _userInput();
            }
        }
Example #7
0
        /// <summary>
        /// Main game loop
        /// </summary>
        public void Run()
        {
            while (!Finished)
            {
                Draw();

                var movement = ProcessInput(_console.ReadKey().KeyChar);
                if (movement != InputEnum.UNKNOWN && _player.IsValidMove(movement))
                {
                    _player.Move(movement);

                    if (_board.CheckCollision(_player.CurrentPosition))
                    {
                        _player.MineHit();
                    }
                    else
                    {
                        _player.Scored();
                    }
                }
            }

            if (Finished)
            {
                Draw();

                _console.WriteLine(_player.IsAlive ? "Congratulations Game Complete" : "Game Over");
                _console.WriteLine("Restart Game? (Y)");

                var restart = ProcessInput(_console.ReadKey().KeyChar);
                if (restart == InputEnum.YES)
                {
                    _console.Clear();

                    _player.Reset();
                    _board.Reset(_player.CurrentPosition);
                    _board.PopulateMines(Constants.NUMBER_OF_MINES, _player.CurrentPosition);

                    Run();
                }
            }
        }
        /// <summary>
        /// The display four items menu.
        /// </summary>
        /// <param name="str1">
        /// The string 1.
        /// </param>
        /// <param name="str2">
        /// The string 2.
        /// </param>
        /// <param name="str3">
        /// The string 3.
        /// </param>
        /// <param name="str4">
        /// The string 4.
        /// </param>
        /// <param name="ev1">
        /// The event 1.
        /// </param>
        /// <param name="ev2">
        /// The event 2.
        /// </param>
        /// <param name="ev3">
        /// The event 3.
        /// </param>
        /// <param name="ev4">
        /// The event 4.
        /// </param>
        /// <param name="output">
        /// The output.
        /// </param>
        private static void DisplayFourItemsMenu(
            string str1, 
            string str2, 
            string str3, 
            string str4, 
            EventHandler ev1, 
            EventHandler ev2, 
            EventHandler ev3, 
            EventHandler ev4, 
            IConsoleWrapper<ConsoleColor, ConsoleKeyInfo> output)
        {
            var buttons = new List<ConsoleButton<ConsoleColor>>
                              {
                                  new ConsoleButton<ConsoleColor>(
                                      20,
                                      3,
                                      ConsoleColor.Blue,
                                      ConsoleColor.Yellow,
                                      ConsoleColor.Yellow,
                                      ConsoleColor.Blue,
                                      str1),
                                  new ConsoleButton<ConsoleColor>(
                                      20,
                                      3,
                                      ConsoleColor.Blue,
                                      ConsoleColor.Yellow,
                                      ConsoleColor.Yellow,
                                      ConsoleColor.Blue,
                                      str2),
                                  new ConsoleButton<ConsoleColor>(
                                      20,
                                      3,
                                      ConsoleColor.Blue,
                                      ConsoleColor.Yellow,
                                      ConsoleColor.Yellow,
                                      ConsoleColor.Blue,
                                      str3),
                                  new ConsoleButton<ConsoleColor>(
                                      20,
                                      3,
                                      ConsoleColor.Blue,
                                      ConsoleColor.Yellow,
                                      ConsoleColor.Yellow,
                                      ConsoleColor.Blue,
                                      str4)
                              };

            buttons[0].ClickEvent += ev1;
            buttons[1].ClickEvent += ev2;
            buttons[2].ClickEvent += ev3;
            buttons[3].ClickEvent += ev4;

            output.Clear();
            var menu = new ConsoleMenu(25, 10, 1, 1, ConsoleColor.DarkBlue, ConsoleColor.Gray, buttons, output);
            menu.Start();
        }
 public static void Clear()
 {
     _consoleWrapper.Clear();
 }
Example #10
0
 public void WriteTitle()
 {
     _consoleWrapper.Clear();
     _consoleWrapper.WriteLine("---- Word Search ----");
     _consoleWrapper.WriteLine();
 }
Example #11
0
        public void Show()
        {
            var characters = _character.GetCharacterData().ToList();

            _console.Clear();
            _console.WriteLine($"Welcome {_character.User.Email} choose a character to play:");
            var i = 1;

            foreach (var character in characters)
            {
                _console.WriteLine($"{i} - {character.Name}");
                i++;
            }

            _console.WriteLine("N - Create a new character.");
            _console.WriteLine("D # - Delete a character where # is the character ID.");
            _console.WriteLine("E - Exit game.");
            _console.Write("Enter selection: ");
            var retry = true;
            var tries = 0;

            while (retry && tries < 3)
            {
                retry = false;
                var selection = _console.ReadLine();
                var split     = selection.Split(' ');
                if (int.TryParse(selection, out _))
                {
                    _mainView.Show(characters[Convert.ToInt32(selection) - 1].Name);
                }
                else if (selection.ToUpper() == "N")
                {
                    _newCharacterView.Show();
                    Show();
                }
                else if (selection.ToUpper().StartsWith('D') &&
                         split.Length == 2 &&
                         int.TryParse(split[1], out _) &&
                         characters.Count > 0 &&
                         Convert.ToInt32(split[1]) <= characters.Count)
                {
                    var name = characters[Convert.ToInt32(split[1]) - 1].Name;
                    _console.Write($"Are you sure you want delete {name}? (Y)es or (N)o: ");
                    var yesNo = _console.ReadLine();
                    if (yesNo.ToUpper().Trim() == "Y")
                    {
                        _character.Delete(name);
                        _console.WriteLine($"{name} was deleted");
                        Show();
                    }
                    else
                    {
                        retry = true;
                        tries = 0;
                        _console.Write("Enter selection: ");
                    }
                }
                else if (selection.ToUpper().StartsWith('E'))
                {
                    _console.Write("Are you sure you want to leave? (Y)es or (N)o: ");
                    var yesNo = _console.ReadLine();
                    if (yesNo.ToUpper().Trim() == "Y")
                    {
                        break;
                    }

                    retry = true;
                    tries = 0;
                    _console.Write("Enter selection: ");
                }
                else
                {
                    tries++;
                    var returnMessage = tries < 3 ? "Try again." : "Go home...";
                    _console.WriteLine($"Invalid selection. {returnMessage}");
                    retry = true;
                }
            }
        }