-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreboard.cpp
40 lines (38 loc) · 1.17 KB
/
scoreboard.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
#include "scoreboard.h"
#include "ui_scoreboard.h"
ScoreBoard::ScoreBoard(Snake* p, QWidget *parent) :
QWidget(parent),
ui(new Ui::ScoreBoard)
{
ui->setupUi(this);
this->setStyleSheet("background-color: #f5f5f5");
player = p;
timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &ScoreBoard::updateUndefeatableTime);
timer->start(1000);
setName(player);
updateLives(player->getLives());
updateScore(player->getScore());
updateUndefeatableTime();
connect(player, &Snake::livesUpdated, this, &ScoreBoard::updateLives);
connect(player, &Snake::scoreUpdated, this, &ScoreBoard::updateScore);
}
void ScoreBoard::setName(Snake* player) {
ui->PlayerName->setText(player->name());
}
void ScoreBoard::setUndefeatableTime(int time) {
ui->UndefeatableTime->setText(QString::number(time / 1000) + " s");
}
void ScoreBoard::updateLives(int lives) {
ui->Lives->setText(QString::number(lives));
}
void ScoreBoard::updateScore(int score) {
ui->Score->setText(QString::number(score));
}
void ScoreBoard::updateUndefeatableTime() {
setUndefeatableTime(player->undefeatableTime());
}
ScoreBoard::~ScoreBoard()
{
delete ui;
}