-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayingcard.cpp
More file actions
107 lines (90 loc) · 2.16 KB
/
playingcard.cpp
File metadata and controls
107 lines (90 loc) · 2.16 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
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
#include "playingcard.h"
#include <QRandomGenerator>
#include <QBitmap>
#include <QPainter>
PlayingCard::PlayingCard()
{
Highlight(false);
}
void PlayingCard::Remove()
{
generated[number][cardType] = false;
}
void PlayingCard::Add()
{
generated[number][cardType] = true;
}
bool PlayingCard::isRevealed()
{
return revealed;
}
PlayingCard::PlayingCard(QLabel* lblCard) : lblCard(lblCard)
{
setImage("back.png");
GenerateRandom();
Highlight(false);
}
PlayingCard::PlayingCard(int number, CardType cardType) : number(number), cardType(cardType)
{
lblCard = nullptr;
revealed = false;
Highlight(false);
}
PlayingCard::~PlayingCard()
{
Remove();
}
QString PlayingCard::getFilename()
{
QString filename = QString::number(number);
if (cardType == spades) filename += "s";
if (cardType == hearts) filename += "h";
if (cardType == diamonds) filename += "d";
if (cardType == clubs) filename += "c";
return filename;
}
void PlayingCard::GenerateRandom()
{
do
{
number = QRandomGenerator::global()->bounded(2, 15);
cardType = static_cast<CardType>(QRandomGenerator::global()->bounded(1, 5));
} while (generated[number][cardType] == true);
generated[number][cardType] = true;
}
void PlayingCard::setRevealed(bool const& _revealed)
{
revealed = _revealed;
if (revealed)
setImage(getFilename());
else setImage("back.png");
}
void PlayingCard::setImage(QString const& filename)
{
lblCard->setPixmap((new QPixmap(":/images/" + filename))->scaled(W, H));
}
void PlayingCard::foldCard()
{
setImage("fold_back.png");
}
SimpleCard PlayingCard::getSimpleCard()
{
return std::make_pair(number, cardType);
}
void PlayingCard::setSimpleCard(SimpleCard sc)
{
number = sc.first;
cardType = sc.second;
}
void PlayingCard::Highlight(bool status)
{
if (status == true)
lblCard->setStyleSheet("border: 8px solid yellow;");
else lblCard->setStyleSheet("border: 5px solid black;");
}
void PlayingCard::MarkTurn(bool turn)
{
if (turn)
lblCard->setStyleSheet("border: 8px solid #73FF33;");
else lblCard->setStyleSheet("border: 5px solid black;");
}