-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeck.cpp
85 lines (62 loc) · 1.25 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
#include <iostream>
#include <cstdlib>
#include "deck.h"
Deck::Deck(void){
Card myCards[SIZE]; // size of deck
for (int i= 0; i<13; i++){
myCards[i]= Card(i,spades);
}
for (int i=13; i<26; i++){
myCards[i]= Card(i,clubs);
}
for (int i= 26; i<39; i++){
myCards[i]= Card(i,hearts);
}
for (int i=39; i<52; i++){
myCards[i]= Card(i,diamonds);
}
int myIndex=0; // current card to deal
}
Card Deck::dealCard(void){
Card temp;
temp= myCards[myIndex];
myIndex++;
return(temp);
}
int size(void){
return(SIZE- myIndex);
}
void Deck::shuffle(){ // shuffle the deck, all 52 cards present
card n[size()};
int count = size();
srand(time(NULL));
CardNode *curr =myCards;
if(myCards== NULL){
return;
}
while(1){
while(1){
int x = rand() % getNumCards();
string a= "";
string b= n[x].getRank();
if(a==b){
n[x] = curr->c;
break;
}
curr= curr->next;
if(curr==NULL){
break;
}
}
CardNode *rep = cards;
for (int i =0; i<count; i++){
rep->c= n[i];
rep=rep->next;
}
}
}
Card dealCard(); // get a card, after 52 are dealt, fail
int size() const; // # cards left in the deck
private:
Card myCards[SIZE];
int myIndex; // current card to deal