TheCOSCGameProject  1.0
Public Member Functions | List of all members
BlackJack Class Reference

Implements the BlackJack mini-game. More...

#include <minigames.h>

Inheritance diagram for BlackJack:
Inheritance graph
[legend]
Collaboration diagram for BlackJack:
Collaboration graph
[legend]

Public Member Functions

 BlackJack ()
 Constructor for the BlackJack game. More...
 
int evaluate (bool hit)
 Evaluates the player's hand. More...
 
void displayState (bool printAll)
 Displays the current state of the game. More...
 
const int * getDealer () const
 Gets the dealer's hand. More...
 
void setDealer (const int newDealer[2])
 Sets the dealer's hand. More...
 
const std::vector< int > & getPlayerCards () const
 Gets the player's hand. More...
 
void setPlayerCards (const std::vector< int > &newPlayerCards)
 Sets the player's hand. More...
 
bool start () override
 Starts the BlackJack game. More...
 
std::string getGameName () override
 Gets the name of the game. More...
 
int initializeGame ()
 Initializes the game state. More...
 
bool handlePlayerTurn ()
 Handles a single player turn. More...
 
void updateGameState (bool won, int rounds, int totalWins, int maxRounds, bool wasHit)
 Updates the game state based on the result of a round. More...
 
bool endGame (bool won)
 Handles the end of the game. More...
 
- Public Member Functions inherited from Game
virtual ~Game ()
 Virtual destructor for proper cleanup of derived classes. More...
 

Detailed Description

Implements the BlackJack mini-game.

The BlackJack class allows the player to play a simple version of the BlackJack card game against a dealer.

Constructor & Destructor Documentation

◆ BlackJack()

BlackJack::BlackJack ( )

Constructor for the BlackJack game.

BlackJack game.

Initializes the game with default settings.

Constructor for the BlackJack class.

Initializes a new game of BlackJack by shuffling the deck and dealing cards to the player and dealer.

Member Function Documentation

◆ displayState()

void BlackJack::displayState ( bool  printAll)

Displays the current state of the game.

Display the current state of the BlackJack game.

Parameters
printAllIndicates whether to print all details or just the player's perspective.
printAllA boolean indicating whether to show all the dealer's cards.

Prints the dealer's and player's cards, and whether the dealer's second card should be hidden.

◆ endGame()

bool BlackJack::endGame ( bool  won)

Handles the end of the game.

Parameters
wonIndicates if the player won or lost the game.
Returns
True if the player won, false otherwise.

◆ evaluate()

int BlackJack::evaluate ( bool  hit)

Evaluates the player's hand.

Evaluate the player's hand against the dealer's.

Parameters
hitIndicates if the player has chosen to hit or stand.
Returns
The result of the evaluation.
Parameters
hitA boolean indicating if the player chose to hit.
Returns
An integer indicating the outcome (-1 for loss, 0 for continue, 1 for win).

◆ getDealer()

const int * BlackJack::getDealer ( ) const

Gets the dealer's hand.

Returns
An array containing the dealer's cards.

◆ getGameName()

std::string BlackJack::getGameName ( )
overridevirtual

Gets the name of the game.

Get the name of the BlackJack game.

Returns
A string representing the name of the game.

Implements Game.

◆ getPlayerCards()

const std::vector< int > & BlackJack::getPlayerCards ( ) const

Gets the player's hand.

Returns
A vector containing the player's cards.

◆ handlePlayerTurn()

bool BlackJack::handlePlayerTurn ( )

Handles a single player turn.

Returns
Whether the player chose to hit or stand.

◆ initializeGame()

int BlackJack::initializeGame ( )

Initializes the game state.

Returns
The maximum number of rounds for the game.

◆ setDealer()

void BlackJack::setDealer ( const int  newDealer[2])

Sets the dealer's hand.

Parameters
newDealerAn array containing the new cards for the dealer.

◆ setPlayerCards()

void BlackJack::setPlayerCards ( const std::vector< int > &  newPlayerCards)

Sets the player's hand.

Parameters
newPlayerCardsA vector containing the new cards for the player.

◆ start()

bool BlackJack::start ( )
overridevirtual

Starts the BlackJack game.

Start the BlackJack game.

Returns
True if the game was completed successfully, otherwise false.
True if the player wins, false otherwise.

The player plays against the dealer, attempting to win the majority of rounds.

Implements Game.

◆ updateGameState()

void BlackJack::updateGameState ( bool  won,
int  rounds,
int  totalWins,
int  maxRounds,
bool  wasHit 
)

Updates the game state based on the result of a round.

Parameters
wonIndicates if the round was won or lost.

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