-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.cpp
More file actions
76 lines (67 loc) · 1.19 KB
/
Card.cpp
File metadata and controls
76 lines (67 loc) · 1.19 KB
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
#include "Card.h"
#include <qlabel.h>
#include "Game.h"
#include <qwidget.h>
#include <qpainter.h>
#include <qstring.h>
#include <algorithm>
#include <random>
#include <qobject.h>
//-- Card --//
Card::Card(CardType type, int value, std::string name)
{
this->type = type;
this->value = value;
this->name = name;
id = std::format("{}_{}", strFromType(type), name);
}
std::string Card::strFromType(CardType type)
{
//Get the string from the type
switch (type)
{
case SPADES:
return "Spades";
case DIAMONDS:
return "Diamonds";
case HEART:
return "Hearts";
case CLUBS:
return "Clubs";
default:
return "Unknown";
}
}
std::string Card::nameFromValue(int value)
{
//Get the name from the value
switch (value)
{
case 11:
return "Jack";
case 12:
return "Queen";
case 13:
return "King";
case 14:
return "Ace";
default:
return std::to_string(value);
}
}
void shuffleCards(std::vector<Card*>* cards)
{
std::random_device rd;
std::default_random_engine rng(rd());
std::ranges::shuffle(*cards, rng);
}
//-- CardPair --//
CardPair::CardPair(Card* attack)
{
this->attack = attack;
}
CardPair::CardPair(Card* attack, Card* defense)
{
this->attack = attack;
this->defense = defense;
}