Terminal Games
Simple games that run in the terminal.
|
Implementation of the Tic-Tac-Toe game: https://en.wikipedia.org/wiki/Tic-tac-toe. More...
#include "TicTacToe.hpp"
Public Member Functions | |
TicTacToe (const bool &p_useAnsiEscapeCodes) | |
Constructs a new TicTacToe object. | |
virtual void | Play () final |
The main orchestration loop for all games. |
Private Member Functions | |
void | SetupGame () override |
Clears and sets all member variables to their game start default. | |
void | GetUserOptions () override |
Prompt the user for their choice on various game-related options. | |
void | UpdateGameInformation () override |
Updates GameInformation to match the current state of the game. | |
bool | IsGameOver () override |
Check whether the game is over. | |
void | ToggleCurrentPlayer () override |
Change the current player to the other player. | |
bool | IsCurrentTurnUsers () override |
Check whether the current turn should be executed by the user. | |
void | ExecuteUserCommand () override |
Prompt the user to enter their command for the current turn. | |
void | ExecuteComputerCommand () override |
Get a random command from the computer. | |
void | GameOver () override |
Display the game over message and prompt the user whether they would like to play again or quit the game. | |
void | RestartGame () override |
Update variables to allow for the game to be restarted with the same user options. | |
void | ResetGame () override |
Update variables to allow for the game to be reset and so the user will be asked for new options. | |
void | GetPlayerCount () |
Prompts the user to select how many players will be playing the game. | |
void | GetUserPlayerChoice () |
Prompts the user to select which player the will be playing the game as (only supported if playing against the computer). | |
void | GetComputerSpeed () |
Prompts the user to select how the speed of computer decision making (this does not affect the difficulty of the computer). | |
bool | ValidateCommand (const std::tuple< uint32_t, uint32_t > &p_command) |
Checks whether the command is valid. | |
void | ExecuteGeneralCommand (const std::tuple< uint32_t, uint32_t > &p_command) |
Executes the command against the game grid. |
Private Attributes | |
PageBuilder | m_pageBuilder |
Used to build pages required by the game. | |
GameInformation | m_gameInformation |
Used to package up the current state of the game so it can be used by m_pageBuilder. | |
std::default_random_engine | m_randomNumberGenerator |
Used to randomly choose the player to start the game and to randomly decide the computer's next command. | |
std::array< std::array< std::string, Globals::G_TICTACTOE_GRID_WIDTH >, Globals::G_TICTACTOE_GRID_HEIGHT > | m_gameGrid |
The Tic Tac Toe grid. | |
std::vector< std::tuple< uint32_t, uint32_t > > | m_commandsRemaining |
The grid <row, column> values that have not been chosen yet. | |
std::tuple< uint32_t, uint32_t > | m_previousCommand |
The previous grid <row, column> value that was chosen by the user. This is used to return the cursor to this position when the user is prompted to select their next command. | |
std::string | m_computerSpeedName |
The name of the user selected computer speed. | |
std::string | m_currentPlayer |
The name of the player whose turn it is. | |
std::string | m_playerCount |
The count of the user selected number of players. | |
std::string | m_userPlayerChoice |
The choice of which player the user has selected. | |
uint32_t | m_computerSpeed |
The computer speed determined by the amount of seconds the computer must wait before executing it's command. | |
uint32_t | m_turnCount |
The number of turns that have occurred. | |
bool | m_hasSavedGameOptions |
Whether the user has selected all the game options (true) or not/partially (false). This is used to determine whether to re-prompt the user to select the game options when restarting the game. | |
bool | m_hasWinner |
Whether the game has concluded with a winner (true) or whether it is a draw (false). | |
bool | m_saveGameOptions |
Whether to save the user's currently selected game options (true) and restart the game or not (false) and reset the game back to the initial state which will re-prompt the user for the game options. |
Implementation of the Tic-Tac-Toe game: https://en.wikipedia.org/wiki/Tic-tac-toe.
Definition at line 25 of file TicTacToe.hpp.
|
explicit |
Constructs a new TicTacToe object.
p_useAnsiEscapeCodes | Whether to use use ANSI escapes codes (true) or only extended ASCII characters (false). |
Definition at line 16 of file TicTacToe.cpp.
|
overrideprivatevirtual |
Clears and sets all member variables to their game start default.
Implements TerminalGames::Game.
Definition at line 27 of file TicTacToe.cpp.
|
overrideprivatevirtual |
Prompt the user for their choice on various game-related options.
Implements TerminalGames::Game.
Definition at line 45 of file TicTacToe.cpp.
|
overrideprivatevirtual |
Updates GameInformation to match the current state of the game.
Implements TerminalGames::Game.
Definition at line 71 of file TicTacToe.cpp.
|
overrideprivatevirtual |
Check whether the game is over.
Implements TerminalGames::Game.
Definition at line 83 of file TicTacToe.cpp.
|
overrideprivatevirtual |
Change the current player to the other player.
Implements TerminalGames::Game.
Definition at line 106 of file TicTacToe.cpp.
|
overrideprivatevirtual |
Check whether the current turn should be executed by the user.
Implements TerminalGames::Game.
Definition at line 111 of file TicTacToe.cpp.
|
overrideprivatevirtual |
Prompt the user to enter their command for the current turn.
Implements TerminalGames::Game.
Definition at line 116 of file TicTacToe.cpp.
|
overrideprivatevirtual |
Get a random command from the computer.
Implements TerminalGames::Game.
Definition at line 131 of file TicTacToe.cpp.
|
overrideprivatevirtual |
Display the game over message and prompt the user whether they would like to play again or quit the game.
Implements TerminalGames::Game.
Definition at line 145 of file TicTacToe.cpp.
|
overrideprivatevirtual |
Update variables to allow for the game to be restarted with the same user options.
Implements TerminalGames::Game.
Definition at line 150 of file TicTacToe.cpp.
|
overrideprivatevirtual |
Update variables to allow for the game to be reset and so the user will be asked for new options.
Implements TerminalGames::Game.
Definition at line 155 of file TicTacToe.cpp.
|
private |
Prompts the user to select how many players will be playing the game.
Definition at line 161 of file TicTacToe.cpp.
|
private |
Prompts the user to select which player the will be playing the game as (only supported if playing against the computer).
Definition at line 170 of file TicTacToe.cpp.
|
private |
Prompts the user to select how the speed of computer decision making (this does not affect the difficulty of the computer).
Definition at line 179 of file TicTacToe.cpp.
|
private |
Checks whether the command is valid.
p_command | The command in the form of <row, column>. |
Definition at line 189 of file TicTacToe.cpp.
|
private |
Executes the command against the game grid.
p_command | The command in the form of <row, column>. |
Definition at line 196 of file TicTacToe.cpp.
|
inlinefinalvirtualinherited |
|
private |
Used to build pages required by the game.
Definition at line 107 of file TicTacToe.hpp.
|
private |
Used to package up the current state of the game so it can be used by m_pageBuilder.
Definition at line 112 of file TicTacToe.hpp.
|
private |
Used to randomly choose the player to start the game and to randomly decide the computer's next command.
Definition at line 117 of file TicTacToe.hpp.
|
private |
The Tic Tac Toe grid.
Definition at line 122 of file TicTacToe.hpp.
|
private |
The grid <row, column> values that have not been chosen yet.
Definition at line 127 of file TicTacToe.hpp.
|
private |
The previous grid <row, column> value that was chosen by the user. This is used to return the cursor to this position when the user is prompted to select their next command.
Definition at line 133 of file TicTacToe.hpp.
|
private |
The name of the user selected computer speed.
Definition at line 138 of file TicTacToe.hpp.
|
private |
The name of the player whose turn it is.
Definition at line 143 of file TicTacToe.hpp.
|
private |
The count of the user selected number of players.
Definition at line 148 of file TicTacToe.hpp.
|
private |
The choice of which player the user has selected.
Definition at line 153 of file TicTacToe.hpp.
|
private |
The computer speed determined by the amount of seconds the computer must wait before executing it's command.
Definition at line 158 of file TicTacToe.hpp.
|
private |
The number of turns that have occurred.
Definition at line 163 of file TicTacToe.hpp.
|
private |
Whether the user has selected all the game options (true) or not/partially (false). This is used to determine whether to re-prompt the user to select the game options when restarting the game.
Definition at line 169 of file TicTacToe.hpp.
|
private |
Whether the game has concluded with a winner (true) or whether it is a draw (false).
Definition at line 174 of file TicTacToe.hpp.
|
private |
Whether to save the user's currently selected game options (true) and restart the game or not (false) and reset the game back to the initial state which will re-prompt the user for the game options.
Definition at line 180 of file TicTacToe.hpp.