|
| deck () |
| Constructs a new deck object.
|
|
| deck (const std::vector< card * > &cards) |
| Constructs a new deck object.
|
|
| ~deck () override |
| Destructs a deck object.
|
|
bool | is_empty () const noexcept |
| Checks if _remaining_cards is empty, i.e., if all cards are dealt.
|
|
unsigned int | get_number_of_remaining_cards () const noexcept |
| Gets the number of remaining cards, i.e., the number of cards not dealt yet.
|
|
void | setup_round () |
| Sets up the deck for a new round.
|
|
bool | draw_cards (const player *player, int round_number, std::string &err) |
| Draws a number of random cards based on the current round number and places them into a player's hand.
|
|
card * | draw_trump () const |
| Draws a random trump card from the remaining cards.
|
|
void | write_into_json (rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override |
| Serializes a deck object into a json object.
|
|
std::string | get_id () const |
|
virtual void | write_into_json (rapidjson::Value &json, rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > &allocator) const override |
|
virtual rapidjson::Document * | to_json () const |
|
Represents the card deck in the game.
This class encapsulates all information about a card deck, including all cards of the game and the remaining cards not dealt yet.
In the whole game, there is only one object of each possible cards. The _all_cards member of the deck class holds pointers to these cards that are not changed once created and are used to update the _remaining_cards member of the deck class when a new round is set up. The _remaining_cards member helps to keep track of which cards are already dealt and which can still be dealt and used to draw a trump.
Constructs a new deck object.
This is the main constructor of the deck class used by the game_state to create a deck for a game. When this constructor is called, all possible cards in Wizard are created and added to the deck. This is the only time actual card objects are created, every card only exists exactly once. In all other instances where cards are removed or added somewhere (e.g., to a player's hand), actually only pointers are added or removed.
bool deck::draw_cards |
( |
const player * | player, |
|
|
int | round_number, |
|
|
std::string & | err ) |
Draws a number of random cards based on the current round number and places them into a player's hand.
- Parameters
-
player | The player to which the cards are added. |
round_number | The current round number determining how many cards are drawn. |
err | The error message updated in case something does not work. |
- Returns
- A boolean indicated if drawing the cards worked or not.
This function is used to place cards into the players' hands at the start of each round. The cards are randomly drawn from the remaining cards, added to a player's hand, and then are removed from the remaining cards. The number of cards to be drawn should be the current round number (if round number 0-indexed, the round_number parameter must be the round number + 1).