12#include "helpers/Globals.hpp"
13#include "helpers/PageBuilder.hpp"
14#include "helpers/Terminal.hpp"
16#include "games/Hangman.hpp"
34 m_commandsRemaining = {
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z'};
123 uint32_t keyPress = 0;
124 uint32_t currentSelection = 0;
145 currentSelection == 0 ? currentSelection =
m_commandsRemaining.size() - 1 : --currentSelection;
149 currentSelection == (
m_commandsRemaining.size() - 1) ? currentSelection = 0 : ++currentSelection;
158 currentSelection =
static_cast<uint32_t
>(std::distance(
m_commandsRemaining.begin(), COMMAND_FIND_LOCATION));
169 std::this_thread::sleep_until(std::chrono::system_clock::now() + std::chrono::seconds(
m_computerSpeed));
197 const std::vector<std::string> QUIT_MENUS =
m_pageBuilder.GetQuitOptionSelectionPage();
206 const std::vector<std::string> QUIT_MENUS =
m_pageBuilder.GetQuitOptionSelectionPage();
215 const std::vector<std::string> QUIT_MENUS =
m_pageBuilder.GetQuitOptionSelectionPage();
233 std::getline(std::cin, input);
246 std::ranges::transform(input.begin(), input.end(), input.begin(), ::toupper);
248 if (std::regex_match(input, std::regex(
"^[A-Z]+$")))
263 bool isGuessCorrect =
false;
269 isGuessCorrect =
true;
void GetWordFromComputer()
Gets a random word, from the word list loaded during the setup, when the computer is the word setter.
void GetUserPlayerChoice()
Prompts the user to select which player the will be playing the game as (only supported if playing ag...
uint32_t m_turnCount
The number of turns that have occurred.
void ToggleCurrentPlayer() override
Change the current player to the other player.
void UpdateGameInformation() override
Updates GameInformation to match the current state of the game.
void ExecuteUserCommand() override
Prompt the user to enter their command for the current turn.
bool IsGameOver() override
Check whether the game is over.
void SetupGame() override
Clears and sets all member variables to their game start default.
Hangman(const bool &p_useAnsiEscapeCodes)
Constructs a new Hangman object.
void GameOver() override
Display the game over message and prompt the user whether they would like to play again or quit the g...
void ExecuteComputerCommand() override
Get a random command from the computer.
uint32_t m_computerSpeed
The computer speed determined by the amount of seconds the computer must wait before executing it's c...
std::string m_userPlayerChoice
The choice of whether the user has selected to be the guesser or word setter.
void GetUserOptions() override
Prompt the user for their choice on various game-related options.
PageBuilder m_pageBuilder
Used to build pages required by the game.
bool m_isGameOver
Whether the game is over (true) or not (false).
void GetComputerSpeed()
Prompts the user to select how the speed of the computer decision making (this does not affect the di...
void RestartGame() override
Update variables to allow for the game to be restarted with the same user options.
void ResetGame() override
Update variables to allow for the game to be reset and so the user will be asked for new options.
GameInformation m_gameInformation
Used to package up the current state of the game so it can be used by m_pageBuilder.
std::string m_playerCount
The count of the user selected number of players.
std::vector< char > m_commandsRemaining
The letters which remain to be guessed.
std::default_random_engine m_randomNumberGenerator
Used to randomly select the word to be guessed from Globals::G_HANGMAN_COMPUTER_WORDS when the comput...
bool m_hasSavedGameOptions
Whether the user has selected all the game options (true) or not/partially (false)....
std::string m_currentGuessOfWord
The current guess state of the word to be guessed from the perspective of the guesser.
std::vector< char > m_incorrectGuesses
The letters which were guessed by the guesser and are incorrect.
bool IsCurrentTurnUsers() override
Check whether the current turn should be executed by the user.
void GetWordFromUser()
Prompts the user to enter a word to be guessed (whether the word is actually a word is not checked) w...
bool m_saveGameOptions
Whether to save the user's currently selected game options (true) and restart the game or not (false)...
std::string m_computerSpeedName
The name of the user selected computer speed.
std::string m_wordToBeGuessed
The word to be guessed by the guesser.
void ExecuteGeneralCommand(const char &p_guess)
Checks the single-letter guess against the word, updates the current guess of the word and the error ...
void GetPlayerCount()
Prompts the user to select how many players will be playing the game.
char m_currentLetterSelected
The letter to display to the user to represent what their current selected guess is.
static void GetUserChoiceFromGameOverMenu(const std::string &p_gameOverPage, const std::vector< std::string > &p_quitOptionMenus)
Get the user choice whether to restart the game, reset the game or a choice from the GetUserChoiceFro...
static uint32_t GetNextKeyPress()
Wrapper for <Windows.h> API for the FlushConsoleInputBuffer() and _getch() functions.
static void PrintOutput(const std::string &p_output)
Clears and then prints to the terminal.
static uint32_t GetUserChoiceFromGameMenus(const std::vector< std::string > &p_menus, const std::vector< std::string > &p_quitOptionMenus)
Get the user choice from a list of game menus screens that are printed to the terminal.
static void SetCursorPosition(const int16_t &p_xCoord, const int16_t &p_yCoord)
Wrapper around the <Windows.h> API for the SetConsoleCursorPosition() function.
static void GetUserChoiceFromQuitMenus(const std::vector< std::string > &p_menus)
Gets the user choice from the quit menu. All user choices result in a different custom exception bein...
static const uint32_t G_HANGMAN_KEY_PRESS_CHAR_OFFSET
Hangman value to minus from key press to get char representation.
static const std::array< std::string, G_HANGMAN_NUMBER_OF_COMPUTER_WORDS > G_HANGMAN_COMPUTER_WORDS
Hangman computer word list for when the computer is asked to chose a word to be guessed.
static constexpr T ImplementStdRangesFind(const T &p_begin, const T &p_end, const U &p_value)
Implements std::ranges::find which should work for all standard template library containers.
static const uint32_t G_HANGMAN_GET_WORD_FROM_USER_COLUMN
Hangman cursor position when getting user input on Windows.
static const uint32_t G_HANGMAN_MAXIMUM_WORD_SIZE
Hangman word to be guessed constraints.
static const uint32_t G_TERMINAL_ENTER_KEY
Keyboard values when getting user input on Windows.
static const std::string G_HANGMAN_GUESSER
Hangman player choice options.
static const std::vector< std::string > G_GAME_MAX_TWO_PLAYERS_OPTIONS
Used by multiple games or an attribute not specific to one game.
static const uint32_t G_TERMINAL_UP_ARROW_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_HANGMAN_MAXIMUM_ERROR_COUNT
Hangman maximum errors count to determine whether the game is over.
static const uint32_t G_HANGMAN_USER_INPUT_ROW
Hangman cursor position when getting user input on Windows.
static const std::string G_HANGMAN_WORD_SETTER
Hangman player choice options.
static const std::vector< std::string > G_GAME_COMPUTER_SPEED_OPTIONS
Used by multiple games or an attribute not specific to one game.
static const std::vector< std::string > G_HANGMAN_PLAYER_CHOICE_OPTIONS
Hangman player choice options.
static const uint32_t G_TERMINAL_DOWN_ARROW_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_HANGMAN_MINIMUM_WORD_SIZE
Hangman word to be guessed constraints.
static const char G_HANGMAN_HIDDEN_LETTER
Hangman constants used to construct the hangman.
static const uint32_t G_TERMINAL_QUIT_KEY
Keyboard values when getting user input on Windows.
static const std::string G_GAME_UNKNOWN_OPTION
Used by multiple games or an attribute not specific to one game.
Contains all Terminal-Games objects.
@ HANGMAN
Page supported by PageBuilder.