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
|
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <ctime>
const int NUM_OF_CARDS = 52;
class DeckOfCards
{
private:
std::string str, str2;
public:
void fillDeckVector(std::vector<std::string>&, std::string[], std::string[]);
void splitDeck(std::vector<std::string>&, std::vector<std::string>&, std::vector<std::string>&);
int foo(std::string, std::string[]);
};
void DeckOfCards::fillDeckVector(std::vector<std::string>& theDeck, std::string s[], std::string r[])
{
int x = 0; int y = 0;
for(unsigned int i = 0; i < theDeck.size(); i++)
{
theDeck[i] = r[x++] + " of " + s[y++];
if(x == 13)
x = 0;
else if(y == 4)
y = 0;
}
srand(static_cast<int>(time(NULL)));
for(int i = 0; i < rand() % 50; i++)
random_shuffle(theDeck.begin(), theDeck.end());
}
void DeckOfCards::splitDeck(std::vector<std::string>& theDeck, std::vector<std::string>& playerHand1, std::vector<std::string>& playerHand2)
{
int x = 1;
int y = 1;
playerHand1[0] = theDeck[0];
playerHand2[0] = theDeck[1];
for(unsigned int i = 2; i < theDeck.size(); i++)
{
if((i % 2) == 0)
playerHand1[x++] = theDeck[i];
else
playerHand2[y++] = theDeck[i];
}
}
int DeckOfCards::foo(std::string strP1, std::string r[]){
str = strP1.erase(strP1.find(" ", 0));
for(int i = 0; i < 13; i++)
{
if(str == r[i])
{
std::cout << "strP1 is: " << strP1 << std::endl;
std::cout << "r[i] is: " << r[i] << std::endl;
std::cout << "Yes, strings match." << std::endl;
return i;
}
}
}
int main()
{
DeckOfCards DeckObject;
std::vector<std::string>theDeck(NUM_OF_CARDS);
std::vector<std::string>playerHand1(26);
std::vector<std::string>playerHand2(26);
std::string sASuit[4] = {"Clubs", "Diamonds", "Hearts", "Spades"};
std::string sARank[13] = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
int iAValue[13] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
DeckObject.fillDeckVector(theDeck, sASuit, sARank);
DeckObject.splitDeck(theDeck, playerHand1, playerHand2);
int returnValue = DeckObject.foo(playerHand1[0], sARank);
std::cout << "The return value from the compare string function was: " << returnValue << std::endl;
std::cout << "The interger value for " << playerHand1[0] << " is " << iAValue[returnValue] <<std::endl;
std::cout << std::endl << playerHand1[0] << " beats ";
for(int i = returnValue; i > 0; i--)
std::cout << sARank[i] << " ";
std::cin.ignore();
return 0;
}
|