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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
Deck.h
class deck //creates class deck
{
public: //lines 11 - 21 create public variables that can be used in other files
deck();
~deck();
int getPlaceInDeck();
void setPlaceInDeck(int aPlace);
void getDeck(card aDeck[], int deckSize);
void showDeck();
void shuffleDeck();
card dealCard();
private: //lines 24 - 27 create private variables that can only be used within the header file
const int numberOfCards = 52;
card cardDeck[52];
int placeInDeck = 0;
};
Deck.cpp
deck::deck()
{
getDeck(cardDeck, numberOfCards); // constuctor for getDeck to include card deck and number of cards before launching
}
deck::~deck()
{
}
int deck::getPlaceInDeck() // sets code to return placeInDeck when getPlaceInDeck is used
{
return placeInDeck;
}
void deck::setPlaceInDeck(int aPlace) // makes placeInDeck equal to aPlace and is what getPlaceInDeck will return
{
placeInDeck = aPlace;
}
void deck::getDeck(card aDeck[], int deckSize) // lines 25 - 62 set up the card deck to include faces, suits, and values, as well as code to move forward through the deck
{
string suits[] = { "Hearts", "Diamonds", "Clubs", "Spades" };
int numberSuits = 4;
string faces[] = { "Ace", "Deuce", "Trip", "Quad", "Fin", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
int numFaces = 13;
int aSuit = 0;
int aFace = 0;
for (int i = 0; i < deckSize; i++)
{
aDeck[i].setFace(faces[aFace]);
aDeck[i].setSuit(suits[aSuit]);
if (aFace < 10)
{
aDeck[i].setValue(aFace + 1);
}
else
{
aDeck[i].setValue(+10);
}
aSuit++;
if (aSuit > 3)
{
aSuit = 0;
aFace++;
}
if (aSuit > 12)
{
aFace = 0;
}
}//for
}
void deck::showDeck() // lines 64 - 70 show the deck so we can see that previous code functions properly and includes all cards
{
for (int i = 0; i < 52; i++)
{
cout << cardDeck[i].getFace() << " of " << cardDeck[i].getSuit() << endl;
}
}
void deck::shuffleDeck() // lines 72 - 83 shuffle the deck
{
srand(time(0));
cout << endl << "Shuffling....." << endl << endl << endl;
for (int i = 0; i < 52; i++)
{
int r = i + (rand() % (52 - i));
swap(cardDeck[i], cardDeck[r]);
}
}
card deck::dealCard() // lines 85- 90 deal card and uses code from Card.h
{
card aCard = cardDeck[placeInDeck];
placeInDeck++;
return aCard;
}
Player.h
using namespace std;
class player // sets up class for player, lines 10 - 23 set public variables, lines 26 - 31 set private variables
{
public:
player();
~player();
void setName(string aString);
int getNumberOfCardsInHand();
int getValue();
string getName();
void getCard(card aCard);
void showYourHand();
int getScore();
//void setAce(card aCard);
private:
string name = "";
card hand[10];
int numberOfCardsInHand = 0;
int value = 0;
};
Player.cpp
player::player()
{
}
player::~player()
{
}
int player::getNumberOfCardsInHand() //lines 15 - 35 getters and setters for player variables
{
return numberOfCardsInHand;
}
int player::getValue()
{
return value;
}
void player::setName(string aString)
{
name = "";
}
string player::getName()
{
return name;
}
void player::getCard(card aCard) // gives player card and increments the number of cards in hand
{
cout << aCard.getFace() << " of " << aCard.getSuit() << endl;
hand[numberOfCardsInHand] = aCard;
numberOfCardsInHand++;
}
void player::showYourHand() // moves through players and shows what they have in hand
{
for (int i = 0; i < numberOfCardsInHand; i++)
{
cout << hand[i].getFace() << " of " << hand[i].getSuit() << endl;
}
}
int player::getScore() // determines scores of individual players
{
int handScore = 0;
for (int i = 0; i < numberOfCardsInHand; i++)
{
handScore += hand[i].getValue();
}
return handScore;
}
|