forked from yangsheng6810/pvz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplant.cpp
49 lines (40 loc) · 1.04 KB
/
plant.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
#include "plant.h"
int Plant::originHealthPoint = 100;
Plant::Plant(QWidget *parent, QString picName) :
QWidget(parent) //, healthPoint(originHealthPoint)
{
QPushButton *bite = new QPushButton(tr("bite"));
connect(bite, SIGNAL(clicked()), this, SLOT(bitten()));// this is for debug
hp = new QLCDNumber(3);
hp->setSegmentStyle(QLCDNumber::Filled);
connect(this,SIGNAL(hpChanged(int)),hp,SLOT(display(int)));
setMinimumSize(40,40);
resetHealthPoint();
QLabel *pea = new QLabel(this);
QMovie *movie = new QMovie(picName);
pea->setMovie(movie);
movie->start();
pea->show();
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(pea);
layout->addWidget(bite);
layout->addWidget(hp);
this->setLayout(layout);
}
void Plant::bitten()
{
int num = 4;
healthPoint -= num;
emit hpChanged(healthPoint);
if (healthPoint <= 0){
die();
}
}
void Plant::die()
{
}
void Plant::resetHealthPoint()
{
healthPoint = originHealthPoint;
emit hpChanged(healthPoint);
}