Terminal Games
Simple games that run in the terminal.
Loading...
Searching...
No Matches
Game.hpp
1#pragma once
2
3#include "helpers/Globals.hpp"
4
9namespace TerminalGames
10{
15 class Game
16 {
17 public:
21 Game() = default;
22
26 virtual ~Game() = default;
27
31 virtual void Play() final
32 {
33 ResetGame();
34
35 while (true)
36 {
37 try
38 {
39 SetupGame();
40
42
44
45 while (!IsGameOver())
46 {
48 {
50 }
51
52 else
53 {
55 }
56
58
60 }
61
63
65
66 GameOver();
67 }
68
70 {
72 }
73
75 {
76 ResetGame();
77 }
78 }
79 }
80
86 Game(const Game& p_game) = delete;
87
93 Game(const Game&& p_game) = delete;
94
100 Game& operator=(const Game& p_game) = delete;
101
107 Game& operator=(const Game&& p_game) = delete;
108
109 private:
113 virtual void SetupGame() = 0;
114
118 virtual void GetUserOptions() = 0;
119
123 virtual void UpdateGameInformation() = 0;
124
130 virtual bool IsGameOver() = 0;
131
135 virtual void ToggleCurrentPlayer() = 0;
136
142 virtual bool IsCurrentTurnUsers() = 0;
143
147 virtual void ExecuteUserCommand() = 0;
148
152 virtual void ExecuteComputerCommand() = 0;
153
157 virtual void GameOver() = 0;
158
162 virtual void RestartGame() = 0;
163
167 virtual void ResetGame() = 0;
168 };
169}
Game(const Game &&p_game)=delete
Disable constructing a new Game object using move constructor.
virtual void ToggleCurrentPlayer()=0
Change the current player to the other player.
virtual ~Game()=default
Destructs the Game object.
Game & operator=(const Game &&p_game)=delete
Disable constructing a new Game object using move assignment operator.
virtual void ExecuteUserCommand()=0
Prompt the user to enter their command for the current turn.
virtual bool IsGameOver()=0
Check whether the game is over.
virtual void RestartGame()=0
Update variables to allow for the game to be restarted with the same user options.
Game & operator=(const Game &p_game)=delete
Disable constructing a new Game object using copy assignment operator.
virtual void ResetGame()=0
Update variables to allow for the game to be reset and so the user will be asked for new options.
virtual void UpdateGameInformation()=0
Updates GameInformation to match the current state of the game.
Game(const Game &p_game)=delete
Disable constructing a new Game object using copy constructor.
virtual void ExecuteComputerCommand()=0
Get a random command from the computer.
virtual void GetUserOptions()=0
Prompt the user for their choice on various game-related options.
Game()=default
Constructs a new Game object.
virtual bool IsCurrentTurnUsers()=0
Check whether the current turn should be executed by the user.
virtual void SetupGame()=0
Clears and sets all member variables to their game start default.
virtual void GameOver()=0
Display the game over message and prompt the user whether they would like to play again or quit the g...
virtual void Play() final
The main orchestration loop for all games.
Definition Game.hpp:31
Used to reset a game which prompts the user for new options.
Definition Globals.hpp:47
Used to restart a game with the same user options.
Definition Globals.hpp:54
Contains all Terminal-Games objects.