-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPile.cpp
83 lines (70 loc) · 1.21 KB
/
Pile.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
#include "Pile.h"
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>
Pile::Pile(bool isDrawPile)
{
for(int k = 0; k < 3; ++k)
if (isDrawPile) //constructs the drawPile
{
for (int i = 1; i <= 12; i++) //iterates through cards with numbers 1-12
{
for (int j = 1; j <= 12; j++) //adds 12 of each card
{
Card *temp = new Card(i);
cards.push_back(*temp);
}
}
for (int i = 1; i <= 18; i++) //adds 18 skipbo cards
{
Card *temp = new Card(0);
cards.push_back(*temp);
}
}
}
void Pile::deckShuffle() //shuffles the pile
{
std::srand ( unsigned ( std::time(0) ) );
std::random_shuffle ( cards.begin(), cards.end() );
}
Card Pile::cardAt(int num)
{
return cards.at(num);
}
void Pile::empty()
{
cards.clear();
}
void Pile::removeTop()
{
cards.pop_back();
}
void Pile::operator+ (const Card &c)
{
cards.push_back(c);
}
void Pile::operator+= (const Card &c)
{
*this + c;
}
Card Pile::operator[](int i)
{
return cardAt(i);
}
Card Pile::draw()
{
Card c = (*this)[getSize() - 1];
removeTop();
return c;
}
Card Pile::getTop()
{
return (*this)[getSize() - 1];
}
Card Pile::drawAt(int i)
{
std::swap(cards[i], cards[cards.size()-1]);
return draw();
}