Terminal Games
Simple games that run in the terminal.
Loading...
Searching...
No Matches
Terminal.hpp
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <tuple>
6#include <vector>
7
8#include "helpers/GameInformation.hpp"
9#include "helpers/PageBuilder.hpp"
10
15namespace TerminalGames
16{
22 {
23 public:
27 Terminal() = delete;
28
39 static bool GetUserChoiceFromHomepage(const std::vector<std::string>& p_menus, const bool& p_useAnsiEscapeCodes);
40
49 static uint32_t GetUserChoiceFromMainMenus(const std::vector<std::string>& p_menus);
50
64 static uint32_t GetUserChoiceFromGameMenus(const std::vector<std::string>& p_menus, const std::vector<std::string>& p_quitOptionMenus);
65
84 static std::tuple<uint32_t, uint32_t> GetUserCommandFromGameGrid(
85 const std::tuple<uint32_t, uint32_t>& p_startingGridLocation,
86 const PageBuilder& p_pageBuilder,
87 const GameInformation& p_gameInformation,
88 const bool& p_displayGetUserCommandPage);
89
107 static std::tuple<uint32_t, uint32_t> GetUserCommandFromGameGridWindows(
108 const std::tuple<uint32_t, uint32_t>& p_startingGridLocation,
109 const PageBuilder& p_pageBuilder,
110 const GameInformation& p_gameInformation,
111 const bool& p_displayGetUserCommandPage);
112
130 static std::tuple<uint32_t, uint32_t> GetUserCommandFromGameGridNonWindows(
131 const std::tuple<uint32_t, uint32_t>& p_startingGridLocation,
132 const PageBuilder& p_pageBuilder,
133 const GameInformation& p_gameInformation,
134 const bool& p_displayGetUserCommandPage);
135
150 static void GetUserChoiceFromGameOverMenu(const std::string& p_gameOverPage, const std::vector<std::string>& p_quitOptionMenus);
151
163 static void GetUserChoiceFromQuitMenus(const std::vector<std::string>& p_menus);
164
170 static void PrintOutput(const std::string& p_output);
171
175 static void Clear();
176
182 static uint32_t GetNextKeyPress();
183
189 static void SetCursorVisibility(const bool& p_cursorVisibility);
190
197 static void SetCursorPosition(const int16_t& p_xCoord, const int16_t& p_yCoord);
198
202 static void InitialiseTerminal();
203
207 static void ResetTerminal();
208 };
209}
Builds pages (i.e. strings) to be printed to the terminal.
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...
Definition Terminal.cpp:311
static void SetCursorVisibility(const bool &p_cursorVisibility)
Wrapper around the <Windows.h> API for the SetConsoleCursorInfo() function.
Definition Terminal.cpp:473
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.
Definition Terminal.cpp:128
static uint32_t GetNextKeyPress()
Wrapper for <Windows.h> API for the FlushConsoleInputBuffer() and _getch() functions.
Definition Terminal.cpp:429
static void PrintOutput(const std::string &p_output)
Clears and then prints to the terminal.
Definition Terminal.cpp:381
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.
Definition Terminal.cpp:83
static void ResetTerminal()
Resets the terminal to its original state before the program was run.
Definition Terminal.cpp:495
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.
Definition Terminal.cpp:53
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.
Definition Terminal.cpp:220
static void Clear()
Clears the terminal based on this article: https://www.cplusplus.com/articles/4z18T05o.
Definition Terminal.cpp:387
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-...
Definition Terminal.cpp:114
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.
Definition Terminal.cpp:21
static void InitialiseTerminal()
Initialises the terminal for the program.
Definition Terminal.cpp:489
static void SetCursorPosition(const int16_t &p_xCoord, const int16_t &p_yCoord)
Wrapper around the <Windows.h> API for the SetConsoleCursorPosition() function.
Definition Terminal.cpp:481
Terminal()=delete
Disable constructing a Terminal object.
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...
Definition Terminal.cpp:332
Contains all Terminal-Games objects.
Used by game objects to package themselves into a format that can be used by PageBuilder to construct...