8#include <unordered_map>
11#include "games/Game.hpp"
12#include "helpers/GameInformation.hpp"
13#include "helpers/Globals.hpp"
14#include "helpers/PageBuilder.hpp"
34 explicit Battleships(
const bool& p_useAnsiEscapeCodes);
100 const std::vector<std::tuple<uint32_t, uint32_t>>& p_currentShipPositions,
101 const std::tuple<uint32_t, uint32_t>& p_selectedShipGridLocation,
102 bool& p_shipIsHorizontal,
103 bool& p_shipIsVertical);
130 const std::vector<std::tuple<uint32_t, uint32_t>>& p_commandsRemaining,
131 const std::tuple<uint32_t, uint32_t>& p_command);
143 std::unordered_map<std::string, uint32_t>& p_opponentShipsRemaining,
144 std::vector<std::tuple<uint32_t, uint32_t>>& p_commandsRemaining,
145 const std::tuple<uint32_t, uint32_t>& p_command);
void ResetGame() override
Update variables to allow for the game to be reset and so the user will be asked for new options.
void ExecuteComputerCommand() override
Get a random command from the computer.
uint32_t m_turnCount
The number of turns that have occurred.
std::unordered_map< std::string, uint32_t > m_shipsRemainingPlayerOne
The respective player's health of each their ships.
bool IsCurrentTurnUsers() override
Check whether the current turn should be executed by the user.
std::vector< std::tuple< uint32_t, uint32_t > > m_commandsRemainingPlayerOne
The respective player's board <row, column> values they have not chosen yet.
GameInformation m_gameInformation
Used to package up the current state of the game so it can be used by m_pageBuilder.
std::string m_playerCount
The count of the user selected number of players.
std::tuple< uint32_t, uint32_t > m_previousCommand
The previous board <row, column> value that was chosen by the user. This is used to return the cursor...
Battleships(const bool &p_useAnsiEscapeCodes)
Constructs a new Battleships object.
void UpdateGameInformation() override
Updates GameInformation to match the current state of the game.
void GameOver() override
Display the game over message and prompt the user whether they would like to play again or quit the g...
PageBuilder m_pageBuilder
Used to build pages required by the game.
void ExecuteUserCommand() override
Prompt the user to enter their command for the current turn.
void ExecuteGeneralCommand(std::array< std::array< std::string, Globals::G_BATTLESHIPS_BOARD_WIDTH >, Globals::G_BATTLESHIPS_BOARD_HEIGHT > &p_opponentBoard, std::unordered_map< std::string, uint32_t > &p_opponentShipsRemaining, std::vector< std::tuple< uint32_t, uint32_t > > &p_commandsRemaining, const std::tuple< uint32_t, uint32_t > &p_command)
Executes the command on the opponent's board and updates their own board and commands remaining.
void RestartGame() override
Update variables to allow for the game to be restarted with the same user options.
void GetPlayerCount()
Prompts the user to select how many players will be playing the game.
bool m_isGameOver
Whether the game is over (true) or not (false).
std::unordered_map< std::string, uint32_t > m_shipsRemainingPlayerTwo
The respective player's health of each their ships.
std::array< std::array< std::string, Globals::G_BATTLESHIPS_BOARD_WIDTH >, Globals::G_BATTLESHIPS_BOARD_HEIGHT > m_boardPlayerTwo
The current state of the respective player's board.
void GetUserShipPositions()
Prompt the user to place all ships on the board.
std::array< std::array< std::string, Globals::G_BATTLESHIPS_BOARD_WIDTH >, Globals::G_BATTLESHIPS_BOARD_HEIGHT > m_boardPlayerOne
The current state of the respective player's board.
static bool ValidateCommand(const std::vector< std::tuple< uint32_t, uint32_t > > &p_commandsRemaining, const std::tuple< uint32_t, uint32_t > &p_command)
Checks whether the command is valid.
void GetComputerSpeed()
Prompts the user to select how the speed of the computer decision making (this does not affect the di...
std::vector< std::tuple< uint32_t, uint32_t > > m_commandsRemainingPlayerTwo
The respective player's board <row, column> values they have not chosen yet.
void SetupGame() override
Clears and sets all member variables to their game start default.
std::string m_currentPlayer
The name of the player whose turn it is.
void GetRandomShipPositions(std::array< std::array< std::string, Globals::G_BATTLESHIPS_BOARD_WIDTH >, Globals::G_BATTLESHIPS_BOARD_HEIGHT > &p_board)
Randomly place all ships on the board and is used to place the computer's ships.
bool IsGameOver() override
Check whether the game is over.
static bool IsShipPresent(std::array< std::array< std::string, Globals::G_BATTLESHIPS_BOARD_WIDTH >, Globals::G_BATTLESHIPS_BOARD_HEIGHT > &p_board)
Checks whether at least a single ship is present on a game board.
std::string m_computerSpeedName
The name of the user selected computer speed.
void ToggleCurrentPlayer() override
Change the current player to the other player.
uint32_t m_computerSpeed
The computer speed determined by the amount of seconds the computer must wait before executing it's c...
bool m_saveGameOptions
Whether to save the user's currently selected game options (true) and restart the game or not (false)...
bool ValidateUserShipPosition(const std::vector< std::tuple< uint32_t, uint32_t > > &p_currentShipPositions, const std::tuple< uint32_t, uint32_t > &p_selectedShipGridLocation, bool &p_shipIsHorizontal, bool &p_shipIsVertical)
Validates whether (true) or not (false) p_selectedShipGridLocation is a valid grid location to place ...
void GetUserOptions() override
Prompt the user for their choice on various game-related options.
bool m_hasSavedGameOptions
Whether the user has selected all the game options (true) or not/partially (false)....
std::default_random_engine m_randomNumberGenerator
Used to randomly select ships positions for the computer and randomly select board <row,...
Game()=default
Constructs a new Game object.
Builds pages (i.e. strings) to be printed to the terminal.
static const uint32_t G_BATTLESHIPS_BOARD_HEIGHT
Battleships board attributes.
Contains all Terminal-Games objects.