-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
73 lines (62 loc) · 2.15 KB
/
mainwindow.cpp
File metadata and controls
73 lines (62 loc) · 2.15 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
#include "mainwindow.h"
#include "newgamedialog.h"
#include "helpdialog.h"
#include "ui_mainwindow.h"
#include "gamemodel.h"
#include "victorydialog.h"
#include "card.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(this, SIGNAL(newGame(qint32,qint32)),&model, SLOT(newGame(qint32,qint32)));
connect(&model, SIGNAL(resetAllCards()),this, SLOT(resetAllCards()));
connect(&model, SIGNAL(stateChanged(qint32,qint32,qint32)),this, SLOT(monitorState(qint32,qint32,qint32)));
for (int i=0;i<7;i++) {
map[i]=QImage(QDir::currentPath()+"/images/card" + QString::number(i),"png");
}
newGame(6,3);
}
void MainWindow::onNewGameClicked() {
NewGameDialog * dialog = new NewGameDialog(this);
if(dialog->exec() == QDialog::Accepted){
if (dialog->getResult()==Ui::EASY) {
newGame(6,3);
} else if (dialog->getResult()==Ui::MEDIUM) {
newGame(7,4);
} else
newGame(8,5);
}
}
void MainWindow::monitorState(qint32 moves, qint32 total, qint32 left) {
statusBar()->showMessage("Wykonano ruchów: " + QString::number(moves) + ". Zostało " + QString::number(left) + "/" + QString::number(total) );
if (left==0) {
VictoryDialog * dialog = new VictoryDialog(this);
dialog->exec();
}
}
void MainWindow::resetAllCards() {
QGridLayout* layout = findChild<QGridLayout*>("gridLayout_2");
QLayoutItem *child;
while ((child = layout->takeAt(0)) != 0) {
delete child->widget();
delete child;
}
for (int i=0;i<model.columnCount();i++) {
for (int j=0;j<model.rowCount();j++) {
Card * c = new Card(i,j,map,this);
layout ->addWidget(c,i,j);
connect(c, SIGNAL(cardClicked(qint32,qint32)),&model, SLOT(clickedCard(qint32,qint32)));
connect(&model, SIGNAL(changeCard(qint32,qint32,qint32)),c, SLOT(setType(qint32,qint32,qint32)));
}
}
}
void MainWindow::onHelpClicked() {
HelpDialog * dialog = new HelpDialog(this);
dialog->exec();
}
MainWindow::~MainWindow()
{
delete ui;
}