-
Notifications
You must be signed in to change notification settings - Fork 0
/
cards.cpp
132 lines (117 loc) · 2.11 KB
/
cards.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
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
#include <iostream>
enum class Suits
{
CLUBS,DIAMONDS,HEARTS,SPADES,
};
enum class CardNames
{
ACE=1,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,JACK,QUEEN,KING
};
struct Card
{
CardNames name;
Suits suit;
int value;
void PrintCard()
{
PrintValue();
std::cout << " of ";
PrintSuit();
std::cout << std::endl;
}
void PrintValue()
{
if(name == CardNames::JACK)
{
std::cout << "Jack";
}
else if(name == CardNames::QUEEN)
{
std::cout << "Queen";
}
else if(name == CardNames::KING)
{
std::cout << "King";
}
else if(name == CardNames::ACE)
{
std::cout << "Ace";
}
else
{
std::cout << value;
}
}
void PrintSuit()
{
if(suit == Suits::CLUBS)
{
std::cout << "clubs";
}
else if(suit == Suits::DIAMONDS)
{
std::cout << "Diamonds";
}
else if(suit == Suits::HEARTS)
{
std::cout << "Hearts";
}
else if(suit == Suits::SPADES)
{
std::cout << "Spades";
}
}
};
struct Deck
{
Card arrCards[52];
void PrintAll()
{
for(int col = (int)Suits::CLUBS; col <= (int)Suits::SPADES; col++)
{
for(int row = (int)CardNames::ACE; row <= (int)CardNames::KING; row++)
{
int index =(13 * col) + row-1;
arrCards[index].PrintCard();
}
std::cout << std::endl;
}
}
void SetupCards()
{
for(int col = (int)Suits::CLUBS; col <= (int)Suits::SPADES; col++)
{
for(int row = (int)CardNames::ACE; row <= (int)CardNames::KING; row++)
{
Card c;
c.suit = (Suits)col;
c.name = (CardNames)row;
if(c.name == CardNames::JACK)
{
c.value = 10;
}else if(c.name == CardNames::QUEEN)
{
c.value = 10;
}
else if(c.name == CardNames::KING)
{
c.value = 10;
}
else
{
c.value = (int)c.name;
}
std::cout << (int)c.name << " of " << (int)c.suit << std::endl;
int index =(13 * col) + row-1;
arrCards[index] = c;
}
}
}
};
int main()
{
Deck deck;
deck.SetupCards();
std::cout << std::endl;
deck.PrintAll();
}