-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreboard.cpp
65 lines (52 loc) · 1.54 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
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
#include "Scoreboard.h"
#include "Game.h"
#include <QDebug>
extern Game* game;
ScoreBoard::ScoreBoard()
{
score_ = 0;
}
ScoreBoard::ScoreBoard(int s)
{
setRect(0,0,100,100);
score_ = s;
}
void ScoreBoard::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *){
if(game->state() == game->State::ongoing){
painter->drawRect((game->width() - 500) / 2,0, 500,50);
painter->drawText(
QRect((game->width() - 500) / 2, 0,500,50),
Qt::AlignCenter, "Score: " + QString::number(score())
);
painter->drawText(
QRect((game->width() - 500) / 2, 12,500,50),
Qt::AlignCenter, "Health: "
+ QString::number(game->getShip()->health()));
}
else{
QString state;
if(game->state() == game->State::won){
state = "won";
}
else{
state = "lost";
}
painter->drawRect((game->width() - 500) / 2,0, 500,50);
painter->drawText(
QRect((game->width() - 500) / 2, 0,500,50),
Qt::AlignCenter, "You have"
+ state
+ " with a score of"
+ QString::number(score())
+ "\n and health of "
+ QString::number(game->getShip()->health()));
}
}
void ScoreBoard::updateScore(int s){
score_ = s;
update();
game->viewport()->repaint();
}
int ScoreBoard::score(){
return score_;
}