Represents a player in the game.
More...
#include <BattleshipGame.h>
|
| 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...
|
|
|
std::vector< std::vector< CellState > > | grid |
| The player's grid.
|
|
std::vector< Ship > | ships |
| The ships owned by the player.
|
|
Represents a player in the game.
◆ aiTurn()
void Player::aiTurn |
( |
Player & |
opponent, |
|
|
ScreenBuffer * |
screenBuffer, |
|
|
std::function< std::string()> |
inputProvider = nullptr |
|
) |
| |
The AI's turn to attack the opponent.
- Parameters
-
opponent | The opponent being attacked. |
screenBuffer | Pointer to the ScreenBuffer for output. |
inputProvider | Function to provide input for testing purposes. |
◆ autoPlaceShips()
void Player::autoPlaceShips |
( |
std::vector< Ship > & |
ships | ) |
|
Automatically places all ships on the player's grid.
- Parameters
-
ships | The ships to be placed. |
◆ displayGrid()
void Player::displayGrid |
( |
bool |
revealShips, |
|
|
ScreenBuffer * |
screenBuffer, |
|
|
int |
startX = 0 , |
|
|
int |
startY = 0 |
|
) |
| |
Displays the player's grid.
- Parameters
-
revealShips | If true, ships will be shown on the grid. |
screenBuffer | Pointer to the ScreenBuffer for output. |
startX | The starting X position for display. |
startY | The 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
-
ship | The ship to place. |
row | The starting row for the ship. |
col | The starting column for the ship. |
horizontal | If 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
-
opponent | The opponent being attacked. |
screenBuffer | Pointer to the ScreenBuffer for input/output. |
inputProvider | Function 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
-
isAI | If true, the setup is for an AI player; otherwise, it's for a human player. |
screenBuffer | Pointer to the ScreenBuffer for input/output. |
inputProvider | Function to provide input for testing purposes. |
◆ showBoards()
Shows the player's and opponent's boards.
- Parameters
-
opponent | The opponent's board. |
screenBuffer | Pointer to the ScreenBuffer for output. |
The documentation for this class was generated from the following files: