Terminal Games
Simple games that run in the terminal.
|
Handles all terminal related tasks such as getting user input, outputting to the terminal, clearing the terminal, etc. More...
#include "Terminal.hpp"
Public Member Functions | |
Terminal ()=delete | |
Disable constructing a Terminal object. |
Static Public Member Functions | |
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 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 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 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-specific GetUserCommandFromGameGrid() functions as the Windows variant uses Windows.h). | |
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 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 | 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 GetUserChoiceFromQuitMenus() 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 being thrown except for the "Cancel" option which results in the function returning normally. | |
static void | PrintOutput (const std::string &p_output) |
Clears and then prints to the terminal. | |
static void | Clear () |
Clears the terminal based on this article: https://www.cplusplus.com/articles/4z18T05o. | |
static uint32_t | GetNextKeyPress () |
Wrapper for <Windows.h> API for the FlushConsoleInputBuffer() and _getch() functions. | |
static void | SetCursorVisibility (const bool &p_cursorVisibility) |
Wrapper around the <Windows.h> API for the SetConsoleCursorInfo() function. | |
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 | InitialiseTerminal () |
Initialises the terminal for the program. | |
static void | ResetTerminal () |
Resets the terminal to its original state before the program was run. |
Handles all terminal related tasks such as getting user input, outputting to the terminal, clearing the terminal, etc.
Definition at line 21 of file Terminal.hpp.
|
static |
Get the user choice from a list of homepage screens that are printed to the terminal.
p_menus | An array of screens used to print the current option selected to the terminal. The screen chosen depends on user input. The only difference between each screen is the selected option. |
p_useAnsiEscapeCodes | Whether to use use ANSI escapes codes (true) or only extended ASCII characters (false). |
Globals::Exceptions::QuitProgram | When the user presses the Globals::G_TERMINAL_QUIT_KEY. |
Definition at line 21 of file Terminal.cpp.
|
static |
Get the user choice from a list of main menus screens that are printed to the terminal.
p_menus | An array of screens used to print the current option selected to the terminal. The screen chosen depends on user input. The only difference between each screen is the selected option. |
Globals::Exceptions::QuitMainMenu | When the user presses the Globals::G_TERMINAL_QUIT_KEY. |
Definition at line 53 of file Terminal.cpp.
|
static |
Get the user choice from a list of game menus screens that are printed to the terminal.
p_menus | An array of screens used to print the current option selected to the terminal. The screen chosen depends on user input. The only difference between each screen is the selected option. |
p_quitOptionMenus | The quit option selection screens returned from PageBuilder::GetQuitOptionSelectionPage(). |
Globals::Exceptions::RestartGame | When the user selects the restart game option from the quit menu. |
Globals::Exceptions::ResetGame | When the user selects the reset game option from the quit menu. |
Globals::Exceptions::QuitGame | When the user selects the quit game option from the quit menu. |
Globals::Exceptions::QuitMainMenu | When the user selects the quit to main menu option from the quit menu. |
Globals::Exceptions::QuitProgram | When the user selects the quit program option from the quit menu. |
Definition at line 83 of file Terminal.cpp.
|
static |
Gets a user command based on the currently displayed game grid (wrapper function around the platform-specific GetUserCommandFromGameGrid() functions as the Windows variant uses Windows.h).
p_startingGridLocation | The initial row and column to place the cursor. |
p_pageBuilder | The PageBuilder object to allow for refreshing the terminal based on user input. |
p_gameInformation | The GameInformation object to pass to the PageBuilder object. |
p_displayGetUserCommandPage | Whether to display the get user command page. |
Globals::Exceptions::NotImplementedError | When the user passes a PageBuilder with a page type not supported by this function. |
Globals::Exceptions::BackspaceKeyPressed | When the user presses the Globals::G_TERMINAL_BACKSPACE_KEY. |
Globals::Exceptions::RestartGame | When the user selects the restart game option from the quit menu. |
Globals::Exceptions::ResetGame | When the user selects the reset game option from the quit menu. |
Globals::Exceptions::QuitGame | When the user selects the quit game option from the quit menu. |
Globals::Exceptions::QuitMainMenu | When the user selects the quit to main menu option from the quit menu. |
Globals::Exceptions::QuitProgram | When the user selects the quit program option from the quit menu. |
Definition at line 114 of file Terminal.cpp.
|
static |
(Windows) Gets a user command based on the currently displayed game grid.
p_startingGridLocation | The initial row and column to place the cursor. |
p_pageBuilder | The PageBuilder object to allow for refreshing the terminal based on user input. |
p_gameInformation | The GameInformation object to pass to the PageBuilder object. |
p_displayGetUserCommandPage | Whether to display the get user command page. |
Globals::Exceptions::NotImplementedError | When the user passes a PageBuilder with a page type not supported by this function. |
Globals::Exceptions::BackspaceKeyPressed | When the user presses the Globals::G_TERMINAL_BACKSPACE_KEY. |
Globals::Exceptions::RestartGame | When the user selects the restart game option from the quit menu. |
Globals::Exceptions::ResetGame | When the user selects the reset game option from the quit menu. |
Globals::Exceptions::QuitGame | When the user selects the quit game option from the quit menu. |
Globals::Exceptions::QuitMainMenu | When the user selects the quit to main menu option from the quit menu. |
Globals::Exceptions::QuitProgram | When the user selects the quit program option from the quit menu. |
Definition at line 128 of file Terminal.cpp.
|
static |
(Non-window) Gets a user command based on the currently displayed game grid.
p_startingGridLocation | The initial row and column to place the cursor. |
p_pageBuilder | The PageBuilder object to allow for refreshing the terminal based on user input. |
p_gameInformation | The GameInformation object to pass to the PageBuilder object. |
p_displayGetUserCommandPage | Whether to display the get user command page. |
Globals::Exceptions::NotImplementedError | When the user passes a PageBuilder with a page type not supported by this function. |
Globals::Exceptions::BackspaceKeyPressed | When the user presses the Globals::G_TERMINAL_BACKSPACE_KEY. |
Globals::Exceptions::RestartGame | When the user selects the restart game option from the quit menu. |
Globals::Exceptions::ResetGame | When the user selects the reset game option from the quit menu. |
Globals::Exceptions::QuitGame | When the user selects the quit game option from the quit menu. |
Globals::Exceptions::QuitMainMenu | When the user selects the quit to main menu option from the quit menu. |
Globals::Exceptions::QuitProgram | When the user selects the quit program option from the quit menu. |
Definition at line 220 of file Terminal.cpp.
|
static |
Get the user choice whether to restart the game, reset the game or a choice from the GetUserChoiceFromQuitMenus() function.
p_gameOverPage | The game over page to display returned from PageBuilder::GetGameOverPage(). |
p_quitOptionMenus | The quit option selection pages returned from PageBuilder::GetQuitOptionSelectionPage(). |
Globals::Exceptions::RestartGame | When the user presses the Globals::G_TERMINAL_RESTART_KEY or when the user selects the restart game option for the quit menu. |
Globals::Exceptions::ResetGame | When the user presses any key other than the Globals::G_TERMINAL_RESTART_KEY or when the user selects the reset game option from the quit menu. |
Globals::Exceptions::QuitGame | When the user selects the quit game option from the quit menu. |
Globals::Exceptions::QuitMainMenu | When the user selects the quit to main menu option from the quit menu. |
Globals::Exceptions::QuitProgram | When the user selects the quit program option from the quit menu. |
Definition at line 311 of file Terminal.cpp.
|
static |
Gets the user choice from the quit menu. All user choices result in a different custom exception being thrown except for the "Cancel" option which results in the function returning normally.
p_menus | The quit option selection pages returned from PageBuilder::GetQuitOptionSelectionPage(). |
Globals::Exceptions::RestartGame | When the user selects the restart game option. |
Globals::Exceptions::ResetGame | When the user selects the reset game option. |
Globals::Exceptions::QuitGame | When the user selects the quit game option. |
Globals::Exceptions::QuitMainMenu | When the user selects the quit to main menu option. |
Globals::Exceptions::QuitProgram | When the user selects the quit program option. |
Definition at line 332 of file Terminal.cpp.
|
static |
Clears and then prints to the terminal.
p_output | The string to output to the terminal. |
Definition at line 381 of file Terminal.cpp.
|
static |
Clears the terminal based on this article: https://www.cplusplus.com/articles/4z18T05o.
Definition at line 387 of file Terminal.cpp.
|
static |
Wrapper for <Windows.h> API for the FlushConsoleInputBuffer() and _getch() functions.
Definition at line 429 of file Terminal.cpp.
|
static |
Wrapper around the <Windows.h> API for the SetConsoleCursorInfo() function.
p_cursorVisibility | Whether the cursor should be visible (true) or not (false). |
Definition at line 473 of file Terminal.cpp.
|
static |
Wrapper around the <Windows.h> API for the SetConsoleCursorPosition() function.
p_xCoord | The horizontal position to set the cursor to. |
p_yCoord | The vertical position to set the cursor to. |
Definition at line 481 of file Terminal.cpp.
|
static |
Initialises the terminal for the program.
Definition at line 489 of file Terminal.cpp.
|
static |
Resets the terminal to its original state before the program was run.
Definition at line 495 of file Terminal.cpp.