-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
138 lines (124 loc) · 4.16 KB
/
mainwindow.cpp
File metadata and controls
138 lines (124 loc) · 4.16 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
timer(new QTimer), secondtimer(new QTimer), counttime(60),
playerscore(0), bossscore(0)
{
ui->setupUi(this);
scene = new Scene;
ui->graphicsView->setScene(scene);
timer->start(10);
secondtimer->start(1000);
scene->gameGround();
QPalette HpBarColor, GameoverColor;
HpBarColor.setColor(QPalette::Highlight, QColor(Qt::red));
GameoverColor.setColor(QPalette::WindowText, QColor(Qt::yellow));
ui->PlayerhpBar->setValue(scene->player->rolehp); ui->BosshpBar->setValue(scene->boss->rolehp);
ui->PlayerhpBar->setPalette(HpBarColor); ui->BosshpBar->setPalette(HpBarColor);
ui->GameOver->setPalette(GameoverColor); ui->GameOver->setVisible(false);
ui->YouWin->setPalette(GameoverColor); ui->YouWin->setVisible(false);
ui->GameTime->setVisible(false); ui->TimeLable->setVisible(false);
this->connect(ui->Start, SIGNAL(clicked()), this, SLOT(startClick_slot()));
this->connect(scene, SIGNAL(skilluse()), this, SLOT(connectSkillTime_slot()));
this->connect(scene, SIGNAL(timeup()), this, SLOT(disconnectSkillTime_slot()));
this->connect(scene, SIGNAL(attacksuccess(int)), this, SLOT(hpChange_slot(int)));
this->connect(this, SIGNAL(gameover()), this, SLOT(Gameover_slot()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::hpChange_slot(int role)
{
switch(role){
case 1:
ui->PlayerhpBar->setValue(scene->player->rolehp-1);
scene->player->rolehp -= 1;
ScoreChange(1);
break;
case 2:
ui->BosshpBar->setValue(scene->boss->rolehp-1);
scene->boss->rolehp -= 1;
ScoreChange(2);
break;
case 3:
ui->BosshpBar->setValue(scene->boss->rolehp-2);
scene->boss->rolehp -= 2;
if(ui->BosshpBar->value()==1)
{
ui->BosshpBar->setValue(scene->boss->rolehp-1);
scene->boss->rolehp -= 1;
}
ScoreChange(3);
break;
}
if(ui->PlayerhpBar->value()==0 || ui->BosshpBar->value()==0)
emit gameover();
}
void MainWindow::setGameTime_slot()
{
counttime -= 1;
QString time = QString::number(counttime);
ui->GameTime->setText(time);
if (counttime == 0)
{
emit gameover();
}
}
void MainWindow::startClick_slot()
{
scene->setGamemode(true);
ui->Start->setVisible(false);
ui->GameTime->setVisible(true); ui->TimeLable->setVisible(true);
this->connect(secondtimer, SIGNAL(timeout()), this, SLOT(setGameTime_slot()));
scene->connect(scene->timer, SIGNAL(timeout()), scene, SLOT(bosstime_slot()));
scene->boss->connect(scene->boss->timer, SIGNAL(timeout()), scene->boss, SLOT(move()));
}
void MainWindow::connectSkillTime_slot()
{
this->connect(timer, SIGNAL(timeout()), this, SLOT(skillTimeCount_slot()));
}
void MainWindow::disconnectSkillTime_slot()
{
ui->SkillTime->setText("");
this->disconnect(timer, SIGNAL(timeout()), this, SLOT(skillTimeCount_slot()));
}
void MainWindow::skillTimeCount_slot()
{
QString time = QString::number(scene->stimeinterval);
QPalette ScoreBarColor;
ScoreBarColor.setColor(QPalette::WindowText, QColor(Qt::red));
ui->SkillTime->setPalette(ScoreBarColor);
ui->SkillTime->setText(time);
ui->SkillTime->setGeometry(1410,510,150,120);
}
void MainWindow::ScoreChange(int casenum)
{
switch(casenum){
case 1:
bossscore += 100;
break;
case 2:
playerscore += 100;
break;
case 3:
playerscore += 200;
break;
}
ui->BossScoreBar->display(bossscore);
ui->PlayerScoreBar->display(playerscore);
}
void MainWindow::Gameover_slot()
{
scene->setGamemode(false);
this->disconnect(secondtimer, SIGNAL(timeout()), this, SLOT(setGameTime_slot()));
scene->disconnect(scene->timer, SIGNAL(timeout()), scene, SLOT(bosstime_slot()));
scene->boss->disconnect(scene->boss->timer, SIGNAL(timeout()), scene->boss, SLOT(move()));
if(playerscore>=bossscore)
ui->YouWin->setVisible(true);
if(bossscore>playerscore)
ui->GameOver->setVisible(true);
}