-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeck.cpp
107 lines (75 loc) · 2.04 KB
/
Deck.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//Kanellaki Maria Anna - 1115201400060
//Matanis Panagiotis - 1115201400297
#include "Deck.hpp"
#include "Card.hpp"
Deck::Deck()
{
//default
minSize = 40;
maxSize = 60;
}
Deck::~Deck()
{
list <Card*>::iterator it;
for (it = deck.begin(); it != deck.end(); it++)
{
deck.remove((*it));
//delete *it;
it = deck.begin();
}
}
void Deck::untapDeck() //untaps whole deck
{
list <Card*>::iterator it;
for (it=deck.begin(); it!=deck.end(); it++)
(*it)->setTapped(false);
}
void Deck::tapDeck() //taps whole deck
{
list <Card*>::iterator it;
for (it=deck.begin(); it!=deck.end(); it++)
(*it)->setTapped(true);
}
void Deck::PrintCards() //prints all decks' cards
{
list <Card*>::iterator it;
for (it=deck.begin(); it!=deck.end(); it++)
(*it)->PrintCardStats();
}
Card* Deck::searchDeck(string title) //searches deck for card with name = title and returns it. if not found returns null
{
list <Card*>::iterator it;
for (it=deck.begin(); it!=deck.end(); it++)
{
if ((*it)->getName() == title)
return *it;
}
return nullptr;
}
void Deck::pushCard(Card* card) //pushes a card in deck list. facilitates pushing out of this class
{
deck.push_back(card);
}
Card* Deck::popCard(Card* card) //pops a card from deck list. facilitates popping out of this class
{
deck.remove(card);
return card;
}
bool Deck::isEmpty() //checks if deck list is empty. facilitates checking out of this class
{
return deck.empty();
}
void Deck::getCardFrom(Deck from) //pops a card from another deck and pushes it into this deck
{
if (from.isEmpty())
return;
Card *card = from.popCard(*from.deck.begin());
this->pushCard(card);
card = nullptr;
delete card;
}
//getters
list<Card*> Deck::getDeck() const
{
return deck;
}