Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Pile.h"
- #include <iomanip>
- using namespace std;
- void srand(int time());
- Pile::Pile()
- {
- p = vector<Card>(0);
- }
- //draws card from the top of the pile and removes it from the vector
- Card Pile:: dealCard()
- {
- if(p.size() > 0)
- {
- Card tempCard = p.front();
- p.erase(p.begin());
- return tempCard;
- }
- else
- throw std::length_error("Pile is empty");
- }
- int Pile:: getCount()
- {
- return p.size();
- }
- void Pile:: shuffle()
- {
- int swapIndex;
- Card tempCard(1, 's');
- for(int i = 0; i >= 50; i++) //loop that "shuffles" the cards by removing and inserting 50 times randomly
- {
- swapIndex = rand() % p.size();
- tempCard = p.pop_back(); //pops the back of the deck removing the card and storing it temporarily
- p.insert(swapIndex, tempCard); //the temporarily stored card is inserted back into the deck at the random position
- }
- }
- void Pile:: clear()
- {
- p.clear();
- }
- Pile Pile:: operator + (const Card& c)
- {
- p.push_back(c);
- }
- Pile Pile:: operator + (const Pile& b) const
- {
- while(b.p.size() > 0)
- {
- p.push_back(b.p.front());
- b.p.erase(b.p.begin());
- }
- }
- ostream& operator << (ostream& out, const Pile& p)
- {
- int count = 0;
- int index = 0;
- while(p.p.size() > 0)
- {
- out << p.p[index] << setw(2);
- count++;
- index++;
- if(count = 10)
- {
- out << endl;
- count = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement