Terminal Games
Simple games that run in the terminal.
Loading...
Searching...
No Matches
PageBuilder.cpp
1#include <algorithm>
2#include <array>
3#include <cmath>
4#include <cstdint>
5#include <string>
6#include <vector>
7
8#include "helpers/GameInformation.hpp"
9#include "helpers/Globals.hpp"
10
11#include "helpers/PageBuilder.hpp"
12
13namespace TerminalGames
14{
23
24 PageBuilder::PageBuilder(const Pages& p_page, const bool& p_useAnsiEscapeCodes) :
25 m_pageWidth(0),
26 m_pageHeight(0),
32 {
33 SetProperties(p_page, p_useAnsiEscapeCodes);
34 }
35
36 void PageBuilder::SetProperties(const Pages& p_page, const bool& p_useAnsiEscapeCodes)
37 {
38 m_currentPage = p_page;
39 m_useAnsiEscapeCodes = p_useAnsiEscapeCodes;
40
41 switch (m_currentPage)
42 {
43 case Pages::HOMEPAGE:
48 break;
49
50 case Pages::MAINMENU:
55 break;
56
62 break;
63
64 case Pages::HANGMAN:
69 break;
70
76 break;
77
78 default:
80 }
81
85 }
86
91
93 {
94 std::vector<std::string> output(Globals::G_GAME_TWO_OPTIONS);
95
96 const bool OLD_USE_ANSI_ESCAPE_CODES = m_useAnsiEscapeCodes;
98
100 {
101 const std::string COMMON_TOP_STRING = GetTopBox() + GetTopLine() +
102 GetNewLineCentred("Platform: " + AddColour("Windows", Globals::Colours::GREEN)) + GetEmptyLine() +
103 GetNewLineCentred("Controls: " + AddColour("Enhanced", Globals::Colours::GREEN)) + GetEmptyLine() +
104 GetNewLineCentred("Instructions: Use the arrows keys") + GetNewLineCentred("to navigate and press enter to") + GetNewLineCentred("confirm a selection.") +
105 GetEmptyLine() + GetEmptyLine() + GetNewLineLeftJustified("Use ANSI colour escape codes?");
106
107 const std::string COMMON_BOTTOM_STRING = GetBottomLine() + GetBottomBox();
108
110
112 }
113
114 else
115 {
116 const std::string COMMON_TOP_STRING = GetTopBox() + GetTopLine() +
117 GetNewLineCentred("Platform: " + AddColour("macOS or Linux", Globals::Colours::GREEN)) + GetEmptyLine() +
118 GetNewLineCentred("Controls: " + AddColour("Enhanced", Globals::Colours::GREEN)) + GetEmptyLine() +
119 GetNewLineCentred("Instructions: Enter one of the") + GetNewLineCentred("WASD keys to navigate, 'e' to") + GetNewLineCentred("to confirm a selection and 'z' to") + GetNewLineCentred("undo a selection in Battleships.") +
120 GetEmptyLine() + GetNewLineLeftJustified("Use ANSI colour escape codes?");
121
122 const std::string COMMON_BOTTOM_STRING = GetBottomLine() + GetBottomBox();
123
125
127 }
128
129 m_useAnsiEscapeCodes = OLD_USE_ANSI_ESCAPE_CODES;
130
131 return output;
132 }
133
134 std::vector<std::string> PageBuilder::GetGameSelectionMainMenuPages(const std::vector<std::string>& p_gameNames) const
135 {
136 const std::string COMMON_TOP_STRING = GetTopBox() + GetTopLine();
137 const std::string COMMON_BOTTOM_STRING = GetBottomLine() + GetBottomBox();
138
139 return GetGeneralOptionSelectionPages(p_gameNames, COMMON_TOP_STRING, COMMON_BOTTOM_STRING, true, true, true);
140 }
141
142 std::vector<std::string> PageBuilder::GetPlayerCountOptionSelectionGamePages(const GameInformation& p_gameInformation)
143 {
144 switch (m_currentPage)
145 {
146 case Pages::TICTACTOE:
147 case Pages::HANGMAN:
148 return GetGameOptionSelectionPages(p_gameInformation, "Please select the number of players:", Globals::G_GAME_MAX_TWO_PLAYERS_OPTIONS);
149
151 return GetGameOptionSelectionPages(p_gameInformation, "Please select the number of players:", Globals::G_GAME_MAX_ONE_PLAYER_OPTIONS);
152
153 default:
154 return {"The 'GetPlayerCountOptionSelectionGameDisplays' function does not support the current page type."};
155 }
156 }
157
158 std::vector<std::string> PageBuilder::GetUserPlayerChoiceOptionSelectionGamePages(const GameInformation& p_gameInformation)
159 {
160 switch (m_currentPage)
161 {
162 case Pages::TICTACTOE:
163 return GetGameOptionSelectionPages(p_gameInformation, "Please select the player you would like to be:", Globals::G_TICTACTOE_PLAYER_CHOICE_OPTIONS);
164
165 case Pages::HANGMAN:
166 return GetGameOptionSelectionPages(p_gameInformation, "Please select the player you would like to be:", Globals::G_HANGMAN_PLAYER_CHOICE_OPTIONS);
167
168 default:
169 return {"The 'GetUserPlayerChoiceOptionSelectionGameDisplays' function does not support the current page type."};
170 }
171 }
172
173 std::vector<std::string> PageBuilder::GetComputerSpeedOptionSelectionGamePages(const GameInformation& p_gameInformation)
174 {
175 switch (m_currentPage)
176 {
177 case Pages::TICTACTOE:
178 case Pages::HANGMAN:
180 return GetGameOptionSelectionPages(p_gameInformation, "Please select the computer speed:", Globals::G_GAME_COMPUTER_SPEED_OPTIONS);
181
182 default:
183 return {"The 'GetComputerSpeedOptionSelectionGameDisplays' function does not support the current page type."};
184 }
185 }
186
187 std::string PageBuilder::GetPageWithMessage(const GameInformation& p_gameInformation, const std::string& p_message)
188 {
189 const std::string COMMON_TOP_STRING = GetTopBox() + GetTopLine() + GetGeneralGameSubPage(p_gameInformation) + GetEmptyLine() + GetNewLineLeftJustified(p_message);
190 const std::string COMMON_BOTTOM_STRING = GetBottomLine() + GetBottomBox();
191
192 return COMMON_TOP_STRING + GetRemainingEmptyLines(COMMON_TOP_STRING, COMMON_BOTTOM_STRING) + COMMON_BOTTOM_STRING;
193 }
194
195 std::string PageBuilder::GetUserCommandPage(const GameInformation& p_gameInformation)
196 {
197 switch (m_currentPage)
198 {
199 case Pages::TICTACTOE:
200 return GetPageWithMessage(p_gameInformation, p_gameInformation.m_ticTacToeGameInformation.m_currentPlayer + ", please enter your next command!");
201
202 case Pages::HANGMAN:
203 return GetPageWithMessage(p_gameInformation, "Guesser, please enter your next guess: " + AddColour(std::string(1, p_gameInformation.m_hangmanGameInformation.m_currentLetterSelected), Globals::Colours::BLUE));
204
206 return GetPageWithMessage(p_gameInformation, p_gameInformation.m_battleshipsGameInformation.m_currentPlayer + ", please enter your next command!");
207
208 default:
209 return "The 'GetUserCommandGameDisplay' function does not support the current page type.";
210 }
211 }
212
213 std::string PageBuilder::GetComputerCommandPage(const GameInformation& p_gameInformation)
214 {
215 switch (m_currentPage)
216 {
217 case Pages::TICTACTOE:
218 case Pages::HANGMAN:
220 return GetPageWithMessage(p_gameInformation, "The computer is executing their next move!");
221
222 default:
223 return "The 'GetComputerSpeedOptionSelectionGameDisplays' function does not support the current page type.";
224 }
225 }
226
227 std::string PageBuilder::GetGameOverPage(const GameInformation& p_gameInformation)
228 {
229 std::string topString = GetTopBox() + GetTopLine() + GetGeneralGameSubPage(p_gameInformation) + GetEmptyLine() + GetNewLineCentred("GAME OVER") + GetEmptyLine();
230 const std::string BOTTOM_STRING = GetEmptyLine() + GetNewLineCentred("Press 'r' to restart game OR any key to reset game...") + GetBottomLine() + GetBottomBox();
231
232 switch (m_currentPage)
233 {
234 case Pages::TICTACTOE:
235 if (p_gameInformation.m_ticTacToeGameInformation.m_hasWinner) // This game can be drawn unlike the others.
236 {
237 topString += GetNewLineCentred(p_gameInformation.m_ticTacToeGameInformation.m_currentPlayer + " has won! The game lasted " + std::to_string(p_gameInformation.m_ticTacToeGameInformation.m_turnCount) + " turns.");
238 }
239
240 else
241 {
242 topString += GetNewLineCentred("The game is a draw! The game lasted " + std::to_string(p_gameInformation.m_ticTacToeGameInformation.m_turnCount) + " turns.");
243 }
244 break;
245
246 case Pages::HANGMAN:
248 {
249 topString += GetNewLineCentred("The word setter has won! The game lasted " + std::to_string(p_gameInformation.m_hangmanGameInformation.m_turnCount) + " turns!");
250 }
251
252 else
253 {
254 topString += GetNewLineCentred("The guesser has won! The game lasted " + std::to_string(p_gameInformation.m_hangmanGameInformation.m_turnCount) + " turns.");
255 }
256 break;
257
259 topString += GetNewLineCentred(p_gameInformation.m_battleshipsGameInformation.m_currentPlayer + " has won! The game lasted " + std::to_string(p_gameInformation.m_battleshipsGameInformation.m_turnCount) + " turns.");
260 break;
261
262 default:
263 return "The 'GetGameOverGameDisplay' function does not support the current page type.";
264 }
265
266 return topString + GetRemainingEmptyLines(topString, BOTTOM_STRING) + BOTTOM_STRING;
267 }
268
269 std::vector<std::string> PageBuilder::GetQuitOptionSelectionPage() const
270 {
271 const std::string COMMON_TOP_STRING = GetTopBox() + GetTopLine();
272 const std::string COMMON_BOTTOM_STRING = GetBottomLine() + GetBottomBox();
273 return GetGeneralOptionSelectionPages(Globals::G_QUIT_MENU_OPTIONS, COMMON_TOP_STRING, COMMON_BOTTOM_STRING, true, true, true);
274 }
275
276 std::string PageBuilder::AddColour(const std::string& p_input, const Globals::Colours& p_colour) const
277 {
279 {
280 return p_input;
281 }
282
283 return Globals::G_PAGE_ANSI_ALL_COLOUR_ESCAPE_CODES.at(static_cast<uint8_t>(p_colour)) + p_input + Globals::G_PAGE_ANSI_WHITE_COLOUR_ESCAPE_CODE;
284 }
285
286 std::string PageBuilder::RemoveColour(const std::string& p_input)
287 {
288 std::string output = p_input;
289
290 for (const std::string& currentAnsiColourEscapeCode : Globals::G_PAGE_ANSI_ALL_COLOUR_ESCAPE_CODES)
291 {
292 Globals::RemoveSubString(output, currentAnsiColourEscapeCode);
293 }
294
295 return output;
296 }
297
298 std::string PageBuilder::GetEmptyLine() const
299 {
300 std::string output;
302
304 output.insert(output.size(), m_lineMaximumCharacterCount + m_minimumLeftPadding + m_minimumRightPadding, ' ');
305 return output + Globals::G_PAGE_VERTICAL_LINE + '\n';
306 }
307
308 std::string PageBuilder::GetNewLineCentred(const std::string& p_input, const Globals::Colours& p_colour, const std::string& p_selector) const
309 {
310 static const double DIVISOR = 2;
311
312 // ANSI colour escape codes when within a string take up *** characters but visually have zero width. Thus, exclude them
313 // from all padding calculations.
314 const std::string INPUT_WITH_SELECTOR = p_selector.empty() ? p_input : p_selector + ' ' + p_input;
315 const uint32_t INPUT_WITH_SELECTOR_ANSI_COLOUR_ESCAPE_CODE_COUNT = Globals::ImplementStdCount(INPUT_WITH_SELECTOR.begin(), INPUT_WITH_SELECTOR.end(), Globals::G_PAGE_ANSI_COLOUR_ESCAPE_CODE_START);
316 const uint32_t INPUT_WITH_SELECTOR_SIZE = static_cast<uint32_t>(INPUT_WITH_SELECTOR.size()) - (INPUT_WITH_SELECTOR_ANSI_COLOUR_ESCAPE_CODE_COUNT * Globals::G_PAGE_ANSI_COLOUR_ESCAPE_CODE_SIZE);
317
318 const uint32_t SELECTOR_ANSI_COLOUR_ESCAPE_CODE_COUNT = Globals::ImplementStdCount(p_selector.begin(), p_selector.end(), Globals::G_PAGE_ANSI_COLOUR_ESCAPE_CODE_START);
319 const uint32_t SELECTOR_SIZE = static_cast<uint32_t>(p_selector.size()) - (SELECTOR_ANSI_COLOUR_ESCAPE_CODE_COUNT * Globals::G_PAGE_ANSI_COLOUR_ESCAPE_CODE_SIZE);
320
321 const std::string INPUT_TRIMMED = INPUT_WITH_SELECTOR_SIZE > m_lineMaximumCharacterCount ? INPUT_WITH_SELECTOR.substr(0, m_lineMaximumCharacterCount) : INPUT_WITH_SELECTOR;
322 const uint32_t INPUT_TRIMMED_SIZE = static_cast<uint32_t>(INPUT_TRIMMED.size()) - (INPUT_WITH_SELECTOR_ANSI_COLOUR_ESCAPE_CODE_COUNT * Globals::G_PAGE_ANSI_COLOUR_ESCAPE_CODE_SIZE);
323
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));
326
327 std::string output;
329
331 output.insert(output.size(), m_minimumLeftPadding + LEFT_PADDING_SIZE, ' ');
332 output += AddColour(INPUT_TRIMMED, p_colour);
333 output.insert(output.size(), RIGHT_PADDING_SIZE + m_minimumRightPadding, ' ');
334 return output + Globals::G_PAGE_VERTICAL_LINE + '\n';
335 }
336
337 std::string PageBuilder::GetNewLineCentredOptimised(const std::string& p_input) const
338 {
339 static const double DIVISOR = 2;
340
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));
343
344 std::string output;
346
348 output.insert(output.size(), m_minimumLeftPadding + LEFT_PADDING_SIZE, ' ');
349 output += p_input;
350 output.insert(output.size(), RIGHT_PADDING_SIZE + m_minimumRightPadding, ' ');
352 output += '\n';
353 return output;
354 }
355
356 std::string PageBuilder::GetNewLineLeftJustified(const std::string& p_input, const Globals::Colours& p_colour, const std::string& p_selector) const
357 {
358 const std::string INPUT = p_selector.empty() ? p_input : p_selector + ' ' + p_input;
359
360 // ANSI colour escape codes when within a string take up *** characters but visually have zero width. Thus, exclude them
361 // from all padding calculations.
362 const uint32_t ANSI_COLOUR_ESCAPE_CODE_COUNT = Globals::ImplementStdCount(INPUT.begin(), INPUT.end(), Globals::G_PAGE_ANSI_COLOUR_ESCAPE_CODE_START);
363 const uint32_t INPUT_SIZE = static_cast<uint32_t>(INPUT.size()) - (ANSI_COLOUR_ESCAPE_CODE_COUNT * Globals::G_PAGE_ANSI_COLOUR_ESCAPE_CODE_SIZE);
364
365 std::string output;
367
369 output.insert(output.size(), m_minimumLeftPadding, ' ');
370
371 if (INPUT_SIZE > m_lineMaximumCharacterCount)
372 {
373 output += AddColour(INPUT.substr(0, m_lineMaximumCharacterCount), p_colour);
374 output.insert(output.size(), m_minimumRightPadding, ' ');
375 }
376
377 else
378 {
379 output += AddColour(INPUT, p_colour);
380 output.insert(output.size(), m_lineMaximumCharacterCount + m_minimumRightPadding - INPUT_SIZE, ' ');
381 }
382
383 return output + Globals::G_PAGE_VERTICAL_LINE + '\n';
384 }
385
386 std::string PageBuilder::GetTopLine() const
387 {
388 std::string output;
389 output.reserve(m_pageWidth);
390
393 return output + Globals::G_PAGE_TOP_RIGHT_CORNER + '\n';
394 }
395
396 std::string PageBuilder::GetBottomLine() const
397 {
398 std::string output;
399 output.reserve(m_pageWidth);
400
403 return output + Globals::G_PAGE_BOTTOM_RIGHT_CORNER + '\n';
404 }
405
410
411 std::string PageBuilder::GetBottomBox() const
412 {
413 // Globals::G_PAGE_ANSI_RESET_COLOUR_ESCAPE_CODE used to unset any ANSI colour escape code. If the program unexpectedly
414 // crashes the user's terminal will not be affected.
416 }
417
418 std::string PageBuilder::GetRemainingEmptyLines(const std::string& p_commonTopString, const std::string& p_commonBottomString) const
419 {
420 const int32_t REMAINING_LINE_COUNT = static_cast<int32_t>(m_pageHeight) - Globals::ImplementStdCount(p_commonTopString.begin(), p_commonTopString.end(), '\n') - Globals::ImplementStdCount(p_commonBottomString.begin(), p_commonBottomString.end(), '\n');
421 const uint32_t EMPTY_LINES_TO_ADD_COUNT = REMAINING_LINE_COUNT < 0 ? 0 : REMAINING_LINE_COUNT;
422
423 std::string output;
424 output.reserve(m_pageWidth * EMPTY_LINES_TO_ADD_COUNT); // NOLINT(bugprone-implicit-widening-of-multiplication-result)
425 for (uint32_t emptyLineCount = 0; emptyLineCount < EMPTY_LINES_TO_ADD_COUNT; emptyLineCount++)
426 {
427 output += GetEmptyLine();
428 }
429
430 return output;
431 }
432
433 std::vector<std::string> PageBuilder::GetGeneralOptionSelectionPages( // NOLINT(readability-function-cognitive-complexity)
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
440 {
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));
444
445 std::vector<std::string> output(p_options.size());
446
447 // Construct a page for each option selected.
448 for (uint32_t currentOptionSelected = 0; currentOptionSelected < p_options.size(); currentOptionSelected++)
449 {
450 std::string currentTopString = p_commonTopString;
451
452 if (p_centerOptionsVertically)
453 {
454 for (uint32_t emptyLineCount = 0; emptyLineCount < EMPTY_LINES_BEFORE_OPTIONS; emptyLineCount++)
455 {
456 currentTopString += GetEmptyLine();
457 }
458 }
459
460 for (uint32_t currentOption = 0; currentOption < p_options.size(); currentOption++)
461 {
462 if (currentOption == currentOptionSelected)
463 {
464 if (p_centerOptionsHorizontally)
465 {
466 currentTopString += GetNewLineCentred(p_options[currentOption], Globals::Colours::BLUE, Globals::G_PAGE_OPTION_SELECTOR);
467 }
468
469 else
470 {
471 currentTopString += GetNewLineLeftJustified(p_options[currentOption], Globals::Colours::BLUE, Globals::G_PAGE_OPTION_SELECTOR);
472 }
473 }
474
475 else if (p_centerOptionsHorizontally)
476 {
477 currentTopString += GetNewLineCentred(p_options[currentOption]);
478 }
479
480 else
481 {
482 currentTopString += GetNewLineLeftJustified(Globals::G_PAGE_OPTION_SELECTOR_ABSENT_PADDING + p_options[currentOption]);
483 }
484
485 if (p_addEmptyLineBetweenOptions)
486 {
487 if (currentOption != p_options.size() - 1) // Don't add extra line on the last option.
488 {
489 currentTopString += GetEmptyLine();
490 }
491 }
492 }
493
494 if (p_centerOptionsVertically)
495 {
496 output[currentOptionSelected] = currentTopString;
497
498 for (uint32_t emptyLineCount = 0; emptyLineCount < EMPTY_LINES_AFTER_OPTIONS; emptyLineCount++)
499 {
500 output[currentOptionSelected] += GetEmptyLine();
501 }
502
503 output[currentOptionSelected] += p_commonBottomString;
504 }
505
506 else
507 {
508 output[currentOptionSelected] = currentTopString;
509 output[currentOptionSelected] += GetRemainingEmptyLines(currentTopString, p_commonBottomString);
510 output[currentOptionSelected] += p_commonBottomString;
511 }
512 }
513
514 return output;
515 }
516
517 std::vector<std::string> PageBuilder::GetGameOptionSelectionPages(const GameInformation& p_gameInformation, const std::string& p_message, const std::vector<std::string>& p_options)
518 {
519 const std::string COMMON_TOP_STRING = GetTopBox() + GetTopLine() + GetGeneralGameSubPage(p_gameInformation) + GetEmptyLine() + GetNewLineLeftJustified(p_message);
520 const std::string COMMON_BOTTOM_STRING = GetBottomLine() + GetBottomBox();
521
522 return GetGeneralOptionSelectionPages(p_options, COMMON_TOP_STRING, COMMON_BOTTOM_STRING, false, false, false);
523 }
524
525 std::string PageBuilder::GetGeneralGameSubPage(const GameInformation& p_gameInformation)
526 {
527 switch (m_currentPage)
528 {
529 case Pages::TICTACTOE:
530 return GetTicTacToeSubPage(p_gameInformation);
531
532 case Pages::HANGMAN:
533 return GetHangmanSubPage(p_gameInformation);
534
536 return GetBattleshipsSubPage(p_gameInformation);
537
538 default:
539 return "The 'GetGeneralGameDisplay' function does not support the current page type.";
540 }
541 }
542
543 std::string PageBuilder::GetTicTacToeSubPage(const GameInformation& p_gameInformation)
544 {
545 // leftGridLines and RIGHT_GRID_STRINGS vectors must equal GRID_HEIGHT in size.
546 // Also LEFT_GRID_SIZE + RIGHT_GRID_SIZE must equal G_TICTACTOE_DISPLAY_WIDTH - (numberOfGrids * (Globals::G_PAGE_MINIMUM_LEFT_VERTICAL_LINE_SIZE - Globals::G_PAGE_MINIMUM_RIGHT_VERTICAL_LINE_SIZE))
547 const uint32_t LEFT_GRID_SIZE = 11;
548 const uint32_t RIGHT_GRID_SIZE = 40;
549 const uint32_t GRID_HEIGHT = 5;
550
551 // Tic Tac Toe board section
552 std::vector<std::string> leftGridLines;
553 for (uint32_t row = 0; row < Globals::G_TICTACTOE_GRID_HEIGHT; row++)
554 {
555 std::string currentRow;
556 std::string currentRowDivider;
557 currentRow.reserve(LEFT_GRID_SIZE);
558 currentRowDivider.reserve(LEFT_GRID_SIZE);
559
560 for (uint32_t column = 0; column < Globals::G_TICTACTOE_GRID_WIDTH; column++)
561 {
562 currentRow += p_gameInformation.m_ticTacToeGameInformation.m_gameGrid.at(row).at(column);
564
565 // Skip on last value
566 if (column != Globals::G_TICTACTOE_GRID_WIDTH - 1)
567 {
569 currentRowDivider += Globals::G_PAGE_GRID_INTERSECTION;
570 }
571 }
572
573 leftGridLines.emplace_back(currentRow);
574 leftGridLines.emplace_back(currentRowDivider);
575 }
576
577 // Game options section
578 const std::vector<std::string> RIGHT_GRID_LINES = {
579 "",
581 "",
583 "",
584 };
585
586 return GetGridLayout({LEFT_GRID_SIZE, RIGHT_GRID_SIZE}, {leftGridLines, RIGHT_GRID_LINES}, GRID_HEIGHT);
587 }
588
589 std::string PageBuilder::GetHangmanSubPage(const GameInformation& p_gameInformation)
590 {
591 // leftGridLines, MIDDLE_GRID_LINES and rightGridLines vectors must equal GRID_HEIGHT in size.
592 // Also LEFT_GRID_SIZE + MIDDLE_GRID_SIZE + RIGHT_GRID_SIZE must equal G_HANGMAN_DISPLAY_WIDTH - (numberOfGrids * (Globals::G_PAGE_MINIMUM_LEFT_VERTICAL_LINE_SIZE - Globals::G_PAGE_MINIMUM_RIGHT_VERTICAL_LINE_SIZE))
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;
597
598 // Hangman state section
599 const std::vector<std::string>& leftGridLines = Globals::G_HANGMAN_STATES[p_gameInformation.m_hangmanGameInformation.m_incorrectGuesses.size()];
600
601 // Game options section
602 const std::vector<std::string> MIDDLE_GRID_LINES = {
603 "",
604 "",
606 "",
608 "",
609 "",
610 };
611
612 // Incorrect Guesses section
613 std::vector<std::string> rightGridLines;
614 std::string currentLine;
615 currentLine.reserve(RIGHT_GRID_SIZE);
616
617 rightGridLines.emplace_back("");
618 rightGridLines.emplace_back(Globals::G_HANGMAN_INCORRECT_GUESSES_TITLE);
619
620 for (uint32_t letterIndex = 0; letterIndex < p_gameInformation.m_hangmanGameInformation.m_incorrectGuesses.size(); letterIndex++)
621 {
622 currentLine += p_gameInformation.m_hangmanGameInformation.m_incorrectGuesses.at(letterIndex);
623
624 // Skip adding space on last value on each line
626 {
628 }
629
630 else
631 {
632 rightGridLines.emplace_back(currentLine);
633 rightGridLines.emplace_back("");
634 currentLine.clear();
635 }
636 }
637
638 if (!currentLine.empty())
639 {
640 rightGridLines.emplace_back(currentLine);
641 }
642
643 // Adding required number of empty lines to meet GRID_HEIGHT
644 const uint32_t REMAINING_LINES_TO_ADD = GRID_HEIGHT - rightGridLines.size();
645 for (uint32_t emptyLineCount = 0; emptyLineCount < REMAINING_LINES_TO_ADD; emptyLineCount++)
646 {
647 rightGridLines.emplace_back("");
648 }
649
650 std::string output = GetGridLayout({LEFT_GRID_SIZE, MIDDLE_GRID_SIZE, RIGHT_GRID_SIZE}, {leftGridLines, MIDDLE_GRID_LINES, rightGridLines}, GRID_HEIGHT);
651
652 // Current guess of word and word to be guessed section
653 std::string currentGuessOfWord;
654 currentGuessOfWord.reserve(2 * p_gameInformation.m_hangmanGameInformation.m_currentGuessOfWord.size());
655 for (const char& letter : p_gameInformation.m_hangmanGameInformation.m_currentGuessOfWord)
656 {
657 currentGuessOfWord += letter;
658 currentGuessOfWord += ' ';
659 }
660
661 if (p_gameInformation.m_hangmanGameInformation.m_isGameOver)
662 {
664 }
665
666 else
667 {
668 output += GetNewLineLeftJustified(currentGuessOfWord);
669 }
670
671 return output;
672 }
673
674 std::string PageBuilder::GetBattleshipsSubPage(const GameInformation& p_gameInformation) // NOLINT(readability-function-cognitive-complexity)
675 {
676 // leftGridLines, middleGridLines and rightGridLines vectors must equal GRID_HEIGHT in size.
677 // Also LEFT_GRID_SIZE + MIDDLE_GRID_SIZE + RIGHT_GRID_SIZE must equal G_BATTLESHIPS_DISPLAY_WIDTH - (numberOfGrids * Globals::G_PAGE_MINIMUM_LEFT_VERTICAL_LINE_SIZE - Globals::G_PAGE_MINIMUM_RIGHT_VERTICAL_LINE_SIZE))
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;
682
683 const std::string SINGLE_SPACE(1, ' ');
684
685 std::string commonGridAlphabetAxis;
686 commonGridAlphabetAxis.reserve(LEFT_GRID_SIZE);
687
688 commonGridAlphabetAxis += Globals::G_PAGE_GRID_VERTICAL_LINE;
689 commonGridAlphabetAxis += Globals::G_BATTLESHIPS_EMPTY_GRID_VALUE;
690
691 for (uint32_t currentLetter = Globals::G_BATTLESHIPS_LETTER_OFFSET; (currentLetter - Globals::G_BATTLESHIPS_LETTER_OFFSET) < Globals::G_BATTLESHIPS_BOARD_WIDTH; currentLetter++)
692 {
693 commonGridAlphabetAxis += Globals::G_PAGE_GRID_VERTICAL_LINE;
694 commonGridAlphabetAxis += SINGLE_SPACE;
695 commonGridAlphabetAxis += static_cast<char>(currentLetter);
696 commonGridAlphabetAxis += SINGLE_SPACE;
697 }
698
699 commonGridAlphabetAxis += Globals::G_PAGE_GRID_VERTICAL_LINE;
700
701 std::vector<std::string> leftGridLines = {Globals::G_BATTLESHIPS_PLAYER_ONE, Globals::G_BATTLESHIPS_GRID_TOP_LINE, commonGridAlphabetAxis, Globals::G_BATTLESHIPS_GRID_MIDDLE_LINE};
702 std::vector<std::string> rightGridLines = {Globals::G_BATTLESHIPS_PLAYER_TWO, Globals::G_BATTLESHIPS_GRID_TOP_LINE, commonGridAlphabetAxis, Globals::G_BATTLESHIPS_GRID_MIDDLE_LINE};
703
704 // Assuming both board are the same size
705 for (uint32_t row = 0; row < p_gameInformation.m_battleshipsGameInformation.m_boardPlayerOne.size(); row++)
706 {
707 std::string currentLeftGridValueLine;
708 currentLeftGridValueLine.reserve(LEFT_GRID_SIZE);
709 currentLeftGridValueLine += Globals::G_PAGE_GRID_VERTICAL_LINE;
710 currentLeftGridValueLine += SINGLE_SPACE;
711 currentLeftGridValueLine += std::to_string(row);
712 currentLeftGridValueLine += SINGLE_SPACE;
713
714 std::string currentRightGridValueLine = currentLeftGridValueLine;
715
716 for (uint32_t column = 0; column < p_gameInformation.m_battleshipsGameInformation.m_boardPlayerOne.at(row).size(); column++)
717 {
718 // Don't include the ship name instead only its state
719 currentLeftGridValueLine += Globals::G_PAGE_GRID_VERTICAL_LINE + p_gameInformation.m_battleshipsGameInformation.m_boardPlayerOne.at(row).at(column).substr(0, Globals::G_BATTLESHIPS_GRID_ELEMENT_WIDTH);
720
721 // Only show player two board if game is over, or if not game over then only if zero player game, or if not game
722 // over and not zero player game (i.e. one player game) then only if grid value is does not have a ship present
723 // (i.e. only if grid value is empty, missed attack or successful attack).
725 {
726 currentRightGridValueLine += Globals::G_PAGE_GRID_VERTICAL_LINE + p_gameInformation.m_battleshipsGameInformation.m_boardPlayerTwo.at(row).at(column).substr(0, Globals::G_BATTLESHIPS_GRID_ELEMENT_WIDTH);
727 }
728
729 else
730 {
732 }
733 }
734
735 currentLeftGridValueLine += Globals::G_PAGE_GRID_VERTICAL_LINE;
736 currentRightGridValueLine += Globals::G_PAGE_GRID_VERTICAL_LINE;
737
738 leftGridLines.emplace_back(currentLeftGridValueLine);
739 rightGridLines.emplace_back(currentRightGridValueLine);
740
741 // Skip on last row
742 if (row != p_gameInformation.m_battleshipsGameInformation.m_boardPlayerOne.size() - 1)
743 {
744 leftGridLines.emplace_back(Globals::G_BATTLESHIPS_GRID_MIDDLE_LINE);
745 rightGridLines.emplace_back(Globals::G_BATTLESHIPS_GRID_MIDDLE_LINE);
746 }
747
748 else
749 {
750 leftGridLines.emplace_back(Globals::G_BATTLESHIPS_GRID_BOTTOM_LINE);
751 rightGridLines.emplace_back(Globals::G_BATTLESHIPS_GRID_BOTTOM_LINE);
752 }
753 }
754
755 std::vector<std::string> middleGridLines = {
756 "",
757 "",
758 "",
759 "",
761 "",
763 "",
764 "",
765 };
766
767 for (uint32_t currentShip = 0; currentShip < Globals::G_BATTLESHIPS_SHIP_NAMES.size(); currentShip++)
768 {
769 std::string currentShipHealthLine;
770 currentShipHealthLine.reserve(MIDDLE_GRID_SIZE);
771
772 // Player one
773 for (uint32_t currentShipHealthSquare = 0; currentShipHealthSquare < Globals::G_BATTLESHIPS_SHIP_SIZES.at(currentShip); currentShipHealthSquare++)
774 {
775 if (currentShipHealthSquare < p_gameInformation.m_battleshipsGameInformation.m_shipsRemainingPlayerOne.at(Globals::G_BATTLESHIPS_SHIP_PLACED_NAMES.at(currentShip)))
776 {
777 currentShipHealthLine += Globals::G_BATTLESHIPS_SHIP_PRESENT;
778 }
779
780 else
781 {
782 currentShipHealthLine += Globals::G_BATTLESHIPS_SUCCESSFUL_ATTACK;
783 }
784
785 // Skip on last iteration
786 if (currentShipHealthSquare != Globals::G_BATTLESHIPS_SHIP_SIZES.at(currentShip) - 1)
787 {
788 currentShipHealthLine += SINGLE_SPACE;
789 }
790 }
791
792 std::string currentShipHealthTitle;
793 currentShipHealthTitle.reserve(MIDDLE_GRID_SIZE);
794
795 if (p_gameInformation.m_battleshipsGameInformation.m_isGameOver || p_gameInformation.m_battleshipsGameInformation.m_playerCount != "1")
796 {
797 currentShipHealthTitle = Globals::G_BATTLESHIPS_SHIP_NAMES.at(currentShip) + std::string(MIDDLE_GRID_SIZE - (2 * Globals::G_BATTLESHIPS_SHIP_NAMES.at(currentShip).size()), ' ') + Globals::G_BATTLESHIPS_SHIP_NAMES.at(currentShip);
798
799 currentShipHealthLine += std::string(MIDDLE_GRID_SIZE - (2 * Globals::G_BATTLESHIPS_SHIP_SIZES.at(currentShip) * Globals::G_BATTLESHIPS_GRID_ELEMENT_WIDTH) - (2 * (Globals::G_BATTLESHIPS_SHIP_SIZES.at(currentShip) - 1)), ' ');
800
801 // Player Two
802 for (uint32_t currentShipHealthSquare = 0; currentShipHealthSquare < Globals::G_BATTLESHIPS_SHIP_SIZES.at(currentShip); currentShipHealthSquare++)
803 {
804 if (currentShipHealthSquare < (Globals::G_BATTLESHIPS_SHIP_SIZES.at(currentShip) - p_gameInformation.m_battleshipsGameInformation.m_shipsRemainingPlayerTwo.at(Globals::G_BATTLESHIPS_SHIP_PLACED_NAMES.at(currentShip))))
805 {
806 currentShipHealthLine += Globals::G_BATTLESHIPS_SUCCESSFUL_ATTACK;
807 }
808
809 else
810 {
811 currentShipHealthLine += Globals::G_BATTLESHIPS_SHIP_PRESENT;
812 }
813
814 // Skip on last iteration
815 if (currentShipHealthSquare != Globals::G_BATTLESHIPS_SHIP_SIZES.at(currentShip) - 1)
816 {
817 currentShipHealthLine += SINGLE_SPACE;
818 }
819 }
820 }
821
822 else
823 {
824 currentShipHealthTitle = Globals::G_BATTLESHIPS_SHIP_NAMES.at(currentShip) + std::string(MIDDLE_GRID_SIZE - Globals::G_BATTLESHIPS_SHIP_NAMES.at(currentShip).size(), ' ');
825 currentShipHealthLine += std::string(MIDDLE_GRID_SIZE - (Globals::G_BATTLESHIPS_SHIP_SIZES.at(currentShip) * Globals::G_BATTLESHIPS_GRID_ELEMENT_WIDTH) - (Globals::G_BATTLESHIPS_SHIP_SIZES.at(currentShip) - 1), ' ');
826 }
827
828 middleGridLines.emplace_back(currentShipHealthTitle);
829 middleGridLines.emplace_back(currentShipHealthLine);
830 middleGridLines.emplace_back("");
831 }
832
833 return GetGridLayout({LEFT_GRID_SIZE, MIDDLE_GRID_SIZE, RIGHT_GRID_SIZE}, {leftGridLines, middleGridLines, rightGridLines}, GRID_HEIGHT);
834 }
835
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)
837 {
838 const uint32_t OLD_MAXIMUM_LINE_SIZE = m_lineMaximumCharacterCount;
839 const uint32_t OLD_MINIMUM_LEFT_PADDING = m_minimumLeftPadding;
840 const uint32_t OLD_MINIMUM_RIGHT_PADDING = m_minimumRightPadding;
841
844
845 std::string output;
846
847 for (uint32_t currentLineNumber = 0; currentLineNumber < p_gridColumnHeight; currentLineNumber++)
848 {
849 std::string currentLine;
850 currentLine.reserve(m_pageWidth);
851
852 for (uint32_t currentGridSize = 0; currentGridSize < p_gridColumnWidths.size(); currentGridSize++)
853 {
854 m_lineMaximumCharacterCount = p_gridColumnWidths[currentGridSize];
855 currentLine += GetNewLineCentredOptimised(p_gridColumnLines[currentGridSize][currentLineNumber]);
856 }
857
858 // Remove the vertical lines created between grids and all new lines
859 std::ranges::replace(currentLine.begin(), currentLine.end(), Globals::G_PAGE_VERTICAL_LINE, ' ');
860 std::erase(currentLine, '\n');
861
862 // Re-add the vertical lines to the start/end and re-add a single newline to the end
864 output += currentLine;
866 output += '\n';
867 }
868
869 m_lineMaximumCharacterCount = OLD_MAXIMUM_LINE_SIZE;
870 m_minimumLeftPadding = OLD_MINIMUM_LEFT_PADDING;
871 m_minimumRightPadding = OLD_MINIMUM_RIGHT_PADDING;
872
873 return output;
874 }
875}
Used for functionality that has not been implemented.
Definition Globals.hpp:68
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.
Definition Globals.hpp:406
static const std::vector< std::string > G_QUIT_MENU_OPTIONS
Quit menu options.
Definition Globals.hpp:335
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.
Definition Globals.hpp:1679
static const std::string G_TICTACTOE_TOP_TITLE
Page attributes for all TicTacToe pages.
Definition Globals.hpp:299
static const std::string G_BATTLESHIPS_TOP_TITLE
Page attributes for all Battleships pages.
Definition Globals.hpp:319
static const char G_PAGE_ANSI_COLOUR_ESCAPE_CODE_START
ANSI colour escape codes to add colour to output.
Definition Globals.hpp:237
static const uint32_t G_MAIN_MENU_DISPLAY_HEIGHT
Page attributes for the MainMenu page.
Definition Globals.hpp:292
static const bool G_PLATFORM_IS_WINDOWS
Used by PageBuilder to display the current platform being used and used by Terminal to decided whethe...
Definition Globals.hpp:166
static const uint32_t G_BATTLESHIPS_DISPLAY_WIDTH
Page attributes for all Battleships pages.
Definition Globals.hpp:321
static const char G_PAGE_BOTTOM_RIGHT_CORNER
Extended ASCII characters for edges and corners of the page.
Definition Globals.hpp:181
static const uint32_t G_HANGMAN_DISPLAY_WIDTH
Page attributes for all Hangman pages.
Definition Globals.hpp:311
static const std::array< std::string, G_PAGE_ANSI_COLOUR_ESCAPE_CODE_COUNT > G_PAGE_ANSI_ALL_COLOUR_ESCAPE_CODES
Definition Globals.hpp:247
static const std::string G_BATTLESHIPS_SUCCESSFUL_ATTACK
Battleships board values.
Definition Globals.hpp:1614
static const std::string G_HANGMAN_WORD_TO_BE_GUESSED_END
Hangman constants used to construct the hangman.
Definition Globals.hpp:581
static const std::string G_HANGMAN_WORD_TO_BE_GUESSED_START
Hangman constants used to construct the hangman.
Definition Globals.hpp:580
static const std::string G_HOMEPAGE_BOTTOM_TITLE
Page attributes for the homepage.
Definition Globals.hpp:280
static const std::string G_BATTLESHIPS_GRID_MIDDLE_LINE
Battleships board constants used to construct the board.
Definition Globals.hpp:1601
static const char G_PAGE_VERTICAL_LINE
Extended ASCII characters for edges and corners of the page.
Definition Globals.hpp:179
static const uint32_t G_BATTLESHIPS_BOARD_WIDTH
Battleships board attributes.
Definition Globals.hpp:1576
static const std::vector< std::string > G_GAME_MAX_TWO_PLAYERS_OPTIONS
Used by multiple games or an attribute not specific to one game.
Definition Globals.hpp:386
static const uint32_t G_TICTACTOE_GRID_WIDTH
TicTacToe grid attributes.
Definition Globals.hpp:394
static const std::string G_PAGE_OPTION_SELECTOR
For when highlighting what is currently selected in an option menu.
Definition Globals.hpp:227
static const char G_PAGE_GRID_VERTICAL_LINE
Extended ASCII characters for grids.
Definition Globals.hpp:191
static const std::string G_BATTLESHIPS_BOTTOM_TITLE
Page attributes for all Battleships pages.
Definition Globals.hpp:320
static const uint32_t G_TICTACTOE_DISPLAY_WIDTH
Page attributes for all TicTacToe pages.
Definition Globals.hpp:301
static const uint32_t G_PAGE_ANSI_COLOUR_ESCAPE_CODE_SIZE
ANSI colour escape codes to add colour to output.
Definition Globals.hpp:236
static const std::string G_HANGMAN_BOTTOM_TITLE
Page attributes for all Hangman pages.
Definition Globals.hpp:310
static const std::string G_HANGMAN_TOP_TITLE
Page attributes for all Hangman pages.
Definition Globals.hpp:309
static const uint32_t G_PAGE_MINIMUM_RIGHT_PADDING_SIZE
Minimum padding amounts.
Definition Globals.hpp:219
static const std::string G_MAIN_MENU_BOTTOM_TITLE
Page attributes for the MainMenu page.
Definition Globals.hpp:290
static const std::string G_BATTLESHIPS_PLAYER_ONE
Battleships player choice options.
Definition Globals.hpp:1621
static const uint32_t G_MAIN_MENU_DISPLAY_WIDTH
Page attributes for the MainMenu page.
Definition Globals.hpp:291
static const std::string G_BATTLESHIPS_GRID_TOP_LINE
Battleships board constants used to construct the board.
Definition Globals.hpp:1600
static const uint32_t G_TICTACTOE_DISPLAY_HEIGHT
Page attributes for all TicTacToe pages.
Definition Globals.hpp:302
static const std::string G_HANGMAN_INCORRECT_GUESSES_PADDING
Hangman constants used to construct the hangman.
Definition Globals.hpp:576
static const uint32_t G_BATTLESHIPS_GRID_ELEMENT_WIDTH
Battleships board attributes.
Definition Globals.hpp:1578
static const char G_PAGE_HORIZONTAL_LINE
Extended ASCII characters for edges and corners of the page.
Definition Globals.hpp:178
static const std::string G_HANGMAN_INCORRECT_GUESSES_TITLE
Hangman constants used to construct the hangman.
Definition Globals.hpp:575
static const uint32_t G_HANGMAN_MAXIMUM_ERROR_COUNT
Hangman maximum errors count to determine whether the game is over.
Definition Globals.hpp:451
static const std::string G_BATTLESHIPS_PLAYER_TWO
Battleships player choice options.
Definition Globals.hpp:1622
static const std::string G_PAGE_ANSI_WHITE_COLOUR_ESCAPE_CODE
ANSI colour escape codes to add colour to output.
Definition Globals.hpp:238
static const std::string G_GAME_NUMBER_OF_PLAYERS
Used by multiple games or an attribute not specific to one game.
Definition Globals.hpp:383
static const std::vector< std::string > G_TICTACTOE_PLAYER_CHOICE_OPTIONS
TicTacToe player choice options.
Definition Globals.hpp:423
static const std::vector< std::vector< std::string > > G_HANGMAN_STATES
Hangman constants used to display the current state of the Hangman game.
Definition Globals.hpp:473
static const std::string G_GAME_COMPUTER_SPEED
Used by multiple games or an attribute not specific to one game.
Definition Globals.hpp:384
static const uint32_t G_BATTLESHIPS_LETTER_OFFSET
Battleships board constants used to construct the board.
Definition Globals.hpp:1604
static const std::string G_MAIN_MENU_TOP_TITLE
Page attributes for the MainMenu page.
Definition Globals.hpp:289
static const std::string G_BATTLESHIPS_SHIP_PRESENT
Battleships board values.
Definition Globals.hpp:1613
static const uint32_t G_PAGE_MINIMUM_RIGHT_VERTICAL_LINE_SIZE
Minimum padding amounts.
Definition Globals.hpp:220
Colours
Colours representing ANSI escape codes.
Definition Globals.hpp:261
@ BLUE
Supported ANSI escape colour.
Definition Globals.hpp:268
@ GREEN
Supported ANSI escape colour.
Definition Globals.hpp:269
@ RED
Supported ANSI escape colour.
Definition Globals.hpp:267
static const char G_PAGE_GRID_INTERSECTION
Extended ASCII characters for grids.
Definition Globals.hpp:192
static const std::string G_TICTACTOE_BOTTOM_TITLE
Page attributes for all TicTacToe pages.
Definition Globals.hpp:300
static const uint32_t G_GAME_TWO_OPTIONS
Used by multiple games or an attribute not specific to one game.
Definition Globals.hpp:380
static const std::string G_BATTLESHIPS_EMPTY_GRID_VALUE
Battleships board values.
Definition Globals.hpp:1611
static const char G_PAGE_TOP_LEFT_CORNER
Extended ASCII characters for edges and corners of the page.
Definition Globals.hpp:183
static const char G_PAGE_BOTTOM_LEFT_CORNER
Extended ASCII characters for edges and corners of the page.
Definition Globals.hpp:182
static const uint32_t G_PAGE_MINIMUM_LEFT_PADDING_SIZE
Minimum padding amounts.
Definition Globals.hpp:218
static const uint32_t G_HANGMAN_INCORRECT_GUESSES_FIRST_LINE_LAST_INDEX
Hangman constants used to construct the hangman.
Definition Globals.hpp:577
static const std::vector< std::string > G_GAME_COMPUTER_SPEED_OPTIONS
Used by multiple games or an attribute not specific to one game.
Definition Globals.hpp:385
static const std::vector< std::string > G_HANGMAN_PLAYER_CHOICE_OPTIONS
Hangman player choice options.
Definition Globals.hpp:590
static const std::string G_PAGE_ANSI_RESET_COLOUR_ESCAPE_CODE
ANSI colour escape codes to add colour to output.
Definition Globals.hpp:243
static const uint32_t G_HANGMAN_DISPLAY_HEIGHT
Page attributes for all Hangman pages.
Definition Globals.hpp:312
static const uint32_t G_BATTLESHIPS_DISPLAY_HEIGHT
Page attributes for all Battleships pages.
Definition Globals.hpp:322
static const uint32_t G_HOMEPAGE_DISPLAY_HEIGHT
Page attributes for the homepage.
Definition Globals.hpp:282
static const std::string G_PAGE_OPTION_SELECTOR_ABSENT_PADDING
For when highlighting what is currently selected in an option menu.
Definition Globals.hpp:228
static const std::vector< std::string > G_GAME_MAX_ONE_PLAYER_OPTIONS
Used by multiple games or an attribute not specific to one game.
Definition Globals.hpp:387
static const std::string G_HOMEPAGE_TOP_TITLE
Page attributes for the homepage.
Definition Globals.hpp:279
static const uint32_t G_HOMEPAGE_DISPLAY_WIDTH
Page attributes for the homepage.
Definition Globals.hpp:281
static const std::array< std::string, G_BATTLESHIPS_SHIP_COUNT > G_BATTLESHIPS_SHIP_NAMES
Battleships list of ship names.
Definition Globals.hpp:1668
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 .
Definition Globals.hpp:150
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.
Definition Globals.hpp:112
static const std::string G_BATTLESHIPS_GRID_BOTTOM_LINE
Battleships board constants used to construct the board.
Definition Globals.hpp:1602
static const uint32_t G_PAGE_MINIMUM_LEFT_VERTICAL_LINE_SIZE
Minimum padding amounts.
Definition Globals.hpp:217
static const char G_PAGE_TOP_RIGHT_CORNER
Extended ASCII characters for edges and corners of the page.
Definition Globals.hpp:180
static const std::array< uint32_t, G_BATTLESHIPS_SHIP_COUNT > G_BATTLESHIPS_SHIP_SIZES
Battleships list of ship sizes.
Definition Globals.hpp:1690
static const uint32_t G_TICTACTOE_GRID_HEIGHT
TicTacToe grid attributes.
Definition Globals.hpp:395
static const uint32_t G_HANGMAN_INCORRECT_GUESSES_SECOND_LINE_LAST_INDEX
Hangman constants used to construct the hangman.
Definition Globals.hpp:578
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.
std::array< std::array< std::string, Globals::G_BATTLESHIPS_BOARD_WIDTH >, Globals::G_BATTLESHIPS_BOARD_HEIGHT > m_boardPlayerOne
Refer to the member data documentation in Battleships.
std::string m_currentPlayer
Refer to the member data documentation in Battleships.
bool m_isGameOver
Refer to the member data documentation in Battleships.
std::array< std::array< std::string, Globals::G_BATTLESHIPS_BOARD_WIDTH >, Globals::G_BATTLESHIPS_BOARD_HEIGHT > m_boardPlayerTwo
Refer to the member data documentation in Battleships.
std::string m_playerCount
Refer to the member data documentation in Battleships.
uint32_t m_turnCount
Refer to the member data documentation in Battleships.
std::unordered_map< std::string, uint32_t > m_shipsRemainingPlayerOne
Refer to the member data documentation in Battleships.
std::unordered_map< std::string, uint32_t > m_shipsRemainingPlayerTwo
Refer to the member data documentation in Battleships.
std::string m_computerSpeedName
Refer to the member data documentation in Battleships.
uint32_t m_turnCount
Refer to the member data documentation in Hangman.
char m_currentLetterSelected
Refer to the member data documentation in Hangman.
std::string m_playerCount
Refer to the member data documentation in Hangman.
std::string m_wordToBeGuessed
Refer to the member data documentation in Hangman.
std::vector< char > m_incorrectGuesses
Refer to the member data documentation in Hangman.
std::string m_currentGuessOfWord
Refer to the member data documentation in Hangman.
std::string m_computerSpeedName
Refer to the member data documentation in Hangman.
bool m_isGameOver
Refer to the member data documentation in Hangman.
uint32_t m_turnCount
Refer to the member data documentation in TicTacToe.
std::array< std::array< std::string, Globals::G_TICTACTOE_GRID_WIDTH >, Globals::G_TICTACTOE_GRID_HEIGHT > m_gameGrid
Refer to the member data documentation in TicTacToe.
std::string m_computerSpeedName
Refer to the member data documentation in TicTacToe.
std::string m_currentPlayer
Refer to the member data documentation in TicTacToe.
bool m_hasWinner
Refer to the member data documentation in TicTacToe.
std::string m_playerCount
Refer to the member data documentation in TicTacToe.
Used by game objects to package themselves into a format that can be used by PageBuilder to construct...
struct TerminalGames::GameInformation::BattleshipsGameInformation m_battleshipsGameInformation
Used to package the Battleships current game state.
struct TerminalGames::GameInformation::HangmanGameInformation m_hangmanGameInformation
Used to package the Hangman current game state.
struct TerminalGames::GameInformation::TicTacToeGameInformation m_ticTacToeGameInformation
Used to package the TicTacToe current game state.