CardGame
Rogue-like card videogame
Loading...
Searching...
No Matches
DeckCombat Class Reference

Manages all card piles during a single combat. More...

#include <deckCombat.h>

Collaboration diagram for DeckCombat:

Public Member Functions

 DeckCombat (const DeckPlayer &deck_player, const ICardFactory &factory)
 Constructs the combat deck from a player's persistent deck.
 
DrawResult drawCard ()
 Draws one card from the draw pile to the hand.
 
DrawData drawMultipleCards (int amount)
 
void discardFromHand (int handIndex)
 Discards a card from the hand to the discard pile.
 
void discardWholeHand ()
 
int getHandSize () const
 Returns the number of cards currently in the hand.
 
void discard (std::unique_ptr< CardInstance > exhaustedCard)
 Moves an exhausted/played card into the discard pile.
 
std::unique_ptr< CardInstancetakeFromHand (int index)
 Removes a card from the hand and transfers ownership to the caller.
 
std::vector< std::unique_ptr< CardInstance > > & getHandPile ()
 Returns a reference to the current hand pile.
 
std::vector< const CardInstance * > getHandView () const
 Returns a non-owning view of the current hand for UI rendering.
 
void shuffle ()
 
void regenerateDeck ()
 

Detailed Description

Manages all card piles during a single combat.

DeckCombat is the runtime deck system used during an encounter. It is initialized from the player's persistent DeckPlayer and builds a fresh set of CardInstances using the provided ICardFactory.

It owns and manages:

  • Draw pile (main deck)
  • Hand pile (cards in hand)
  • Discard pile (used cards)

Cards are never duplicated. Ownership moves between piles via std::move. The deck is destroyed at the end of combat.

Constructor & Destructor Documentation

◆ DeckCombat()

DeckCombat::DeckCombat ( const DeckPlayer deck_player,
const ICardFactory factory 
)

Constructs the combat deck from a player's persistent deck.

Creates runtime CardInstances for each entry in the DeckPlayer.

Parameters
deck_playerThe source persistent deck.
factoryCard creation system used to instantiate CardInstances.

Member Function Documentation

◆ discard()

void DeckCombat::discard ( std::unique_ptr< CardInstance exhaustedCard)

Moves an exhausted/played card into the discard pile.

This takes ownership of the CardInstance. If the pointer is null, no action is taken.

Parameters
exhaustedCardOwned card to discard.

◆ discardFromHand()

void DeckCombat::discardFromHand ( int  handIndex)

Discards a card from the hand to the discard pile.

Parameters
handIndexIndex of the card in the hand pile. If index is out of bounds, no action is taken.

◆ discardWholeHand()

void DeckCombat::discardWholeHand ( )

◆ drawCard()

DrawResult DeckCombat::drawCard ( )

Draws one card from the draw pile to the hand.

If the draw pile is empty, no action is taken.

◆ drawMultipleCards()

DrawData DeckCombat::drawMultipleCards ( int  amount)

◆ getHandPile()

std::vector< std::unique_ptr< CardInstance > > & DeckCombat::getHandPile ( )
inline

Returns a reference to the current hand pile.

◆ getHandSize()

int DeckCombat::getHandSize ( ) const
inline

Returns the number of cards currently in the hand.

◆ getHandView()

std::vector< const CardInstance * > DeckCombat::getHandView ( ) const

Returns a non-owning view of the current hand for UI rendering.

Returns
Vector of raw pointers to cards currently in hand.

◆ regenerateDeck()

void DeckCombat::regenerateDeck ( )

◆ shuffle()

void DeckCombat::shuffle ( )

◆ takeFromHand()

std::unique_ptr< CardInstance > DeckCombat::takeFromHand ( int  index)

Removes a card from the hand and transfers ownership to the caller.

This is how a card is played: the card is removed from the hand immediately and returned as a std::unique_ptr for effect resolution.

Parameters
indexZero-based hand index.
Returns
Owned card if index is valid; nullptr otherwise.

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