Terminal Games
Simple games that run in the terminal.
Loading...
Searching...
No Matches
Hangman.hpp
1#pragma once
2
3#include <cstdint>
4#include <random>
5#include <string>
6#include <vector>
7
8#include "games/Game.hpp"
9#include "helpers/GameInformation.hpp"
10#include "helpers/PageBuilder.hpp"
11
16namespace TerminalGames
17{
22 class Hangman : public Game
23 {
24 public:
30 explicit Hangman(const bool& p_useAnsiEscapeCodes);
31
32 private:
33 void SetupGame() override;
34
35 void GetUserOptions() override;
36
37 void UpdateGameInformation() override;
38
39 bool IsGameOver() override;
40
41 void ToggleCurrentPlayer() override;
42
43 bool IsCurrentTurnUsers() override;
44
49 void ExecuteUserCommand() override;
50
51 void ExecuteComputerCommand() override;
52
57 void GameOver() override;
58
59 void RestartGame() override;
60
61 void ResetGame() override;
62
67 void GetPlayerCount();
68
75
81 void GetComputerSpeed();
82
88 void GetWordFromUser();
89
94
101 void ExecuteGeneralCommand(const char& p_guess);
102
107
112
117 std::default_random_engine m_randomNumberGenerator;
118
122 std::vector<char> m_commandsRemaining;
123
127 std::vector<char> m_incorrectGuesses;
128
133
138
142 std::string m_playerCount;
143
148
152 std::string m_wordToBeGuessed;
153
158
162 uint32_t m_turnCount;
163
168
174
179
185 };
186}
Game()=default
Constructs a new Game object.
void GetWordFromComputer()
Gets a random word, from the word list loaded during the setup, when the computer is the word setter.
Definition Hangman.cpp:256
void GetUserPlayerChoice()
Prompts the user to select which player the will be playing the game as (only supported if playing ag...
Definition Hangman.cpp:201
uint32_t m_turnCount
The number of turns that have occurred.
Definition Hangman.hpp:162
void ToggleCurrentPlayer() override
Change the current player to the other player.
Definition Hangman.cpp:114
void UpdateGameInformation() override
Updates GameInformation to match the current state of the game.
Definition Hangman.cpp:80
void ExecuteUserCommand() override
Prompt the user to enter their command for the current turn.
Definition Hangman.cpp:121
bool IsGameOver() override
Check whether the game is over.
Definition Hangman.cpp:94
void SetupGame() override
Clears and sets all member variables to their game start default.
Definition Hangman.cpp:32
Hangman(const bool &p_useAnsiEscapeCodes)
Constructs a new Hangman object.
Definition Hangman.cpp:20
void GameOver() override
Display the game over message and prompt the user whether they would like to play again or quit the g...
Definition Hangman.cpp:176
void ExecuteComputerCommand() override
Get a random command from the computer.
Definition Hangman.cpp:165
uint32_t m_computerSpeed
The computer speed determined by the amount of seconds the computer must wait before executing it's c...
Definition Hangman.hpp:157
std::string m_userPlayerChoice
The choice of whether the user has selected to be the guesser or word setter.
Definition Hangman.hpp:147
void GetUserOptions() override
Prompt the user for their choice on various game-related options.
Definition Hangman.cpp:43
PageBuilder m_pageBuilder
Used to build pages required by the game.
Definition Hangman.hpp:106
bool m_isGameOver
Whether the game is over (true) or not (false).
Definition Hangman.hpp:178
void GetComputerSpeed()
Prompts the user to select how the speed of the computer decision making (this does not affect the di...
Definition Hangman.cpp:210
void RestartGame() override
Update variables to allow for the game to be restarted with the same user options.
Definition Hangman.cpp:181
void ResetGame() override
Update variables to allow for the game to be reset and so the user will be asked for new options.
Definition Hangman.cpp:186
GameInformation m_gameInformation
Used to package up the current state of the game so it can be used by m_pageBuilder.
Definition Hangman.hpp:111
std::string m_playerCount
The count of the user selected number of players.
Definition Hangman.hpp:142
std::vector< char > m_commandsRemaining
The letters which remain to be guessed.
Definition Hangman.hpp:122
std::default_random_engine m_randomNumberGenerator
Used to randomly select the word to be guessed from Globals::G_HANGMAN_COMPUTER_WORDS when the comput...
Definition Hangman.hpp:117
bool m_hasSavedGameOptions
Whether the user has selected all the game options (true) or not/partially (false)....
Definition Hangman.hpp:173
std::string m_currentGuessOfWord
The current guess state of the word to be guessed from the perspective of the guesser.
Definition Hangman.hpp:137
std::vector< char > m_incorrectGuesses
The letters which were guessed by the guesser and are incorrect.
Definition Hangman.hpp:127
bool IsCurrentTurnUsers() override
Check whether the current turn should be executed by the user.
Definition Hangman.cpp:116
void GetWordFromUser()
Prompts the user to enter a word to be guessed (whether the word is actually a word is not checked) w...
Definition Hangman.cpp:220
bool m_saveGameOptions
Whether to save the user's currently selected game options (true) and restart the game or not (false)...
Definition Hangman.hpp:184
std::string m_computerSpeedName
The name of the user selected computer speed.
Definition Hangman.hpp:132
std::string m_wordToBeGuessed
The word to be guessed by the guesser.
Definition Hangman.hpp:152
void ExecuteGeneralCommand(const char &p_guess)
Checks the single-letter guess against the word, updates the current guess of the word and the error ...
Definition Hangman.cpp:261
void GetPlayerCount()
Prompts the user to select how many players will be playing the game.
Definition Hangman.cpp:192
char m_currentLetterSelected
The letter to display to the user to represent what their current selected guess is.
Definition Hangman.hpp:167
Builds pages (i.e. strings) to be printed to the terminal.
Contains all Terminal-Games objects.
Used by game objects to package themselves into a format that can be used by PageBuilder to construct...