85 template<
typename T,
typename U>
88 for (T i = p_begin; i < p_end; i++)
111 template<
typename T,
typename U>
116 for (T i = p_begin; i < p_end; i++)
134 static std::string
RepeatString(
const uint32_t& p_numberOfRepetitions,
const std::string& p_stringToRepeat)
136 std::ostringstream buffer;
137 for (uint32_t currentRepetition = 0; currentRepetition < p_numberOfRepetitions; currentRepetition++)
139 buffer << p_stringToRepeat;
150 static constexpr void RemoveSubString(std::string& p_string,
const std::string& p_subString)
152 const uint32_t SUB_STRING_LENGTH = p_subString.size();
153 for (std::string::size_type currentSubStringLocation = p_string.find(p_subString); currentSubStringLocation != std::string::npos; currentSubStringLocation = p_string.find(p_subString))
155 p_string.erase(currentSubStringLocation, SUB_STRING_LENGTH);
172 static inline const std::string
G_MAIN_MENU_CLI_HELP_MESSAGE =
"\nUsage: terminal-games [options]\n\nOPTIONS:\n\nGeneric Options:\n\n -h --help Display available options.\n\nOptional Options:\n\n --a --ascii-only Only use extended ASCII characters (this removes all colour).\n\n";
Used when the backspace key is pressed.
Used for functionality that has not been implemented.
Used to quit the main menu.
Used to quit the program.
Used to reset a game which prompts the user for new options.
Used to restart a game with the same user options.
Contains all custom exceptions.
Contains all global and constant objects.
static const uint32_t G_HANGMAN_KEY_PRESS_CHAR_OFFSET
Hangman value to minus from key press to get char representation.
static const std::string G_TICTACTOE_GRID_ROW_VALUE_DIVIDER
TicTacToe grid values.
static const std::vector< std::string > G_QUIT_MENU_OPTIONS
Quit menu options.
static const uint32_t G_BATTLESHIPS_SHIP_COUNT
Battleships number of ships for each board/player.
static const std::array< std::string, G_BATTLESHIPS_SHIP_COUNT > G_BATTLESHIPS_SHIP_PLACED_NAMES
Battleships list of ship names when placed on a board.
static const std::string G_PAGE_ANSI_RED_COLOUR_ESCAPE_CODE
ANSI colour escape codes to add colour to output.
static const uint32_t G_BATTLESHIPS_SUBMARINE_SIZE
Battleships ship-related constants used in later arrays.
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 const std::string G_TICTACTOE_TOP_TITLE
Page attributes for all TicTacToe pages.
static const uint32_t G_BATTLESHIPS_GRID_ELEMENT_HEIGHT
Battleships board attributes.
static const uint32_t G_TERMINAL_ALTERNATIVE_DOWN_ARROW_KEY
Keyboard values when getting user input other platforms.
static const std::string G_BATTLESHIPS_TOP_TITLE
Page attributes for all Battleships pages.
static const char G_PAGE_ANSI_COLOUR_ESCAPE_CODE_START
ANSI colour escape codes to add colour to output.
static const std::string G_TICTACTOE_GRID_PLAYER_X_OCCUPIED
TicTacToe grid values.
static const std::string G_TICTACTOE_GRID_PLAYER_O_OCCUPIED
TicTacToe grid values.
static const uint32_t G_TERMINAL_ALTERNATIVE_LEFT_ARROW_KEY
Keyboard values when getting user input other platforms.
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_MAIN_MENU_DISPLAY_HEIGHT
Page attributes for the MainMenu page.
static const bool G_PLATFORM_IS_WINDOWS
Used by PageBuilder to display the current platform being used and used by Terminal to decided whethe...
static const uint32_t G_BATTLESHIPS_DISPLAY_WIDTH
Page attributes for all Battleships pages.
static const uint32_t G_QUIT_MENU_QUIT_GAME_INDEX
Quit menu options.
static const uint32_t G_QUIT_MENU_QUIT_PROGRAM_INDEX
Quit menu options.
static const std::string G_HANGMAN_GALLOWS_VERTICAL_BEAM_WITH_ROPE
Hangman constants used to construct the hangman.
static const uint32_t G_PAGE_ANSI_COLOUR_ESCAPE_CODE_COUNT
ANSI colour escape codes to add colour to output.
static const uint32_t G_BATTLESHIPS_GRID_TOP_PAD
Battleships board attributes.
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 char G_PAGE_BOTTOM_RIGHT_CORNER
Extended ASCII characters for edges and corners of the page.
static const uint32_t G_HANGMAN_DISPLAY_WIDTH
Page attributes for all Hangman pages.
static const std::array< std::string, G_PAGE_ANSI_COLOUR_ESCAPE_CODE_COUNT > G_PAGE_ANSI_ALL_COLOUR_ESCAPE_CODES
static const uint32_t G_HANGMAN_GET_USER_COMMAND_COLUMN
Hangman cursor position when getting user input on Windows.
static const char G_PAGE_LIGHT_HASH
Misc extended ASCII characters.
static const char G_PAGE_GRID_TOP_RIGHT
Extended ASCII characters for grids.
static const uint32_t G_TERMINAL_ENTER_KEY
Keyboard values when getting user input on Windows.
static const char G_PAGE_GRID_TOP_LEFT
Extended ASCII characters for grids.
static const std::string G_HANGMAN_GUESSER
Hangman player choice options.
static const std::string G_BATTLESHIPS_SUCCESSFUL_ATTACK
Battleships board values.
static const std::string G_PAGE_ANSI_BLUE_COLOUR_ESCAPE_CODE
ANSI colour escape codes to add colour to output.
static const std::string G_HANGMAN_WORD_TO_BE_GUESSED_END
Hangman constants used to construct the hangman.
static const uint32_t G_TERMINAL_RIGHT_ARROW_KEY
Keyboard values when getting user input on Windows.
static const std::string G_HANGMAN_GALLOWS_VERTICAL_BEAM_WITH_PADDING
Hangman constants used to construct the hangman.
static const std::string G_HANGMAN_GALLOWS_VERTICAL_BEAM
Hangman constants used to construct the hangman.
static const std::string G_BATTLESHIPS_GRID_BOTTOM_LINE_BOTTOM_LEFT
Battleships board constants used to construct the board.
static const std::string G_HANGMAN_WORD_TO_BE_GUESSED_START
Hangman constants used to construct the hangman.
static const std::string G_BATTLESHIPS_MISSED_ATTACK
Battleships board values.
static const std::string G_BATTLESHIPS_GRID_MIDDLE_LINE_MIDDLE
Battleships board constants used to construct the board.
static const std::string G_HOMEPAGE_BOTTOM_TITLE
Page attributes for the homepage.
static const std::string G_BATTLESHIPS_GRID_BOTTOM_LINE_MIDDLE
Battleships board constants used to construct the board.
static const std::string G_BATTLESHIPS_GRID_MIDDLE_LINE
Battleships board constants used to construct the board.
static const char G_PAGE_VERTICAL_LINE
Extended ASCII characters for edges and corners of the page.
static const uint32_t G_BATTLESHIPS_BOARD_WIDTH
Battleships board attributes.
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 std::string G_PAGE_ANSI_YELLOW_COLOUR_ESCAPE_CODE
ANSI colour escape codes to add colour to output.
static const uint32_t G_TICTACTOE_GRID_WIDTH
TicTacToe grid attributes.
static const std::string G_PAGE_OPTION_SELECTOR
For when highlighting what is currently selected in an option menu.
static const std::string G_BATTLESHIPS_DESTROYER_PLACED_NAME
Battleships ship-related constants used in later arrays.
static const uint32_t G_QUIT_MENU_QUIT_MAIN_MENU_INDEX
Quit menu options.
static const char G_PAGE_GRID_VERTICAL_LINE
Extended ASCII characters for grids.
static const char G_PAGE_DARK_HASH
Misc extended ASCII characters.
static const std::string G_BATTLESHIPS_BATTLESHIP_PLACED_NAME
Battleships ship-related constants used in later arrays.
static const uint32_t G_TERMINAL_ALTERNATIVE_RIGHT_ARROW_KEY
Keyboard values when getting user input other platforms.
static const std::string G_BATTLESHIPS_PATROL_BOAT_NAME
Battleships ship-related constants used in later arrays.
static const std::string G_BATTLESHIPS_BOTTOM_TITLE
Page attributes for all Battleships pages.
static const char G_PAGE_CENTRAL_DOT
Misc extended ASCII characters.
static const uint32_t G_TERMINAL_CURSOR_WIDTH_PERCENTAGE
The cursor width while running on windows.
static const uint32_t G_TICTACTOE_DISPLAY_WIDTH
Page attributes for all TicTacToe pages.
static const uint32_t G_PAGE_ANSI_COLOUR_ESCAPE_CODE_SIZE
ANSI colour escape codes to add colour to output.
static const std::array< std::string, G_GAME_TWO_OPTIONS > G_BATTLESHIPS_PLAYER_CHOICE_OPTIONS
Battleships player choice options.
static const char G_PAGE_GRID_UPSIDE_DOWN_T
Extended ASCII characters for grids.
static const uint32_t G_TICTACTOE_GRID_ELEMENT_HEIGHT
TicTacToe grid attributes.
static const std::string G_TICTACTOE_EMPTY_GRID_VALUE
TicTacToe grid values.
static const std::string G_HANGMAN_BOTTOM_TITLE
Page attributes for all Hangman pages.
static const std::string G_HANGMAN_TOP_TITLE
Page attributes for all Hangman pages.
static const uint32_t G_PAGE_MINIMUM_RIGHT_PADDING_SIZE
Minimum padding amounts.
static const uint32_t G_TERMINAL_ALTERNATIVE_BACKSPACE_KEY
Keyboard values when getting user input other platforms.
static const std::string G_MAIN_MENU_BOTTOM_TITLE
Page attributes for the MainMenu page.
static const std::string G_BATTLESHIPS_PLAYER_ONE
Battleships player choice options.
static const std::string G_BATTLESHIPS_GRID_ITEM_HORIZONTAL_LINE
Battleships board constants used to construct the board.
static const uint32_t G_MAIN_MENU_DISPLAY_WIDTH
Page attributes for the MainMenu page.
static const uint32_t G_BATTLESHIPS_PATROL_BOAT_SIZE
Battleships ship-related constants used in later arrays.
static const char G_PAGE_GRID_T
Extended ASCII characters for grids.
static const std::string G_BATTLESHIPS_GRID_TOP_LINE
Battleships board constants used to construct the board.
static const uint32_t G_TICTACTOE_GRID_LEFT_PAD
TicTacToe grid attributes.
static const uint32_t G_HANGMAN_GALLOWS_BASE_WIDTH
Hangman constants used to construct the hangman.
static const std::string G_HANGMAN_GALLOWS_BASE_HALF
Hangman constants used to construct the hangman.
static const uint32_t G_TICTACTOE_DISPLAY_HEIGHT
Page attributes for all TicTacToe pages.
static const std::string G_HANGMAN_INCORRECT_GUESSES_PADDING
Hangman constants used to construct the hangman.
static const uint32_t G_TERMINAL_LEFT_ARROW_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_BATTLESHIPS_GRID_ELEMENT_WIDTH
Battleships board attributes.
static const char G_PAGE_GRID_LEFT_SIDEWAYS_T
Extended ASCII characters for grids.
static std::string RepeatString(const uint32_t &p_numberOfRepetitions, const std::string &p_stringToRepeat)
Repeats p_stringToRepeat for a total of p_numberOfRepetitions number of times.
static const uint32_t G_TICTACTOE_GRID_TOP_PAD
TicTacToe grid attributes.
static const char G_PAGE_HORIZONTAL_LINE
Extended ASCII characters for edges and corners of the page.
static const uint32_t G_QUIT_MENU_RESTART_GAME_INDEX
Quit menu options.
static const char G_PAGE_GRID_HORIZONTAL_LINE
Extended ASCII characters for grids.
static const uint32_t G_BATTLESHIPS_BATTLESHIP_SIZE
Battleships ship-related constants used in later arrays.
static const std::string G_PAGE_ANSI_GREEN_COLOUR_ESCAPE_CODE
ANSI colour escape codes to add colour to output.
static const std::string G_HANGMAN_INCORRECT_GUESSES_TITLE
Hangman constants used to construct the hangman.
static const uint32_t G_TERMINAL_UP_ARROW_KEY
Keyboard values when getting user input on Windows.
static const std::string G_BATTLESHIPS_GRID_MIDDLE_LINE_LEFT
Battleships board constants used to construct the board.
static const uint32_t G_HANGMAN_MAXIMUM_ERROR_COUNT
Hangman maximum errors count to determine whether the game is over.
static const std::string G_BATTLESHIPS_PLAYER_TWO
Battleships player choice options.
static const uint32_t G_QUIT_MENU_CANCEL_INDEX
Quit menu options.
static const std::string G_PAGE_ANSI_WHITE_COLOUR_ESCAPE_CODE
ANSI colour escape codes to add colour to output.
static const std::string G_GAME_NUMBER_OF_PLAYERS
Used by multiple games or an attribute not specific to one game.
static const std::vector< std::string > G_TICTACTOE_PLAYER_CHOICE_OPTIONS
TicTacToe player choice options.
static const std::vector< std::vector< std::string > > G_HANGMAN_STATES
Hangman constants used to display the current state of the Hangman game.
static const std::string G_GAME_COMPUTER_SPEED
Used by multiple games or an attribute not specific to one game.
static const uint32_t G_BATTLESHIPS_LETTER_OFFSET
Battleships board constants used to construct the board.
static const std::string G_TICTACTOE_PLAYER_X
TicTacToe player choice options.
static const std::string G_BATTLESHIPS_BATTLESHIP_NAME
Battleships ship-related constants used in later arrays.
static const uint32_t G_BATTLESHIPS_DESTROYER_SIZE
Battleships ship-related constants used in later arrays.
static const uint32_t G_TERMINAL_ALTERNATIVE_UP_ARROW_KEY
Keyboard values when getting user input other platforms.
static const std::string G_HANGMAN_GALLOWS_BASE
Hangman constants used to construct the hangman.
static const uint32_t G_HANGMAN_USER_INPUT_ROW
Hangman cursor position when getting user input on Windows.
static const uint32_t G_QUIT_MENU_RESET_GAME_INDEX
Quit menu options.
static const std::string G_BATTLESHIPS_DESTROYER_NAME
Battleships ship-related constants used in later arrays.
static const std::string G_MAIN_MENU_TOP_TITLE
Page attributes for the MainMenu page.
static const uint32_t G_TICTACTOE_MAXIMUM_ERROR_COUNT
TicTacToe maximum errors count to determine whether the game is over.
static const std::string G_BATTLESHIPS_SHIP_PRESENT
Battleships board values.
static const uint32_t G_PAGE_MINIMUM_RIGHT_VERTICAL_LINE_SIZE
Minimum padding amounts.
static const uint32_t G_BATTLESHIPS_CARRIER_SIZE
Battleships ship-related constants used in later arrays.
static const uint32_t G_BATTLESHIPS_GRID_PLAYER_ONE_BOARD_LEFT_PAD
Battleships board attributes.
Colours
Colours representing ANSI escape codes.
@ BLUE
Supported ANSI escape colour.
@ YELLOW
Supported ANSI escape colour.
@ GREEN
Supported ANSI escape colour.
@ RED
Supported ANSI escape colour.
@ RESET
Supported ANSI escape colour.
@ WHITE
Supported ANSI escape colour.
static const std::string G_HANGMAN_WORD_SETTER
Hangman player choice options.
static const char G_PAGE_GRID_BOTTOM_LEFT
Extended ASCII characters for grids.
static const char G_PAGE_GRID_INTERSECTION
Extended ASCII characters for grids.
static const uint32_t G_TICTACTOE_GRID_ELEMENT_WIDTH
TicTacToe grid attributes.
static const std::string G_TICTACTOE_BOTTOM_TITLE
Page attributes for all TicTacToe pages.
static const uint32_t G_BATTLESHIPS_GRID_PLAYER_TWO_BOARD_LEFT_PAD
Battleships board attributes.
static const uint32_t G_GAME_TWO_OPTIONS
Used by multiple games or an attribute not specific to one game.
static const uint32_t G_HANGMAN_GALLOWS_BASE_WIDTH_HALF
Hangman constants used to construct the hangman.
static const std::string G_BATTLESHIPS_GRID_TOP_LINE_MIDDLE
Battleships board constants used to construct the board.
static const std::string G_BATTLESHIPS_EMPTY_GRID_VALUE
Battleships board values.
static const char G_PAGE_TOP_LEFT_CORNER
Extended ASCII characters for edges and corners of the page.
static const char G_PAGE_BOTTOM_LEFT_CORNER
Extended ASCII characters for edges and corners of the page.
static const uint32_t G_PAGE_MINIMUM_LEFT_PADDING_SIZE
Minimum padding amounts.
static const std::string G_BATTLESHIPS_PATROL_BOAT_PLACED_NAME
Battleships ship-related constants used in later arrays.
static const uint32_t G_HANGMAN_INCORRECT_GUESSES_FIRST_LINE_LAST_INDEX
Hangman constants used to construct the hangman.
static const std::string G_TICTACTOE_PLAYER_O
TicTacToe player choice options.
static const std::string G_HANGMAN_GALLOWS_TOP_BEAM
Hangman constants used to construct the hangman.
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_RESTART_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_GAME_THREE_OPTIONS
Used by multiple games or an attribute not specific to one game.
static const std::string G_BATTLESHIPS_SUBMARINE_PLACED_NAME
Battleships ship-related constants used in later arrays.
static const std::string G_PAGE_ANSI_RESET_COLOUR_ESCAPE_CODE
ANSI colour escape codes to add colour to output.
static const std::string G_MAIN_MENU_CLI_HELP_MESSAGE
CLI help message.
static const uint32_t G_TERMINAL_DOWN_ARROW_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_HANGMAN_DISPLAY_HEIGHT
Page attributes for all Hangman pages.
static const uint32_t G_TERMINAL_BACKSPACE_KEY
Keyboard values when getting user input on Windows.
static const std::string G_HANGMAN_GALLOWS_BASE_INITIAL
Hangman constants used to construct the hangman.
static const std::string G_BATTLESHIPS_GRID_TOP_LINE_TOP_LEFT
Battleships board constants used to construct the board.
static const uint32_t G_BATTLESHIPS_DISPLAY_HEIGHT
Page attributes for all Battleships pages.
static const uint32_t G_HANGMAN_NUMBER_OF_COMPUTER_WORDS
Hangman computer word list for when the computer is asked to chose a word to be guessed.
static const uint32_t G_HOMEPAGE_DISPLAY_HEIGHT
Page attributes for the homepage.
static const std::string G_PAGE_OPTION_SELECTOR_ABSENT_PADDING
For when highlighting what is currently selected in an option menu.
static const std::vector< std::string > G_GAME_MAX_ONE_PLAYER_OPTIONS
Used by multiple games or an attribute not specific to one game.
static const std::string G_HOMEPAGE_TOP_TITLE
Page attributes for the homepage.
static const uint32_t G_HOMEPAGE_DISPLAY_WIDTH
Page attributes for the homepage.
static const std::string G_BATTLESHIPS_SUBMARINE_NAME
Battleships ship-related constants used in later arrays.
static const char G_PAGE_GRID_RIGHT_SIDEWAYS_T
Extended ASCII characters for grids.
static const uint32_t G_TERMINAL_ALTERNATIVE_ENTER_KEY
Keyboard values when getting user input other platforms.
static const std::array< std::string, G_BATTLESHIPS_SHIP_COUNT > G_BATTLESHIPS_SHIP_NAMES
Battleships list of ship names.
static constexpr void RemoveSubString(std::string &p_string, const std::string &p_subString)
Removes in-place all instances of a p_subString from p_string .
static const uint32_t G_HANGMAN_MINIMUM_WORD_SIZE
Hangman word to be guessed constraints.
static constexpr int32_t ImplementStdCount(const T &p_begin, const T &p_end, const U &p_value)
Implements std::count which it should work for all standard template library containers.
static const std::string G_BATTLESHIPS_GRID_BOTTOM_LINE
Battleships board constants used to construct the board.
static const uint32_t G_PAGE_MINIMUM_LEFT_VERTICAL_LINE_SIZE
Minimum padding amounts.
static const char G_HANGMAN_HIDDEN_LETTER
Hangman constants used to construct the hangman.
static const std::array< std::string, G_BATTLESHIPS_SHIP_COUNT > G_BATTLESHIPS_SHIP_INSTRUCTIONS
Battleships list of instructions use when asking the user for the grid locations for their ships.
static const std::string G_HANGMAN_GALLOWS_TOP_BEAM_INITIAL
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 char G_PAGE_TOP_RIGHT_CORNER
Extended ASCII characters for edges and corners of the page.
static const std::array< uint32_t, G_BATTLESHIPS_SHIP_COUNT > G_BATTLESHIPS_SHIP_SIZES
Battleships list of ship sizes.
static const uint32_t G_BATTLESHIPS_BOARD_HEIGHT
Battleships board attributes.
static const uint32_t G_TICTACTOE_GRID_HEIGHT
TicTacToe grid attributes.
static const uint32_t G_HANGMAN_INCORRECT_GUESSES_SECOND_LINE_LAST_INDEX
Hangman constants used to construct the hangman.
static const std::string G_BATTLESHIPS_CARRIER_PLACED_NAME
Battleships ship-related constants used in later arrays.
static const char G_PAGE_GRID_BOTTOM_RIGHT
Extended ASCII characters for grids.
static const std::string G_GAME_UNKNOWN_OPTION
Used by multiple games or an attribute not specific to one game.
static const std::string G_BATTLESHIPS_CARRIER_NAME
Battleships ship-related constants used in later arrays.