14#include "helpers/Globals.hpp"
15#include "helpers/PageBuilder.hpp"
17#include "helpers/Terminal.hpp"
25 uint32_t currentSelection =
static_cast<uint32_t
>(!p_useAnsiEscapeCodes);
37 return !
static_cast<bool>(currentSelection);
40 currentSelection == 0 ? currentSelection = (p_menus.size() - 1) : --currentSelection;
44 currentSelection == (p_menus.size() - 1) ? currentSelection = 0 : ++currentSelection;
55 uint32_t currentSelection = 0;
67 return currentSelection;
70 currentSelection == 0 ? currentSelection = (p_menus.size() - 1) : --currentSelection;
74 currentSelection == (p_menus.size() - 1) ? currentSelection = 0 : ++currentSelection;
85 uint32_t currentSelection = 0;
98 return currentSelection;
101 currentSelection == 0 ? currentSelection = (p_menus.size() - 1) : --currentSelection;
105 currentSelection == (p_menus.size() - 1) ? currentSelection = 0 : ++currentSelection;
115 const std::tuple<uint32_t, uint32_t>& p_startingGridLocation,
118 const bool& p_displayGetUserCommandPage)
129 const std::tuple<uint32_t, uint32_t>& p_startingGridLocation,
132 const bool& p_displayGetUserCommandPage)
135 uint32_t currentRow = std::get<0>(p_startingGridLocation);
136 uint32_t currentColumn = std::get<1>(p_startingGridLocation);
138 uint32_t maxColumn = 0;
139 uint32_t gridLeftPad = 0;
140 uint32_t gridTopPad = 0;
141 uint32_t gridElementWidth = 0;
142 uint32_t gridElementHeight = 0;
172 if (p_displayGetUserCommandPage)
180 SetCursorPosition(
static_cast<int16_t
>(gridLeftPad + (currentColumn * gridElementWidth)),
static_cast<int16_t
>(gridTopPad + (currentRow * gridElementHeight)));
196 return {currentRow, currentColumn};
199 currentRow == 0 ? currentRow = maxRow : --currentRow;
203 currentRow == maxRow ? currentRow = 0 : ++currentRow;
207 currentColumn == 0 ? currentColumn = maxColumn : --currentColumn;
211 currentColumn == maxColumn ? currentColumn = 0 : ++currentColumn;
221 const std::tuple<uint32_t, uint32_t>& p_startingGridLocation,
224 const bool& p_displayGetUserCommandPage)
228 uint32_t currentRow = std::get<0>(p_startingGridLocation);
229 uint32_t currentColumn = std::get<1>(p_startingGridLocation);
231 uint32_t maxColumn = 0;
233 switch (CURRENT_PAGE_TYPE)
268 if (p_displayGetUserCommandPage)
287 return {currentRow, currentColumn};
290 currentRow == 0 ? currentRow = maxRow : --currentRow;
294 currentRow == maxRow ? currentRow = 0 : ++currentRow;
298 currentColumn == 0 ? currentColumn = maxColumn : --currentColumn;
302 currentColumn == maxColumn ? currentColumn = 0 : ++currentColumn;
334 uint32_t currentSelection = 0;
343 switch (currentSelection)
368 currentSelection == 0 ? currentSelection = (p_menus.size() - 1) : --currentSelection;
372 currentSelection == (p_menus.size() - 1) ? currentSelection = 0 : ++currentSelection;
384 std::cout << p_output;
391 const COORD HOME_COORDS = {0, 0};
392 CONSOLE_SCREEN_BUFFER_INFO consoleScreenBufferInfo;
396 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
397 if (hStdOut == INVALID_HANDLE_VALUE)
403 if (!
static_cast<bool>(GetConsoleScreenBufferInfo(hStdOut, &consoleScreenBufferInfo)))
408 cellCount = consoleScreenBufferInfo.dwSize.X * consoleScreenBufferInfo.dwSize.Y;
411 if (!FillConsoleOutputCharacter(hStdOut,
' ', cellCount, HOME_COORDS, &count))
417 if (!
static_cast<bool>(FillConsoleOutputAttribute(hStdOut, consoleScreenBufferInfo.wAttributes, cellCount, HOME_COORDS, &count)))
423 SetConsoleCursorPosition(hStdOut, HOME_COORDS);
425 std::cout <<
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
432 FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
435 std::string inputString;
439 std::getline(std::cin, inputString);
441 if (inputString.size() != 1)
446 switch (inputString[0])
467 return inputString[0];
477 SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &CURSOR_INFO);
484 const COORD CURSOR_POSITION(p_xCoord, p_yCoord);
485 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), CURSOR_POSITION);
Used when the backspace key is pressed.
Used for functionality that has not been implemented.
Used to quit the main menu.
Used to quit the program.
Used to reset a game which prompts the user for new options.
Used to restart a game with the same user options.
Builds pages (i.e. strings) to be printed to the terminal.
std::vector< std::string > GetQuitOptionSelectionPage() const
Creates the quit option selection page.
Pages GetCurrentPageType() const
Get the current page type.
std::string GetUserCommandPage(const GameInformation &p_gameInformation)
Creates the game user command page which should prompt the user to enter a command.
static void GetUserChoiceFromGameOverMenu(const std::string &p_gameOverPage, const std::vector< std::string > &p_quitOptionMenus)
Get the user choice whether to restart the game, reset the game or a choice from the GetUserChoiceFro...
static void SetCursorVisibility(const bool &p_cursorVisibility)
Wrapper around the <Windows.h> API for the SetConsoleCursorInfo() function.
static std::tuple< uint32_t, uint32_t > GetUserCommandFromGameGridWindows(const std::tuple< uint32_t, uint32_t > &p_startingGridLocation, const PageBuilder &p_pageBuilder, const GameInformation &p_gameInformation, const bool &p_displayGetUserCommandPage)
(Windows) Gets a user command based on the currently displayed game grid.
static uint32_t GetNextKeyPress()
Wrapper for <Windows.h> API for the FlushConsoleInputBuffer() and _getch() functions.
static void PrintOutput(const std::string &p_output)
Clears and then prints to the terminal.
static uint32_t GetUserChoiceFromGameMenus(const std::vector< std::string > &p_menus, const std::vector< std::string > &p_quitOptionMenus)
Get the user choice from a list of game menus screens that are printed to the terminal.
static void ResetTerminal()
Resets the terminal to its original state before the program was run.
static uint32_t GetUserChoiceFromMainMenus(const std::vector< std::string > &p_menus)
Get the user choice from a list of main menus screens that are printed to the terminal.
static std::tuple< uint32_t, uint32_t > GetUserCommandFromGameGridNonWindows(const std::tuple< uint32_t, uint32_t > &p_startingGridLocation, const PageBuilder &p_pageBuilder, const GameInformation &p_gameInformation, const bool &p_displayGetUserCommandPage)
(Non-window) Gets a user command based on the currently displayed game grid.
static void Clear()
Clears the terminal based on this article: https://www.cplusplus.com/articles/4z18T05o.
static std::tuple< uint32_t, uint32_t > GetUserCommandFromGameGrid(const std::tuple< uint32_t, uint32_t > &p_startingGridLocation, const PageBuilder &p_pageBuilder, const GameInformation &p_gameInformation, const bool &p_displayGetUserCommandPage)
Gets a user command based on the currently displayed game grid (wrapper function around the platform-...
static bool GetUserChoiceFromHomepage(const std::vector< std::string > &p_menus, const bool &p_useAnsiEscapeCodes)
Get the user choice from a list of homepage screens that are printed to the terminal.
static void InitialiseTerminal()
Initialises the terminal for the program.
static void SetCursorPosition(const int16_t &p_xCoord, const int16_t &p_yCoord)
Wrapper around the <Windows.h> API for the SetConsoleCursorPosition() function.
static void GetUserChoiceFromQuitMenus(const std::vector< std::string > &p_menus)
Gets the user choice from the quit menu. All user choices result in a different custom exception bein...
static const uint32_t G_BATTLESHIPS_GRID_ELEMENT_HEIGHT
Battleships board attributes.
static const uint32_t G_TERMINAL_ALTERNATIVE_DOWN_ARROW_KEY
Keyboard values when getting user input other platforms.
static const uint32_t G_TERMINAL_ALTERNATIVE_LEFT_ARROW_KEY
Keyboard values when getting user input other platforms.
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_QUIT_MENU_QUIT_GAME_INDEX
Quit menu options.
static const uint32_t G_QUIT_MENU_QUIT_PROGRAM_INDEX
Quit menu options.
static const uint32_t G_BATTLESHIPS_GRID_TOP_PAD
Battleships board attributes.
static const uint32_t G_TERMINAL_ENTER_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_TERMINAL_RIGHT_ARROW_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_BATTLESHIPS_BOARD_WIDTH
Battleships board attributes.
static const uint32_t G_TICTACTOE_GRID_WIDTH
TicTacToe grid attributes.
static const uint32_t G_QUIT_MENU_QUIT_MAIN_MENU_INDEX
Quit menu options.
static const uint32_t G_TERMINAL_ALTERNATIVE_RIGHT_ARROW_KEY
Keyboard values when getting user input other platforms.
static const uint32_t G_TERMINAL_CURSOR_WIDTH_PERCENTAGE
The cursor width while running on windows.
static const uint32_t G_TICTACTOE_GRID_ELEMENT_HEIGHT
TicTacToe grid attributes.
static const uint32_t G_TERMINAL_ALTERNATIVE_BACKSPACE_KEY
Keyboard values when getting user input other platforms.
static const uint32_t G_TICTACTOE_GRID_LEFT_PAD
TicTacToe grid attributes.
static const uint32_t G_TERMINAL_LEFT_ARROW_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_BATTLESHIPS_GRID_ELEMENT_WIDTH
Battleships board attributes.
static const uint32_t G_TICTACTOE_GRID_TOP_PAD
TicTacToe grid attributes.
static const uint32_t G_QUIT_MENU_RESTART_GAME_INDEX
Quit menu options.
static const uint32_t G_TERMINAL_UP_ARROW_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_QUIT_MENU_CANCEL_INDEX
Quit menu options.
static const uint32_t G_TERMINAL_ALTERNATIVE_UP_ARROW_KEY
Keyboard values when getting user input other platforms.
static const uint32_t G_QUIT_MENU_RESET_GAME_INDEX
Quit menu options.
static const uint32_t G_BATTLESHIPS_GRID_PLAYER_ONE_BOARD_LEFT_PAD
Battleships board attributes.
static const uint32_t G_TICTACTOE_GRID_ELEMENT_WIDTH
TicTacToe grid attributes.
static const uint32_t G_BATTLESHIPS_GRID_PLAYER_TWO_BOARD_LEFT_PAD
Battleships board attributes.
static const uint32_t G_TERMINAL_RESTART_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_TERMINAL_DOWN_ARROW_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_TERMINAL_BACKSPACE_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_TERMINAL_ALTERNATIVE_ENTER_KEY
Keyboard values when getting user input other platforms.
static const uint32_t G_TERMINAL_QUIT_KEY
Keyboard values when getting user input on Windows.
static const uint32_t G_BATTLESHIPS_BOARD_HEIGHT
Battleships board attributes.
static const uint32_t G_TICTACTOE_GRID_HEIGHT
TicTacToe grid attributes.
Contains all Terminal-Games objects.
Pages
Represents the page types that are supported by PageBuilder.
@ TICTACTOE
Page supported by PageBuilder.
@ BATTLESHIPS
Page supported by PageBuilder.