Terminal Games
Simple games that run in the terminal.
|
Implementation of the Hangman game: https://en.wikipedia.org/wiki/Hangman_(game) More...
#include "Hangman.hpp"
Public Member Functions | |
Hangman (const bool &p_useAnsiEscapeCodes) | |
Constructs a new Hangman 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 the computer decision making (this does not affect the difficulty of the computer). | |
void | GetWordFromUser () |
Prompts the user to enter a word to be guessed (whether the word is actually a word is not checked) when the user is the word setter. | |
void | GetWordFromComputer () |
Gets a random word, from the word list loaded during the setup, when the computer is the word setter. | |
void | ExecuteGeneralCommand (const char &p_guess) |
Checks the single-letter guess against the word, updates the current guess of the word and the error count depending upon if the guess if correct. |
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 select the word to be guessed from Globals::G_HANGMAN_COMPUTER_WORDS when the computer is the word setter and used to randomly select a letter to guess when the computer is the guesser. | |
std::vector< char > | m_commandsRemaining |
The letters which remain to be guessed. | |
std::vector< char > | m_incorrectGuesses |
The letters which were guessed by the guesser and are incorrect. | |
std::string | m_computerSpeedName |
The name of the user selected computer speed. | |
std::string | m_currentGuessOfWord |
The current guess state of the word to be guessed from the perspective of the guesser. | |
std::string | m_playerCount |
The count of the user selected number of players. | |
std::string | m_userPlayerChoice |
The choice of whether the user has selected to be the guesser or word setter. | |
std::string | m_wordToBeGuessed |
The word to be guessed by the guesser. | |
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. | |
char | m_currentLetterSelected |
The letter to display to the user to represent what their current selected guess is. | |
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_isGameOver |
Whether the game is over (true) or not (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 Hangman game: https://en.wikipedia.org/wiki/Hangman_(game)
Definition at line 22 of file Hangman.hpp.
|
explicit |
Constructs a new Hangman object.
p_useAnsiEscapeCodes | Whether to use use ANSI escapes codes (true) or only extended ASCII characters (false). |
Definition at line 20 of file Hangman.cpp.
|
overrideprivatevirtual |
Clears and sets all member variables to their game start default.
Implements TerminalGames::Game.
Definition at line 32 of file Hangman.cpp.
|
overrideprivatevirtual |
Prompt the user for their choice on various game-related options.
Implements TerminalGames::Game.
Definition at line 43 of file Hangman.cpp.
|
overrideprivatevirtual |
Updates GameInformation to match the current state of the game.
Implements TerminalGames::Game.
Definition at line 80 of file Hangman.cpp.
|
overrideprivatevirtual |
Check whether the game is over.
Implements TerminalGames::Game.
Definition at line 94 of file Hangman.cpp.
|
overrideprivatevirtual |
Change the current player to the other player.
Implements TerminalGames::Game.
Definition at line 114 of file Hangman.cpp.
|
overrideprivatevirtual |
Check whether the current turn should be executed by the user.
Implements TerminalGames::Game.
Definition at line 116 of file Hangman.cpp.
|
overrideprivatevirtual |
Prompt the user to enter their command for the current turn.
Implements TerminalGames::Game.
Definition at line 121 of file Hangman.cpp.
|
overrideprivatevirtual |
Get a random command from the computer.
Implements TerminalGames::Game.
Definition at line 165 of file Hangman.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 176 of file Hangman.cpp.
|
overrideprivatevirtual |
Update variables to allow for the game to be restarted with the same user options.
Implements TerminalGames::Game.
Definition at line 181 of file Hangman.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 186 of file Hangman.cpp.
|
private |
Prompts the user to select how many players will be playing the game.
Definition at line 192 of file Hangman.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 201 of file Hangman.cpp.
|
private |
Prompts the user to select how the speed of the computer decision making (this does not affect the difficulty of the computer).
Definition at line 210 of file Hangman.cpp.
|
private |
Prompts the user to enter a word to be guessed (whether the word is actually a word is not checked) when the user is the word setter.
Definition at line 220 of file Hangman.cpp.
|
private |
Gets a random word, from the word list loaded during the setup, when the computer is the word setter.
Definition at line 256 of file Hangman.cpp.
|
private |
Checks the single-letter guess against the word, updates the current guess of the word and the error count depending upon if the guess if correct.
p_guess | A single-letter to check against the word to be guessed. |
Definition at line 261 of file Hangman.cpp.
|
inlinefinalvirtualinherited |
|
private |
Used to build pages required by the game.
Definition at line 106 of file Hangman.hpp.
|
private |
Used to package up the current state of the game so it can be used by m_pageBuilder.
Definition at line 111 of file Hangman.hpp.
|
private |
Used to randomly select the word to be guessed from Globals::G_HANGMAN_COMPUTER_WORDS when the computer is the word setter and used to randomly select a letter to guess when the computer is the guesser.
Definition at line 117 of file Hangman.hpp.
|
private |
The letters which remain to be guessed.
Definition at line 122 of file Hangman.hpp.
|
private |
The letters which were guessed by the guesser and are incorrect.
Definition at line 127 of file Hangman.hpp.
|
private |
The name of the user selected computer speed.
Definition at line 132 of file Hangman.hpp.
|
private |
The current guess state of the word to be guessed from the perspective of the guesser.
Definition at line 137 of file Hangman.hpp.
|
private |
The count of the user selected number of players.
Definition at line 142 of file Hangman.hpp.
|
private |
The choice of whether the user has selected to be the guesser or word setter.
Definition at line 147 of file Hangman.hpp.
|
private |
The word to be guessed by the guesser.
Definition at line 152 of file Hangman.hpp.
|
private |
The computer speed determined by the amount of seconds the computer must wait before executing it's command.
Definition at line 157 of file Hangman.hpp.
|
private |
The number of turns that have occurred.
Definition at line 162 of file Hangman.hpp.
|
private |
The letter to display to the user to represent what their current selected guess is.
Definition at line 167 of file Hangman.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 173 of file Hangman.hpp.
|
private |
Whether the game is over (true) or not (false).
Definition at line 178 of file Hangman.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 184 of file Hangman.hpp.