-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDeck.cpp
62 lines (55 loc) · 1.23 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
//******************************************************************************
//
// Revision History:
//
// Date Author Description
// 11/27/2017 Jason Chen Added class
//******************************************************************************
#include <iostream>
#include "Deck.h"
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include "Card.h"
using namespace std;
//constructor
//initialize a new deck with a shuffle
Deck::Deck()
{
shuffle();
}
//load 52 cards into the array deck
//using locations from 0 to 51
//0-12 corresponds to suit 0
//13-25 corresponds to suit 1
//26-38 corresponds to suit 2
//39-51 corresponds to suit 3
void Deck::shuffle()
{
for(int i = 0; i < 13; i++)
{
for(int j = 0; j < 4; j++)
{
deck[i + 13 * j] = Card(i + 2, j);
}
}
}
Card Deck::draw()
{
srand((unsigned) time(NULL));
while(true)
{
int k = rand() % 52;
if(deck[k].getNumber() != 0)
{
Card temp = deck[k];
deck[k] = Card(0, 0);
return temp;
}
}
return Card();
}
Card Deck::getCard(int num, int suit)
{
return deck[num + 13 * suit];
}