-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealth.cpp
More file actions
43 lines (32 loc) · 955 Bytes
/
health.cpp
File metadata and controls
43 lines (32 loc) · 955 Bytes
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
#include "Health.h"
#include <QFont>
#include "Game.h"
#include <QMessageBox>
extern Game * game;
Health::Health(QGraphicsItem *parent): QGraphicsTextItem(parent){
health = 3;
setPlainText(QString("Health: ") + QString::number(health));
setDefaultTextColor(Qt::red);
setFont(QFont("times",16));
}
void Health::decrease(int amount){
health -= amount;
if ((health == 0) || (health == -1))
{
QMessageBox * box = new QMessageBox;
box->setText("Game over, your record is " + QString::number(game->max_score));
box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
box->show();
game->close();
}
setPlainText(QString("Health: ") + QString::number(health));
//game->score->decrease();
}
void Health::increase(int amount)
{
health += amount;
setPlainText(QString("Health: ") + QString::number(health));
}
int Health::getHealth(){
return health;
}