Terminal Games
Simple games that run in the terminal.
Loading...
Searching...
No Matches
PageBuilder.hpp
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <vector>
6
7#include "helpers/GameInformation.hpp"
8#include "helpers/Globals.hpp"
9
14namespace TerminalGames
15{
19 enum class Pages : std::uint8_t
20 {
32 };
33
39 {
40 public:
44 explicit PageBuilder();
45
53 explicit PageBuilder(const Pages& p_page, const bool& p_useAnsiEscapeCodes);
54
62 void SetProperties(const Pages& p_page, const bool& p_useAnsiEscapeCodes);
63
70
76 std::vector<std::string> GetOptionSelectionHomepages();
77
84 std::vector<std::string> GetGameSelectionMainMenuPages(const std::vector<std::string>& p_gameNames) const;
85
92 std::vector<std::string> GetPlayerCountOptionSelectionGamePages(const GameInformation& p_gameInformation);
93
100 std::vector<std::string> GetUserPlayerChoiceOptionSelectionGamePages(const GameInformation& p_gameInformation);
101
108 std::vector<std::string> GetComputerSpeedOptionSelectionGamePages(const GameInformation& p_gameInformation);
109
118 std::string GetPageWithMessage(const GameInformation& p_gameInformation, const std::string& p_message);
119
126 std::string GetUserCommandPage(const GameInformation& p_gameInformation);
127
135 std::string GetComputerCommandPage(const GameInformation& p_gameInformation);
136
144 std::string GetGameOverPage(const GameInformation& p_gameInformation);
145
151 std::vector<std::string> GetQuitOptionSelectionPage() const;
152
153 private:
161 std::string AddColour(const std::string& p_input, const Globals::Colours& p_colour) const;
162
169 static std::string RemoveColour(const std::string& p_input);
170
176 std::string GetEmptyLine() const;
177
190 std::string GetNewLineCentred(const std::string& p_input, const Globals::Colours& p_colour = Globals::Colours::WHITE, const std::string& p_selector = "") const;
191
202 std::string GetNewLineCentredOptimised(const std::string& p_input) const;
203
216 std::string GetNewLineLeftJustified(const std::string& p_input, const Globals::Colours& p_colour = Globals::Colours::WHITE, const std::string& p_selector = "") const;
217
223 std::string GetTopLine() const;
224
230 std::string GetBottomLine() const;
231
237 std::string GetTopBox() const;
238
244 std::string GetBottomBox() const;
245
253 std::string GetRemainingEmptyLines(const std::string& p_commonTopString, const std::string& p_commonBottomString) const;
254
266 std::vector<std::string> GetGeneralOptionSelectionPages(
267 const std::vector<std::string>& p_options,
268 const std::string& p_commonTopString,
269 const std::string& p_commonBottomString,
270 const bool& p_addEmptyLineBetweenOptions,
271 const bool& p_centerOptionsHorizontally,
272 const bool& p_centerOptionsVertically) const;
273
285 std::vector<std::string> GetGameOptionSelectionPages(const GameInformation& p_gameInformation, const std::string& p_message, const std::vector<std::string>& p_options);
286
293 std::string GetGeneralGameSubPage(const GameInformation& p_gameInformation);
294
301 std::string GetTicTacToeSubPage(const GameInformation& p_gameInformation);
302
309 std::string GetHangmanSubPage(const GameInformation& p_gameInformation);
310
317 std::string GetBattleshipsSubPage(const GameInformation& p_gameInformation);
318
333 std::string GetGridLayout(const std::vector<uint32_t>& p_gridColumnWidths, const std::vector<std::vector<std::string>>& p_gridColumnLines, const uint32_t& p_gridColumnHeight);
334
338 std::string m_topTitle;
339
343 std::string m_bottomTitle;
344
348 uint32_t m_pageWidth;
349
353 uint32_t m_pageHeight;
354
359
367
372
377 };
378}
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.
Colours
Colours representing ANSI escape codes.
Definition Globals.hpp:261
@ WHITE
Supported ANSI escape colour.
Definition Globals.hpp:266
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.
Used by game objects to package themselves into a format that can be used by PageBuilder to construct...