MiniGame-Madness
Public Member Functions | Public Attributes | List of all members
Player Class Reference

Represents a player in the game. More...

#include <BattleshipGame.h>

Public Member Functions

 Player ()
 Constructs a Player with an empty grid and no ships.
 
void displayGrid (bool revealShips, ScreenBuffer *screenBuffer, int startX=0, int startY=0)
 Displays the player's grid. More...
 
bool placeShip (Ship &ship, int row, int col, bool horizontal)
 Places a ship on the player's grid. More...
 
void autoPlaceShips (std::vector< Ship > &ships)
 Automatically places all ships on the player's grid. More...
 
bool isGameOver () const
 Checks if the game is over for the player (i.e., all ships are sunk). More...
 
void playerTurn (Player &opponent, ScreenBuffer *screenBuffer, std::function< std::string()> inputProvider=nullptr)
 The player's turn to attack the opponent. More...
 
void aiTurn (Player &opponent, ScreenBuffer *screenBuffer, std::function< std::string()> inputProvider=nullptr)
 The AI's turn to attack the opponent. More...
 
void setupGame (bool isAI, ScreenBuffer *screenBuffer, std::function< std::string()> inputProvider=nullptr)
 Sets up the player's ships on the grid. More...
 
void showBoards (Player &opponent, ScreenBuffer *screenBuffer)
 Shows the player's and opponent's boards. More...
 
virtual std::pair< int, int > getAIShot ()
 Generates a shot for the AI player. More...
 

Public Attributes

std::vector< std::vector< CellState > > grid
 The player's grid.
 
std::vector< Shipships
 The ships owned by the player.
 

Detailed Description

Represents a player in the game.

Member Function Documentation

◆ aiTurn()

void Player::aiTurn ( Player opponent,
ScreenBuffer screenBuffer,
std::function< std::string()>  inputProvider = nullptr 
)

The AI's turn to attack the opponent.

Parameters
opponentThe opponent being attacked.
screenBufferPointer to the ScreenBuffer for output.
inputProviderFunction to provide input for testing purposes.

◆ autoPlaceShips()

void Player::autoPlaceShips ( std::vector< Ship > &  ships)

Automatically places all ships on the player's grid.

Parameters
shipsThe ships to be placed.

◆ displayGrid()

void Player::displayGrid ( bool  revealShips,
ScreenBuffer screenBuffer,
int  startX = 0,
int  startY = 0 
)

Displays the player's grid.

Parameters
revealShipsIf true, ships will be shown on the grid.
screenBufferPointer to the ScreenBuffer for output.
startXThe starting X position for display.
startYThe starting Y position for display.

◆ getAIShot()

std::pair< int, int > Player::getAIShot ( )
virtual

Generates a shot for the AI player.

Returns
A pair of integers representing the row and column of the shot.

◆ isGameOver()

bool Player::isGameOver ( ) const

Checks if the game is over for the player (i.e., all ships are sunk).

Returns
True if the game is over; otherwise, false.

◆ placeShip()

bool Player::placeShip ( Ship ship,
int  row,
int  col,
bool  horizontal 
)

Places a ship on the player's grid.

Parameters
shipThe ship to place.
rowThe starting row for the ship.
colThe starting column for the ship.
horizontalIf true, the ship is placed horizontally; otherwise, vertically.
Returns
True if the ship was placed successfully; otherwise, false.

◆ playerTurn()

void Player::playerTurn ( Player opponent,
ScreenBuffer screenBuffer,
std::function< std::string()>  inputProvider = nullptr 
)

The player's turn to attack the opponent.

Parameters
opponentThe opponent being attacked.
screenBufferPointer to the ScreenBuffer for input/output.
inputProviderFunction to provide input for testing purposes.

◆ setupGame()

void Player::setupGame ( bool  isAI,
ScreenBuffer screenBuffer,
std::function< std::string()>  inputProvider = nullptr 
)

Sets up the player's ships on the grid.

Parameters
isAIIf true, the setup is for an AI player; otherwise, it's for a human player.
screenBufferPointer to the ScreenBuffer for input/output.
inputProviderFunction to provide input for testing purposes.

◆ showBoards()

void Player::showBoards ( Player opponent,
ScreenBuffer screenBuffer 
)

Shows the player's and opponent's boards.

Parameters
opponentThe opponent's board.
screenBufferPointer to the ScreenBuffer for output.

The documentation for this class was generated from the following files: