-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
94 lines (76 loc) · 2.06 KB
/
MainWindow.cpp
File metadata and controls
94 lines (76 loc) · 2.06 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
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "ImageManager.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
if (!m_databaseManager.isValid())
{
QMessageBox msgBox;
msgBox.setText("Cannot launch database or it is corrupted. Program terminated.");
msgBox.exec();
exit(1);
}
connect(ui->fAnsBtn, SIGNAL (released()), this, SLOT (handleFButton()));
connect(ui->sAnsBtn, SIGNAL (released()), this, SLOT (handleSButton()));
connect(ui->tAnsBtn, SIGNAL (released()), this, SLOT (handleTButton()));
connect(ui->foAnsBtn, SIGNAL (released()), this, SLOT (handleFoButton()));
m_pButtons = {ui->fAnsBtn, ui->sAnsBtn, ui->tAnsBtn, ui->foAnsBtn};
generate();
ImageManager imageManager;
imageManager.setImage("resources/knight.png", ui->heroImg);
imageManager.setImage("resources/goblin.png", ui->enemyImg);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::handleButton(size_t index)
{
if (index == m_index)
{
int enemyHp = ui->enemyHP->value() - 10;
if (enemyHp > 0)
ui->enemyHP->setValue(ui->enemyHP->value() - 10);
else
{
ui->enemyHP->setValue(100);
ui->heroEXP->setValue(ui->heroEXP->value() + 10);
}
}
else
ui->heroHP->setValue(ui->heroHP->value() - 10);
generate();
}
void MainWindow::generate()
{
m_databaseManager.shuffle();
ui->questLbl->setText(m_databaseManager.getQuestion());
m_index = rand() % 4;
for (size_t i = 0; i < 4; ++i)
{
if (i == m_index)
m_pButtons[i]->setText(m_databaseManager.getCorrectAnswer());
else
m_pButtons[i]->setText(m_databaseManager.getIncorrectAnswer());
}
}
void MainWindow::handleFButton()
{
handleButton(0);
}
void MainWindow::handleSButton()
{
handleButton(1);
}
void MainWindow::handleTButton()
{
handleButton(2);
}
void MainWindow::handleFoButton()
{
handleButton(3);
}