8#include "helpers/GameInformation.hpp"
9#include "helpers/Globals.hpp"
11#include "helpers/PageBuilder.hpp"
154 return {
"The 'GetPlayerCountOptionSelectionGameDisplays' function does not support the current page type."};
169 return {
"The 'GetUserPlayerChoiceOptionSelectionGameDisplays' function does not support the current page type."};
183 return {
"The 'GetComputerSpeedOptionSelectionGameDisplays' function does not support the current page type."};
192 return COMMON_TOP_STRING +
GetRemainingEmptyLines(COMMON_TOP_STRING, COMMON_BOTTOM_STRING) + COMMON_BOTTOM_STRING;
209 return "The 'GetUserCommandGameDisplay' function does not support the current page type.";
220 return GetPageWithMessage(p_gameInformation,
"The computer is executing their next move!");
223 return "The 'GetComputerSpeedOptionSelectionGameDisplays' function does not support the current page type.";
263 return "The 'GetGameOverGameDisplay' function does not support the current page type.";
288 std::string output = p_input;
310 static const double DIVISOR = 2;
314 const std::string INPUT_WITH_SELECTOR = p_selector.empty() ? p_input : p_selector +
' ' + p_input;
324 const uint32_t LEFT_PADDING_SIZE =
static_cast<uint32_t
>(ceil(
static_cast<double>(
m_lineMaximumCharacterCount - (INPUT_TRIMMED_SIZE - SELECTOR_SIZE)) / DIVISOR) - SELECTOR_SIZE);
325 const uint32_t RIGHT_PADDING_SIZE =
static_cast<uint32_t
>(floor(
static_cast<double>(
m_lineMaximumCharacterCount - (INPUT_TRIMMED_SIZE - SELECTOR_SIZE)) / DIVISOR));
332 output +=
AddColour(INPUT_TRIMMED, p_colour);
339 static const double DIVISOR = 2;
341 const uint32_t LEFT_PADDING_SIZE =
static_cast<uint32_t
>(ceil(
static_cast<double>(
m_lineMaximumCharacterCount - p_input.size()) / DIVISOR));
342 const uint32_t RIGHT_PADDING_SIZE =
static_cast<uint32_t
>(floor(
static_cast<double>(
m_lineMaximumCharacterCount - p_input.size()) / DIVISOR));
358 const std::string INPUT = p_selector.empty() ? p_input : p_selector +
' ' + p_input;
421 const uint32_t EMPTY_LINES_TO_ADD_COUNT = REMAINING_LINE_COUNT < 0 ? 0 : REMAINING_LINE_COUNT;
424 output.reserve(
m_pageWidth * EMPTY_LINES_TO_ADD_COUNT);
425 for (uint32_t emptyLineCount = 0; emptyLineCount < EMPTY_LINES_TO_ADD_COUNT; emptyLineCount++)
434 const std::vector<std::string>& p_options,
435 const std::string& p_commonTopString,
436 const std::string& p_commonBottomString,
437 const bool& p_addEmptyLineBetweenOptions,
438 const bool& p_centerOptionsHorizontally,
439 const bool& p_centerOptionsVertically)
const
441 const double DIVISOR = 2;
442 const uint32_t EMPTY_LINES_BEFORE_OPTIONS =
static_cast<uint32_t
>(floor(
static_cast<double>(
m_pageHeight -
Globals::ImplementStdCount(p_commonTopString.begin(), p_commonTopString.end(),
'\n') -
Globals::ImplementStdCount(p_commonBottomString.begin(), p_commonBottomString.end(),
'\n') - (2 * p_options.size() - 1)) / DIVISOR));
443 const uint32_t EMPTY_LINES_AFTER_OPTIONS =
static_cast<uint32_t
>(ceil(
static_cast<double>(
m_pageHeight -
Globals::ImplementStdCount(p_commonTopString.begin(), p_commonTopString.end(),
'\n') -
Globals::ImplementStdCount(p_commonBottomString.begin(), p_commonBottomString.end(),
'\n') - (2 * p_options.size() - 1)) / DIVISOR));
445 std::vector<std::string> output(p_options.size());
448 for (uint32_t currentOptionSelected = 0; currentOptionSelected < p_options.size(); currentOptionSelected++)
450 std::string currentTopString = p_commonTopString;
452 if (p_centerOptionsVertically)
454 for (uint32_t emptyLineCount = 0; emptyLineCount < EMPTY_LINES_BEFORE_OPTIONS; emptyLineCount++)
460 for (uint32_t currentOption = 0; currentOption < p_options.size(); currentOption++)
462 if (currentOption == currentOptionSelected)
464 if (p_centerOptionsHorizontally)
475 else if (p_centerOptionsHorizontally)
485 if (p_addEmptyLineBetweenOptions)
487 if (currentOption != p_options.size() - 1)
494 if (p_centerOptionsVertically)
496 output[currentOptionSelected] = currentTopString;
498 for (uint32_t emptyLineCount = 0; emptyLineCount < EMPTY_LINES_AFTER_OPTIONS; emptyLineCount++)
503 output[currentOptionSelected] += p_commonBottomString;
508 output[currentOptionSelected] = currentTopString;
510 output[currentOptionSelected] += p_commonBottomString;
539 return "The 'GetGeneralGameDisplay' function does not support the current page type.";
547 const uint32_t LEFT_GRID_SIZE = 11;
548 const uint32_t RIGHT_GRID_SIZE = 40;
549 const uint32_t GRID_HEIGHT = 5;
552 std::vector<std::string> leftGridLines;
555 std::string currentRow;
556 std::string currentRowDivider;
557 currentRow.reserve(LEFT_GRID_SIZE);
558 currentRowDivider.reserve(LEFT_GRID_SIZE);
573 leftGridLines.emplace_back(currentRow);
574 leftGridLines.emplace_back(currentRowDivider);
578 const std::vector<std::string> RIGHT_GRID_LINES = {
586 return GetGridLayout({LEFT_GRID_SIZE, RIGHT_GRID_SIZE}, {leftGridLines, RIGHT_GRID_LINES}, GRID_HEIGHT);
593 const uint32_t LEFT_GRID_SIZE = 13;
594 const uint32_t MIDDLE_GRID_SIZE = 24;
595 const uint32_t RIGHT_GRID_SIZE = 17;
596 const uint32_t GRID_HEIGHT = 7;
602 const std::vector<std::string> MIDDLE_GRID_LINES = {
613 std::vector<std::string> rightGridLines;
614 std::string currentLine;
615 currentLine.reserve(RIGHT_GRID_SIZE);
617 rightGridLines.emplace_back(
"");
632 rightGridLines.emplace_back(currentLine);
633 rightGridLines.emplace_back(
"");
638 if (!currentLine.empty())
640 rightGridLines.emplace_back(currentLine);
644 const uint32_t REMAINING_LINES_TO_ADD = GRID_HEIGHT - rightGridLines.size();
645 for (uint32_t emptyLineCount = 0; emptyLineCount < REMAINING_LINES_TO_ADD; emptyLineCount++)
647 rightGridLines.emplace_back(
"");
650 std::string output =
GetGridLayout({LEFT_GRID_SIZE, MIDDLE_GRID_SIZE, RIGHT_GRID_SIZE}, {leftGridLines, MIDDLE_GRID_LINES, rightGridLines}, GRID_HEIGHT);
653 std::string currentGuessOfWord;
657 currentGuessOfWord += letter;
658 currentGuessOfWord +=
' ';
678 const uint32_t LEFT_GRID_SIZE = 45;
679 const uint32_t MIDDLE_GRID_SIZE = 44;
680 const uint32_t RIGHT_GRID_SIZE = 45;
681 const uint32_t GRID_HEIGHT = 24;
683 const std::string SINGLE_SPACE(1,
' ');
685 std::string commonGridAlphabetAxis;
686 commonGridAlphabetAxis.reserve(LEFT_GRID_SIZE);
694 commonGridAlphabetAxis += SINGLE_SPACE;
695 commonGridAlphabetAxis +=
static_cast<char>(currentLetter);
696 commonGridAlphabetAxis += SINGLE_SPACE;
707 std::string currentLeftGridValueLine;
708 currentLeftGridValueLine.reserve(LEFT_GRID_SIZE);
710 currentLeftGridValueLine += SINGLE_SPACE;
711 currentLeftGridValueLine += std::to_string(row);
712 currentLeftGridValueLine += SINGLE_SPACE;
714 std::string currentRightGridValueLine = currentLeftGridValueLine;
738 leftGridLines.emplace_back(currentLeftGridValueLine);
739 rightGridLines.emplace_back(currentRightGridValueLine);
755 std::vector<std::string> middleGridLines = {
769 std::string currentShipHealthLine;
770 currentShipHealthLine.reserve(MIDDLE_GRID_SIZE);
788 currentShipHealthLine += SINGLE_SPACE;
792 std::string currentShipHealthTitle;
793 currentShipHealthTitle.reserve(MIDDLE_GRID_SIZE);
817 currentShipHealthLine += SINGLE_SPACE;
828 middleGridLines.emplace_back(currentShipHealthTitle);
829 middleGridLines.emplace_back(currentShipHealthLine);
830 middleGridLines.emplace_back(
"");
833 return GetGridLayout({LEFT_GRID_SIZE, MIDDLE_GRID_SIZE, RIGHT_GRID_SIZE}, {leftGridLines, middleGridLines, rightGridLines}, GRID_HEIGHT);
836 std::string
PageBuilder::GetGridLayout(
const std::vector<uint32_t>& p_gridColumnWidths,
const std::vector<std::vector<std::string>>& p_gridColumnLines,
const uint32_t& p_gridColumnHeight)
847 for (uint32_t currentLineNumber = 0; currentLineNumber < p_gridColumnHeight; currentLineNumber++)
849 std::string currentLine;
852 for (uint32_t currentGridSize = 0; currentGridSize < p_gridColumnWidths.size(); currentGridSize++)
860 std::erase(currentLine,
'\n');
864 output += currentLine;
Used for functionality that has not been implemented.
std::string GetGeneralGameSubPage(const GameInformation &p_gameInformation)
Wrapper function around the game specific game sub-page functions.
std::string GetNewLineCentredOptimised(const std::string &p_input) const
Creates a new line on a page with p_input automatically centred. If the spacing on the sides is unequ...
std::string GetGridLayout(const std::vector< uint32_t > &p_gridColumnWidths, const std::vector< std::vector< std::string > > &p_gridColumnLines, const uint32_t &p_gridColumnHeight)
Calculates a grid layout based on the grid content in p_gridColumnLines and the grid sizes in p_gridC...
void SetProperties(const Pages &p_page, const bool &p_useAnsiEscapeCodes)
Set the properties of the PageBuilder object.
std::string GetPageWithMessage(const GameInformation &p_gameInformation, const std::string &p_message)
Creates a general game page with a custom message to display on the page.
std::string GetTopBox() const
Creates the top box display which acts as the title bar for a page.
std::vector< std::string > GetGameSelectionMainMenuPages(const std::vector< std::string > &p_gameNames) const
Creates the pages for displaying the main menu game selection page.
std::string GetEmptyLine() const
Creates a new line on a page but with no input text.
std::vector< std::string > GetOptionSelectionHomepages()
Creates the pages for displaying the option selection home page.
static std::string RemoveColour(const std::string &p_input)
Removes colour from the input text by removing all ANSI colour escape codes.
Pages m_currentPage
The current page type to build for.
uint32_t m_lineMaximumCharacterCount
The maximum number of characters (excluding page edge and padding characters) that can exist within a...
std::string GetTopLine() const
Creates the top line of a box within a page.
uint32_t m_pageHeight
The page height in terms of the total number of lines (inclusive of the page edge lines).
std::string GetComputerCommandPage(const GameInformation &p_gameInformation)
Creates the computer command page for when the computer is entering their command.
std::string GetBottomBox() const
Creates the bottom box which acts as the footer for a page.
uint32_t m_minimumRightPadding
The minimum amount of padding between the edge characters of the page and the inner content.
std::string GetNewLineLeftJustified(const std::string &p_input, const Globals::Colours &p_colour=Globals::Colours::WHITE, const std::string &p_selector="") const
Creates a new line on a page with p_input automatically left justified (with one space padding on to ...
std::string GetBattleshipsSubPage(const GameInformation &p_gameInformation)
Creates the sub-page containing the current state of the Battleships game.
std::string GetBottomLine() const
Creates the bottom line of a box within a page.
std::vector< std::string > GetGeneralOptionSelectionPages(const std::vector< std::string > &p_options, const std::string &p_commonTopString, const std::string &p_commonBottomString, const bool &p_addEmptyLineBetweenOptions, const bool &p_centerOptionsHorizontally, const bool &p_centerOptionsVertically) const
Creates the pages for displaying the option selection page for the given options.
std::string m_topTitle
The text to display in the top box which acts as the title bar within a page.
std::string m_bottomTitle
The text to display in the bottom box which acts as a footer of a page.
std::string GetHangmanSubPage(const GameInformation &p_gameInformation)
Creates the sub-page containing the current state of the Hangman game.
std::string GetGameOverPage(const GameInformation &p_gameInformation)
Creates the game over page.
std::vector< std::string > GetUserPlayerChoiceOptionSelectionGamePages(const GameInformation &p_gameInformation)
Creates the pages for displaying the user player choice for a game option selection page.
std::string AddColour(const std::string &p_input, const Globals::Colours &p_colour) const
Sets the colour of p_input using ANSI escape codes.
std::string GetNewLineCentred(const std::string &p_input, const Globals::Colours &p_colour=Globals::Colours::WHITE, const std::string &p_selector="") const
Creates a new line on a page with p_input automatically centred. If the spacing on the sides is unequ...
std::vector< std::string > GetQuitOptionSelectionPage() const
Creates the quit option selection page.
std::vector< std::string > GetPlayerCountOptionSelectionGamePages(const GameInformation &p_gameInformation)
Creates the pages for displaying the number of players playing the game option selection page.
std::string GetTicTacToeSubPage(const GameInformation &p_gameInformation)
Creates the sub-page containing the current state of the TicTacToe game.
Pages GetCurrentPageType() const
Get the current page type.
std::string GetRemainingEmptyLines(const std::string &p_commonTopString, const std::string &p_commonBottomString) const
Used to pad a page vertically with empty lines.
uint32_t m_minimumLeftPadding
The minimum amount of padding between the edge characters of the page and the inner content.
std::vector< std::string > GetGameOptionSelectionPages(const GameInformation &p_gameInformation, const std::string &p_message, const std::vector< std::string > &p_options)
Creates the pages for displaying the option selection page for the given options within a game page.
std::vector< std::string > GetComputerSpeedOptionSelectionGamePages(const GameInformation &p_gameInformation)
Creates the pages for displaying the computer speed for a game option selection page.
uint32_t m_pageWidth
The page width in terms of the total number of characters (inclusive of the page edge characters) per...
std::string GetUserCommandPage(const GameInformation &p_gameInformation)
Creates the game user command page which should prompt the user to enter a command.
bool m_useAnsiEscapeCodes
Whether to use use ANSI escapes codes (true) or only extended ASCII characters (false).
PageBuilder()
Constructs a new default PageBuilder object.
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 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_TICTACTOE_TOP_TITLE
Page attributes for all TicTacToe pages.
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 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 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 std::string G_BATTLESHIPS_SUCCESSFUL_ATTACK
Battleships board values.
static const std::string G_HANGMAN_WORD_TO_BE_GUESSED_END
Hangman constants used to construct the hangman.
static const std::string G_HANGMAN_WORD_TO_BE_GUESSED_START
Hangman constants used to construct the hangman.
static const std::string G_HOMEPAGE_BOTTOM_TITLE
Page attributes for the homepage.
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 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 char G_PAGE_GRID_VERTICAL_LINE
Extended ASCII characters for grids.
static const std::string G_BATTLESHIPS_BOTTOM_TITLE
Page attributes for all Battleships pages.
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::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 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 uint32_t G_MAIN_MENU_DISPLAY_WIDTH
Page attributes for the MainMenu page.
static const std::string G_BATTLESHIPS_GRID_TOP_LINE
Battleships board constants used to construct the board.
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_BATTLESHIPS_GRID_ELEMENT_WIDTH
Battleships board attributes.
static const char G_PAGE_HORIZONTAL_LINE
Extended ASCII characters for edges and corners of the page.
static const std::string G_HANGMAN_INCORRECT_GUESSES_TITLE
Hangman constants used to construct the hangman.
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 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_MAIN_MENU_TOP_TITLE
Page attributes for the MainMenu page.
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.
Colours
Colours representing ANSI escape codes.
@ BLUE
Supported ANSI escape colour.
@ GREEN
Supported ANSI escape colour.
@ RED
Supported ANSI escape colour.
static const char G_PAGE_GRID_INTERSECTION
Extended ASCII characters for grids.
static const std::string G_TICTACTOE_BOTTOM_TITLE
Page attributes for all TicTacToe pages.
static const uint32_t G_GAME_TWO_OPTIONS
Used by multiple games or an attribute not specific to one game.
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 uint32_t G_HANGMAN_INCORRECT_GUESSES_FIRST_LINE_LAST_INDEX
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 std::string G_PAGE_ANSI_RESET_COLOUR_ESCAPE_CODE
ANSI colour escape codes to add colour to output.
static const uint32_t G_HANGMAN_DISPLAY_HEIGHT
Page attributes for all Hangman pages.
static const uint32_t G_BATTLESHIPS_DISPLAY_HEIGHT
Page attributes for all Battleships pages.
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::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 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_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_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.
Contains all Terminal-Games objects.
Pages
Represents the page types that are supported by PageBuilder.
@ MAINMENU
Page supported by PageBuilder.
@ HOMEPAGE
Page supported by PageBuilder.
@ DEFAULT
Page supported by PageBuilder.
@ TICTACTOE
Page supported by PageBuilder.
@ HANGMAN
Page supported by PageBuilder.
@ BATTLESHIPS
Page supported by PageBuilder.