#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
usingnamespace std;
class Card
{
private: string suit; int value;
public:
Card()//default constructor (no arguments) allows you to make an
{ //array
value = 0;
}
Card(int v, string s)// allows the private attributes to be set
{
value = v;
suit = s;
}
int getvalue()// returns the cards value
{
return value;
}
string getsuit()// returns the cards suit
{
return suit;
}
};
class Deck
{
/** these private vectors are the deck, and the pointers to the deck */
private: vector<Card> cardvector; vector<Card *> pcardvector;
public:
/** this constructor also uses a for loop to create a pointer for each card */
Deck (vector<Card> cardvector2)
{
cardvector = cardvector2;
for (size_t x = 0; x < cardvector.size(); ++x)
{
pcardvector.push_back(&cardvector[x]);
}
}
/** by printing with the pointers, it allows me to shuffle the pointers later on
rather than the actual deck, this is good because i still have my original deck.
*/
void printdeck ()
{
for (size_t x = 0; x < pcardvector.size(); ++x)
{
switch(pcardvector[x]->getvalue())
{
case 1: cout << "Ace"; break;
case 11: cout << "Jack"; break;
case 12: cout << "Queen"; break;
case 13: cout << "King"; break;
default: cout << pcardvector[x]->getvalue(); break;
}
cout << " of ";
cout << pcardvector[x]->getsuit() << endl;
}cout << endl;
}
void nextcard ()
{
}
void shufflecards ()
{
random_shuffle(pcardvector.begin(),pcardvector.end());
}
};
vector<Card> deck1;
/** this void function creates a vector of 'card' objects using the push_back
function*/
void createDeck()
{
int n,i,j;
string b;
j = 0;
for(n = 0; n < 4; n++)
{
for(i = 1; i < 14; ++i)
{
switch (n)
{
case 0: b = "Hearts";
break;
case 1: b = "Spades";
break;
case 2: b = "Diamonds";
break;
case 3: b = "Clubs";
break;
};
deck1.push_back(Card(i, b));
}
}
}
/** i have placed the above created deck as the argument for the deck class
constructor, and called for the printdeck function to be used.*/
int main(array<System::String ^> ^args)
{
srand ( time(NULL) );
createDeck();
Deck(deck1).shufflecards();
Deck(deck1).printdeck();
system("pause");
}