-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck.cpp
More file actions
65 lines (57 loc) · 1.96 KB
/
Copy pathdeck.cpp
File metadata and controls
65 lines (57 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <algorithm>
#include <random>
#include <chrono>
#include "deck.h"
#include "definitions.h"
Deck::~Deck() {
for (auto& card : draw_deck_) {
delete card;
}
for (auto& card : discard_deck_) {
delete card;
}
}
/* DrawCard returns the last Card in the deck and pops it off. If the deck is empty
* then nullptr is returned.
* Return: Card*
*/
Card* Deck::DrawCard() {
if (!draw_deck_.empty()) {
Card* temp = draw_deck_.back();
draw_deck_.pop_back();
return temp;
}
return nullptr;
}
/* AddCard takes a pointer to a card object and adds it to the deck vector. */
void Deck::AddCard(Card* new_card) {
draw_deck_.push_back(new_card);
}
/* AddEmptyCard takes a pointer to a card object and adds it to the empty_cards vector. */
void Deck::AddEmptyCard(Card * new_card) {
empty_cards_.push_back(new_card);
}
/* DiscardCard takes a pointer to a card object and adds it to the discard_deck vector. */
void Deck::DiscardCard(Card *discard_card) {
discard_deck_.push_back(discard_card);
}
/* Deal takes a vector of players and deals MAX_HAND_SIZE cards to each player. The last card dealt
* is an empty card to allow each player to draw on the beginning of their turn.
* Params: std::vector<Player*> players
*/
void Deck::Deal(std::vector<Player*> players) {
for (int i = 0; i < MAX_HAND_SIZE - 1; i++) {
for (int j = 0; j < static_cast<int>(players.size()); j++) {
Card* temp = DrawCard();
players[static_cast<unsigned long>(j)]->AddCard(temp, i);
}
}
for (unsigned long i = 0; i < players.size(); i++) {
players[i]->set_action_card(empty_cards_[i]);
}
}
/* Shuffle is a simple function to shuffle the deck vector using a shuffle function */
void Deck::Shuffle() {
unsigned seed = static_cast<unsigned>(std::chrono::system_clock::now().time_since_epoch().count());
std::shuffle(draw_deck_.begin(), draw_deck_.end(), std::default_random_engine(seed));
}