-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeck.h
47 lines (34 loc) · 790 Bytes
/
deck.h
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
//
// Created by iDarkDuck on 2018-10-20.
//
#ifndef CPP_PROJECT_MEMORY_GAME_DECK_H
#define CPP_PROJECT_MEMORY_GAME_DECK_H
#include <algorithm>
#include <iterator>
#include <random>
#include <vector>
#include "card.h"
#include "reward.h"
template<class C>
class Deck {
public:
Deck() = default;
virtual ~Deck() = default;
void shuffle() {
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(deck->begin(), deck->end(), g);
}
C *getNext() {
if (!(*deck).empty()) {
C *last = deck->back();
deck->pop_back();
return last;
}
return nullptr;
}
bool isEmpty() { return (*deck).empty(); }
protected:
vector<C *> *deck;
};
#endif //CPP_PROJECT_MEMORY_GAME_DECK_H