-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deck.cpp
104 lines (100 loc) · 2.67 KB
/
Deck.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "Deck.h"
#include <string>
#include <iostream>
using namespace std;
Deck::Deck() {
char T_rank;
char T_suit;
cout << "Initiating Deck...";
for (int i= 0; i< 4; i++) {
for (int j = 1; j <= 13; j++) {
switch (i) { // gives suit value to Card.
case 0:
T_suit = 'S'; // Spade
break;
case 1:
T_suit = 'H'; // Heart
break;
case 2:
T_suit = 'D'; // Diamond
break;
case 3:
T_suit = 'C'; // CLover
break;
}
switch (j) { // gives Number Value to card
case 1:
T_rank = 'A'; // ACE
break;
case 11:
T_rank = 'J'; // JACK
break;
case 12:
T_rank = 'Q'; // QUEEN
break;
case 13:
T_rank = 'K'; // KING
break;
case 10:
T_rank = 't'; // 10
break;
default:
T_rank = j + '0'; // NUMBER VALUES INTO CHAR
}
this->Stack[size].setCard(T_rank, T_suit);
//Stack[size].display();
//cout << "Size: " << size << "\t Deck Size: "<< sizeof(Deck) << endl;
this->size++;
}
}
cout << " OK\n";
}
void Deck::display(){
cout << "\n~~~~~~~~~~~~~~~~~~~~~~ Deck ~~~~~~~~~~~~~~~~~~~~~~"<< endl;
for (int i = 0; i < 13; ++i) { // displays first 13 cards
Stack[i].display();
}
cout << endl;
for (int i = 13; i < 26; ++i) {
Stack[i].display();
}
cout << endl;
for (int i = 26; i < 39; ++i) {
Stack[i].display();
}
cout << endl;
for (int i = 39; i < 52; ++i) {
Stack[i].display();
}
cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
}
void Deck::shuffle()
{
cout << "\nDeck Shuffling...";
srand(time(0));
for (int i = 0; i < rand(); ++i) {
int alpine = rand() % 52;
int cavern = rand() % 52;
Card copy = Stack[alpine];
Stack[alpine] = Stack[cavern];
Stack[cavern] = copy;
}
cout << " OK\n";
}
Card Deck::deal(){
Card topCard = Stack[top++];
//top_card.display();
//cout << "Top: " << top << endl;
return topCard;
}
bool Deck::isempty() {
if (top == 52){
//cout << "Isempty";
return true;
}
}
void Deck::refreshDeck() {
cout << "Deck Refreshing...\n";
*this = {};
cout << endl;
}