-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowcards.cpp
More file actions
154 lines (132 loc) · 6.8 KB
/
Copy pathshowcards.cpp
File metadata and controls
154 lines (132 loc) · 6.8 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "showcards.h"
#include "ui_showcards.h"
#include "filepath.h"
#include <QColor>
showCards::showCards(QWidget *parent)
: QDialog(parent)
, ui(new Ui::showCards)
{
ui->setupUi(this); //// this code for add label of cards to my vector
this->cardLabel.push_back(ui->lb_card_1);
this->cardLabel.push_back(ui->lb_card_2);
this->cardLabel.push_back(ui->lb_card_3);
this->cardLabel.push_back(ui->lb_card_4);
this->cardLabel.push_back(ui->lb_card_5);
this->cardLabel.push_back(ui->lb_card_6);
this->cardLabel.push_back(ui->lb_card_7);
this->cardLabel.push_back(ui->lb_card_8);
this->cardLabel.push_back(ui->lb_card_9);
this->cardLabel.push_back(ui->lb_card_10);
this->cardLabel.push_back(ui->lb_card_11);
this->cardLabel.push_back(ui->lb_card_12);
this->cardLabel.push_back(ui->lb_card_13);
this->cardLabel.push_back(ui->lb_card_14);
///////
//// set photo of cards
cardsImageRef["Bishop"] = "border-image:url(" + std::string(BISHOP_IMAGE) + ")";
cardsImageRef["Drummer"] = "border-image:url(" + std::string(DRUMMER_IMAGE) + ")";
cardsImageRef["Heroine"] = "border-image:url(" + std::string(HEROINE_IMAGE) + ")";
cardsImageRef["Scarecrow"] = "border-image:url(" + std::string(SCARECROW_IMAGE) + ")";
cardsImageRef["Spring"] = "border-image:url(" + std::string(SPRING_IMAGE) + ")";
cardsImageRef["Winter"] = "border-image:url(" + std::string(WINTER_IMAGE) + ")";
cardsImageRef["Spy"] = "border-image:url(" + std::string(SPY_IMAGE) + ")";
cardsImageRef["Turncoat"] = "border-image:url(" + std::string(TURNCOAT_IMAGE) + ")";
cardsImageRef["WhiteRakhsh"] = "border-image:url(" + std::string(WHITERAKHSH_IMAGE) + ")"; //This code is related to phase 3 of the project
cardsImageRef["WhiteSeals"] = "border-image:url(" + std::string(WHITESEALS_IMAGE) + ")"; //This code is related to phase 3 of the project
//cardsImageRef["ShirinAghl"] = "border-image:url(" + std::string(SHIRINAGHL_IMAGE) + ")"; //This code is related to phase 3 of the project
cardsImageRef["1"] = "border-image:url(" + std::string(ONE_IMAGE) + ")";
cardsImageRef["2"] = "border-image:url(" + std::string(TWO_IMAGE) + ")";
cardsImageRef["3"] = "border-image:url(" + std::string(THREE_IMAGE) + ")";
cardsImageRef["4"] = "border-image:url(" + std::string(FOUR_IMAGE) + ")";
cardsImageRef["5"] = "border-image:url(" + std::string(FIVE_IMAGE) + ")";
cardsImageRef["6"] = "border-image:url(" + std::string(SIX_IMAGE) + ")";
cardsImageRef["10"] = "border-image:url(" + std::string(TEN_IMAGE) + ")";
// set animation object
audioPlayer = new QMediaPlayer;
audioOutput = new QAudioOutput;
audioPlayer->setAudioOutput(audioOutput);
audioPlayer->setSource(QUrl::fromLocalFile("../../Description/Graphics/Sounds/distribute.mp3")); // sound of game
audioOutput->setVolume(100);
audioPlayer->setLoops(QMediaPlayer::Infinite); // pause
audioPlayer->setPlaybackRate(3.0);
}
// distructor
showCards::~showCards()
{
delete ui;
delete audioOutput;
delete audioPlayer;
}
// this function is for set player informations
void showCards::getPlayer(const Player &player)
{
ui->lb_color->setStyleSheet("QLabel { background-color : " + QString::fromStdString(player.getColor()) +";}"); // set color player
ui->btn_lets_go->setVisible(false);
for (auto &&label : cardLabel) {
label->setStyleSheet("border-image:url(:/Description/Graphics/Assets/zard/Back.png)"); // path of yellow cards
label->setVisible(false);
}
ui->lb_player_counter->setText("Player " + QString::number(player.getID() + 1)); // players id
this->show();
const std::vector<const Card*>& playerCards = player.getCards(); // sent cards by function of player class
for (int i = 0; i < playerCards.size(); ++i) {
animation.push_back(new QPropertyAnimation(cardLabel[i], "geometry", this));
}
// set animation for show cards
QSequentialAnimationGroup group;
for (int i = 0; i < playerCards.size(); ++i) {
cardLabel[i]->setVisible(true);
QRect end(cardLabel[i]->geometry());
cardLabel[i]->setGeometry(QRect(0 ,0, 0, 0)); // /// animation for show cards
animation[i]->setDuration(200);
animation[i]->setStartValue(QRect(0 ,0, 0, 0)); // /// animation for show cards
animation[i]->setEndValue(end);
group.addAnimation(animation[i]);
}
QObject::connect(&group, SIGNAL(finished()), audioPlayer, SLOT(stop())); ///signal and slots
QEventLoop loop;
QObject::connect(&group, SIGNAL(finished()), &loop, SLOT(quit())); /// signal and slots
audioPlayer->play();
group.start();
loop.exec();
ui->btn_lets_go->setVisible(true); //change page
QObject::disconnect(&group, SIGNAL(finished()), &loop, SLOT(quit())); /// signal and slots
QObject::disconnect(&group, SIGNAL(finished()), audioPlayer, SLOT(stop())); /// signal and slots
QObject::connect(ui->btn_lets_go, SIGNAL(clicked(bool)), &loop, SLOT(quit()));
loop.exec();
QObject::disconnect(ui->btn_lets_go, SIGNAL(clicked(bool)), &loop, SLOT(quit())); /// signal and slots
for (int i = 0; i < playerCards.size(); ++i) {
QRect end(cardLabel[i]->geometry());
animation[i]->setDuration(200); // speed of show cards
animation[i]->setStartValue(end); //time
animation[i]->setEndValue(QRect(end.left() + (end.width()/2), end.top(), 0, end.height()));
animation[i]->start();
QEventLoop loop;
QObject::connect(animation[i], SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
cardLabel[i]->setStyleSheet(QString::fromStdString(cardsImageRef[playerCards[i]->getType()]));
animation[i]->setDuration(200);
animation[i]->setStartValue(QRect(end.left() + (end.width()/2), end.top(), 0, end.height()));
animation[i]->setEndValue(end);
animation[i]->start();
}
QObject::disconnect(ui->btn_lets_go, SIGNAL(clicked(bool)), &loop, SLOT(quit()));
ui->btn_lets_go->setVisible(false);
QObject::connect(ui->btn_Nplayer, SIGNAL(clicked(bool)), &loop, SLOT(quit())); /// signal and slots
loop.exec();
QObject::disconnect(ui->btn_Nplayer, SIGNAL(clicked(bool)), &loop, SLOT(quit())); /// signal and slots
for (int i = 0; i < playerCards.size(); ++i) { /// this loop for end of animations cards
delete animation[i];
}
animation.clear();
this->hide();
}
void showCards::on_btn_Nplayer_clicked()
{
}
void showCards::on_cb_show_player_list_activated(int index)
{
}
void showCards::on_btn_lets_go_clicked()
{
}