-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInGame.cpp
100 lines (80 loc) · 2.96 KB
/
InGame.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
#include "InGame.h"
InGame::InGame(QWidget *parent) : QWidget(parent) {
this->mainLayout = new QVBoxLayout(this);
this->mainLayout->setAlignment(Qt::AlignCenter);
QPixmap bgPixmap(":/img/ISEN-Nantes.png");
bgPixmap = bgPixmap.scaled(this->size(), Qt::KeepAspectRatioByExpanding);
QPalette palette;
palette.setBrush(QPalette::Window, QBrush(bgPixmap));
this->setPalette(palette);
this->pts = new QLabel("Points : 0", this);
this->pts->setStyleSheet("font-size: 96px; color: black;");
this->x = new QLabel("X : 0", this);
this->x->setStyleSheet("font-size: 32px; color: black;");
this->y = new QLabel("Y : 0", this);
this->y->setStyleSheet("font-size: 32px; color: black;");
this->time = new QLabel("Time : 0m0s", this);
this->time->setStyleSheet("font-size: 32px; color: black;");
this->speed = new QLabel("Vitesse : 0", this);
this->speed->setStyleSheet("font-size: 32px; color: black;");
this->angle = new QLabel("Angle : 0", this);
this->angle->setStyleSheet("font-size: 32px; color: black;");
this->mainLayout->addWidget(pts);
this->posAndTimeLayout = new QHBoxLayout();
this->mainLayout->addLayout(this->posAndTimeLayout);
this->posAndTimeLayout->addWidget(time);
this->posLayout = new QVBoxLayout();
this->posLayout->addWidget(x);
this->posLayout->addWidget(y);
this->posLayout->addWidget(speed);
this->posLayout->addWidget(angle);
this->posLayout->setAlignment(Qt::AlignCenter);
this->posAndTimeLayout->addLayout(this->posLayout);
this->setLayout(mainLayout);
this->timer = new QTimer(this);
this->timer->setInterval(1000); // 1 second
connect(this->timer, &QTimer::timeout, this, &InGame::updateTime);
}
void InGame::updateScode() const
{
this->pts->setText("Points : " + QString::number(this->score));
}
void InGame::updatePos(const std::string& x, const std::string &y) const
{
this->x->setText("X : " + QString::fromStdString(x));
this->y->setText("Y : " + QString::fromStdString(y));
}
void InGame::updateSpeed(const std::string& speed) const
{
this->speed->setText("Vitesse : " + QString::fromStdString(speed));
}
void InGame::updateAngle(const std::string& angle) const
{
this->angle->setText("Angle : " + QString::fromStdString(angle));
}
void InGame::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);
this->timer->start();
}
void InGame::updateTime()
{
this->timeCounter++;
int min = this->timeCounter / 60;
int sec = this->timeCounter % 60;
this->time->setText("Time : " + QString::number(min) + "m" + QString::number(sec) + "s");
emit askTCPServer("ihm;strat;get pos;1");
emit askTCPServer("ihm;strat;get speed;1");
emit askTCPServer("ihm;strat;get angle;1");
}
void InGame::stopTimer() const {
this->timer->stop();
}
void InGame::addScore(int score) {
this->score += score;
this->updateScode();
}
void InGame::setScore(int score) {
this->score = score;
this->updateScode();
}