-
Notifications
You must be signed in to change notification settings - Fork 0
/
minewindow.cpp
63 lines (53 loc) · 1.59 KB
/
minewindow.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
#include "minewindow.h"
#include "mineboard.h"
#include <QMessageBox>
MineWindow::MineWindow(QWidget *parent) : QMainWindow(parent), board(nullptr)
{
reset();
}
void MineWindow::reset()
{
board = new MineBoard(25, 25, this);
setCentralWidget(board);
resize(board->size());
setMaximumSize(board->width(), board->height());
connect(board, SIGNAL(lost()), this, SLOT(lost()));
connect(board, SIGNAL(won()), this, SLOT(won()));
board->initialize();
}
void MineWindow::checkButtons(QAbstractButton *btn)
{
if (btn->text() == tr("Restart")) {
this->reset();
} else if (btn->text() == tr("Close")) {
this->close();
}
}
void MineWindow::lost()
{
QMessageBox msgBox;
msgBox.setWindowTitle("You lost the game.");
msgBox.setText("You lost the game.");
msgBox.addButton(tr("Restart"), QMessageBox::ResetRole);
msgBox.addButton(tr("Close"), QMessageBox::DestructiveRole);
connect(&msgBox, SIGNAL(buttonClicked(QAbstractButton *)), this,
SLOT(checkButtons(QAbstractButton *)));
msgBox.exec();
}
void MineWindow::won()
{
board->openAll();
QMessageBox msgBox;
msgBox.setWindowTitle("You won.");
msgBox.setText("You won.");
msgBox.addButton(tr("Restart"), QMessageBox::ResetRole);
msgBox.addButton(tr("Close"), QMessageBox::DestructiveRole);
connect(&msgBox, SIGNAL(buttonClicked(QAbstractButton *)), this,
SLOT(checkButtons(QAbstractButton *)));
msgBox.exec();
}
MineWindow::~MineWindow()
{
// delete ui;
// delete board;
}