Terminal Games
Simple games that run in the terminal.
|
Builds pages (i.e. strings) to be printed to the terminal. More...
#include "PageBuilder.hpp"
Public Member Functions | |
PageBuilder () | |
Constructs a new default PageBuilder object. | |
PageBuilder (const Pages &p_page, const bool &p_useAnsiEscapeCodes) | |
Constructs a new custom PageBuilder object. | |
void | SetProperties (const Pages &p_page, const bool &p_useAnsiEscapeCodes) |
Set the properties of the PageBuilder object. | |
Pages | GetCurrentPageType () const |
Get the current page type. | |
std::vector< std::string > | GetOptionSelectionHomepages () |
Creates the pages for displaying the option selection home 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::vector< std::string > | GetPlayerCountOptionSelectionGamePages (const GameInformation &p_gameInformation) |
Creates the pages for displaying the number of players playing the game option selection 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::vector< std::string > | GetComputerSpeedOptionSelectionGamePages (const GameInformation &p_gameInformation) |
Creates the pages for displaying the computer speed for a game option selection page. | |
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 | GetUserCommandPage (const GameInformation &p_gameInformation) |
Creates the game user command page which should prompt the user to enter a command. | |
std::string | GetComputerCommandPage (const GameInformation &p_gameInformation) |
Creates the computer command page for when the computer is entering their command. | |
std::string | GetGameOverPage (const GameInformation &p_gameInformation) |
Creates the game over page. | |
std::vector< std::string > | GetQuitOptionSelectionPage () const |
Creates the quit option selection page. |
Private Member Functions | |
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 | GetEmptyLine () const |
Creates a new line on a page but with no input text. | |
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 unequal, the left side will always have the higher amount of spacing. With an optional parameters of p_colour to colour the input text and p_selector used when creating option selection pages. | |
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 unequal, the left side will always have the higher amount of spacing. This is a simplified more performant version of GetNewLineCentred. | |
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 the left page edge). With an optional parameters of p_colour to colour the input text and p_selector used when creating option selection pages. | |
std::string | GetTopLine () const |
Creates the top line of a box within a page. | |
std::string | GetBottomLine () const |
Creates the bottom line of a box within a page. | |
std::string | GetTopBox () const |
Creates the top box display which acts as the title bar for a page. | |
std::string | GetBottomBox () const |
Creates the bottom box which acts as the footer for a page. | |
std::string | GetRemainingEmptyLines (const std::string &p_commonTopString, const std::string &p_commonBottomString) const |
Used to pad a page vertically with empty lines. | |
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::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::string | GetGeneralGameSubPage (const GameInformation &p_gameInformation) |
Wrapper function around the game specific game sub-page functions. | |
std::string | GetTicTacToeSubPage (const GameInformation &p_gameInformation) |
Creates the sub-page containing the current state of the TicTacToe game. | |
std::string | GetHangmanSubPage (const GameInformation &p_gameInformation) |
Creates the sub-page containing the current state of the Hangman game. | |
std::string | GetBattleshipsSubPage (const GameInformation &p_gameInformation) |
Creates the sub-page containing the current state of the Battleships game. | |
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_gridColumnWidths. Only columns can be defined and all content is centred within its grid column. This is used by the game sub-page functions to simplify their code. |
Static Private Member Functions | |
static std::string | RemoveColour (const std::string &p_input) |
Removes colour from the input text by removing all ANSI colour escape codes. |
Private Attributes | |
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. | |
uint32_t | m_pageWidth |
The page width in terms of the total number of characters (inclusive of the page edge characters) per line. | |
uint32_t | m_pageHeight |
The page height in terms of the total number of lines (inclusive of the page edge lines). | |
uint32_t | m_lineMaximumCharacterCount |
The maximum number of characters (excluding page edge and padding characters) that can exist within a line. | |
Pages | m_currentPage |
The current page type to build for. | |
bool | m_useAnsiEscapeCodes |
Whether to use use ANSI escapes codes (true) or only extended ASCII characters (false). | |
uint32_t | m_minimumLeftPadding |
The minimum amount of padding between the edge characters of the page and the inner content. | |
uint32_t | m_minimumRightPadding |
The minimum amount of padding between the edge characters of the page and the inner content. |
Builds pages (i.e. strings) to be printed to the terminal.
Definition at line 38 of file PageBuilder.hpp.
|
explicit |
Constructs a new default PageBuilder object.
Definition at line 15 of file PageBuilder.cpp.
|
explicit |
Constructs a new custom PageBuilder object.
p_page | Which page type to configure the PageBuilder for. |
p_useAnsiEscapeCodes | Whether to use use ANSI escapes codes (true) or only extended ASCII characters (false). |
Globals::Exceptions::NotImplementedError | When passed a Pages value that is not supported. |
Definition at line 24 of file PageBuilder.cpp.
void TerminalGames::PageBuilder::SetProperties | ( | const Pages & | p_page, |
const bool & | p_useAnsiEscapeCodes ) |
Set the properties of the PageBuilder object.
p_page | Which page type to configure the PageBuilder for. |
p_useAnsiEscapeCodes | Whether to use use ANSI escapes codes (true) or only extended ASCII characters (false). |
Globals::Exceptions::NotImplementedError | When passed a Pages value that is not supported. |
Definition at line 36 of file PageBuilder.cpp.
Pages TerminalGames::PageBuilder::GetCurrentPageType | ( | ) | const |
Get the current page type.
Definition at line 87 of file PageBuilder.cpp.
std::vector< std::string > TerminalGames::PageBuilder::GetOptionSelectionHomepages | ( | ) |
Creates the pages for displaying the option selection home page.
Definition at line 92 of file PageBuilder.cpp.
std::vector< std::string > TerminalGames::PageBuilder::GetGameSelectionMainMenuPages | ( | const std::vector< std::string > & | p_gameNames | ) | const |
Creates the pages for displaying the main menu game selection page.
p_gameNames | The name of the games that can be selected. |
Definition at line 134 of file PageBuilder.cpp.
std::vector< std::string > TerminalGames::PageBuilder::GetPlayerCountOptionSelectionGamePages | ( | const GameInformation & | p_gameInformation | ) |
Creates the pages for displaying the number of players playing the game option selection page.
p_gameInformation | Information on the current state of the current game. |
Definition at line 142 of file PageBuilder.cpp.
std::vector< std::string > TerminalGames::PageBuilder::GetUserPlayerChoiceOptionSelectionGamePages | ( | const GameInformation & | p_gameInformation | ) |
Creates the pages for displaying the user player choice for a game option selection page.
p_gameInformation | Information on the current state of the current game. |
Definition at line 158 of file PageBuilder.cpp.
std::vector< std::string > TerminalGames::PageBuilder::GetComputerSpeedOptionSelectionGamePages | ( | const GameInformation & | p_gameInformation | ) |
Creates the pages for displaying the computer speed for a game option selection page.
p_gameInformation | Information on the current state of the current game. |
Definition at line 173 of file PageBuilder.cpp.
std::string TerminalGames::PageBuilder::GetPageWithMessage | ( | const GameInformation & | p_gameInformation, |
const std::string & | p_message ) |
Creates a general game page with a custom message to display on the page.
p_gameInformation | Information on the current state of the current game. |
p_message | The custom message to display. |
Definition at line 187 of file PageBuilder.cpp.
std::string TerminalGames::PageBuilder::GetUserCommandPage | ( | const GameInformation & | p_gameInformation | ) |
Creates the game user command page which should prompt the user to enter a command.
p_gameInformation | Information on the current state of the current game. |
Definition at line 195 of file PageBuilder.cpp.
std::string TerminalGames::PageBuilder::GetComputerCommandPage | ( | const GameInformation & | p_gameInformation | ) |
Creates the computer command page for when the computer is entering their command.
p_gameInformation | Information on the current state of the current game. |
Definition at line 213 of file PageBuilder.cpp.
std::string TerminalGames::PageBuilder::GetGameOverPage | ( | const GameInformation & | p_gameInformation | ) |
Creates the game over page.
p_gameInformation | Information on the current state of the current game. |
Definition at line 227 of file PageBuilder.cpp.
std::vector< std::string > TerminalGames::PageBuilder::GetQuitOptionSelectionPage | ( | ) | const |
Creates the quit option selection page.
Definition at line 269 of file PageBuilder.cpp.
|
private |
Sets the colour of p_input using ANSI escape codes.
p_input | The input text to be coloured. |
p_colour | The colour of the input text. |
Definition at line 276 of file PageBuilder.cpp.
|
staticprivate |
Removes colour from the input text by removing all ANSI colour escape codes.
p_input | The input text to be un-coloured. |
Definition at line 286 of file PageBuilder.cpp.
|
private |
Creates a new line on a page but with no input text.
Definition at line 298 of file PageBuilder.cpp.
|
private |
Creates a new line on a page with p_input automatically centred. If the spacing on the sides is unequal, the left side will always have the higher amount of spacing. With an optional parameters of p_colour to colour the input text and p_selector used when creating option selection pages.
p_input | The text to display on the new line. |
p_colour | The colour of the input text. |
p_selector | An identifier to show the line is selected. |
Definition at line 308 of file PageBuilder.cpp.
|
private |
Creates a new line on a page with p_input automatically centred. If the spacing on the sides is unequal, the left side will always have the higher amount of spacing. This is a simplified more performant version of GetNewLineCentred.
p_input | The text to display on the new line. |
Definition at line 337 of file PageBuilder.cpp.
|
private |
Creates a new line on a page with p_input automatically left justified (with one space padding on to the left page edge). With an optional parameters of p_colour to colour the input text and p_selector used when creating option selection pages.
p_input | The text to display on the new line. |
p_colour | The colour of the input text. |
p_selector | An identifier to show the line is selected. |
Definition at line 356 of file PageBuilder.cpp.
|
private |
Creates the top line of a box within a page.
Definition at line 386 of file PageBuilder.cpp.
|
private |
Creates the bottom line of a box within a page.
Definition at line 396 of file PageBuilder.cpp.
|
private |
Creates the top box display which acts as the title bar for a page.
Definition at line 406 of file PageBuilder.cpp.
|
private |
Creates the bottom box which acts as the footer for a page.
Definition at line 411 of file PageBuilder.cpp.
|
private |
Used to pad a page vertically with empty lines.
p_commonTopString | The part of the page above where the empty lines are to be padded. |
p_commonBottomString | The part of the page below where the empty lines are to be padded. |
Definition at line 418 of file PageBuilder.cpp.
|
private |
Creates the pages for displaying the option selection page for the given options.
p_options | The options for the option selection page |
p_commonTopString | The common string between all pages found above the options. |
p_commonBottomString | The common string between all pages found below the options. |
p_addEmptyLineBetweenOptions | Whether to add an empty line between the options (true) or not (false). |
p_centerOptionsHorizontally | Whether to center the options horizontally (true) or left justify them (false). |
p_centerOptionsVertically | Whether to center the options vertically (true) or left justify them (false). |
Definition at line 433 of file PageBuilder.cpp.
|
private |
Creates the pages for displaying the option selection page for the given options within a game page.
p_gameInformation | Information on the current state of the current game. |
p_message | The custom message to display. |
p_options | The selectable options to display. |
Definition at line 517 of file PageBuilder.cpp.
|
private |
Wrapper function around the game specific game sub-page functions.
p_gameInformation | Information on the current state of the current game. |
Definition at line 525 of file PageBuilder.cpp.
|
private |
Creates the sub-page containing the current state of the TicTacToe game.
p_gameInformation | Information on the current state of the current game. |
Definition at line 543 of file PageBuilder.cpp.
|
private |
Creates the sub-page containing the current state of the Hangman game.
p_gameInformation | Information on the current state of the current game. |
Definition at line 589 of file PageBuilder.cpp.
|
private |
Creates the sub-page containing the current state of the Battleships game.
p_gameInformation | Information on the current state of the current game. |
Definition at line 674 of file PageBuilder.cpp.
|
private |
Calculates a grid layout based on the grid content in p_gridColumnLines and the grid sizes in p_gridColumnWidths. Only columns can be defined and all content is centred within its grid column. This is used by the game sub-page functions to simplify their code.
p_gridColumnWidths | The width of each grid column. |
p_gridColumnLines | The content of each grid column where each grid column is an element in p_gridColumnLines. |
p_gridColumnHeight | The height of the grid columns (i.e. the number of lines within each grid column). Note that this must be the same for all grid columns. |
Definition at line 836 of file PageBuilder.cpp.
|
private |
The text to display in the top box which acts as the title bar within a page.
Definition at line 338 of file PageBuilder.hpp.
|
private |
The text to display in the bottom box which acts as a footer of a page.
Definition at line 343 of file PageBuilder.hpp.
|
private |
The page width in terms of the total number of characters (inclusive of the page edge characters) per line.
Definition at line 348 of file PageBuilder.hpp.
|
private |
The page height in terms of the total number of lines (inclusive of the page edge lines).
Definition at line 353 of file PageBuilder.hpp.
|
private |
The maximum number of characters (excluding page edge and padding characters) that can exist within a line.
Definition at line 358 of file PageBuilder.hpp.
|
private |
The minimum amount of padding between the edge characters of the page and the inner content.
Definition at line 364 of file PageBuilder.hpp.
|
private |
The minimum amount of padding between the edge characters of the page and the inner content.
Definition at line 365 of file PageBuilder.hpp.
|
private |
The current page type to build for.
Definition at line 371 of file PageBuilder.hpp.
|
private |
Whether to use use ANSI escapes codes (true) or only extended ASCII characters (false).
Definition at line 376 of file PageBuilder.hpp.