-
Notifications
You must be signed in to change notification settings - Fork 0
/
construction-deck.cpp
68 lines (60 loc) · 1.54 KB
/
construction-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
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include "construction-deck.h"
using namespace std;
ConstructionDeck::ConstructionDeck(int initialSize)
{
Deck::Deck();
this->initialSize = initialSize;
}
ConstructionDeck::ConstructionDeck(std::vector<Card> cards, int initialSize)
{
Deck::Deck(this->cards = cards);
this->initialSize = initialSize;
}
void ConstructionDeck::pushThrow(Deck deck)
{
if (isMergeableWith(deck.getBack()))
{
while (!deck.isEmpty())
{
Deck::push(deck);
}
}
}
void ConstructionDeck::pushThrow(Card card)
{
if (isMergeableWith(card))
{
std::vector<Card>::iterator iterator;
iterator = this->cards.begin();
iterator = this->cards.insert(iterator, card);
}
}
std::vector<Card> ConstructionDeck::throwAndReturnSubVector(int startPos, int endPos)
{
std::vector<Card>::iterator itStart = this->getCards().begin() + (startPos - 1);
std::vector<Card>::iterator itEnd = this->getCards().begin() + endPos;
std::vector<Card> subVector(itStart, itEnd);
this->cards.erase(itStart, itEnd);
return subVector;
}
bool ConstructionDeck::isMergeableWith(Deck deck)
{
Card deckBackCard = deck.getBack();
return !isSameColorWith(deckBackCard.isRed());
}
bool ConstructionDeck::isMergeableWith(Card card)
{
return !isSameColorWith(card.isRed());
}
bool ConstructionDeck::isSameColorWith(bool isRed)
{
if (!this->isEmpty())
{
return this->getTop().isRed() == isRed;
}
return false;
}