-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameWindow.cpp
63 lines (47 loc) · 1.59 KB
/
GameWindow.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 <QGraphicsScene>
#include <QLinearGradient>
#include <QBrush>
#include <QDebug>
#include "GameWindow.h"
#include "ui_GameWindow.h"
GameWindow::GameWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::GameWindow)
{
ui->setupUi(this);
this->showFullScreen();
// Устанавливается градиент заднего плана
QLinearGradient gradient(0, 0, 0, ui->graphicsView->size().height());
gradient.setColorAt(0, QColor::fromRgbF(0.87, 0.89, 0.94, 1));
gradient.setColorAt(1, QColor::fromRgbF(0.69, 0.79, 0.97, 1));
QBrush brush(gradient);
ui->graphicsView->setBackgroundBrush(brush);
// Задается сцена в виде игрового поля
gameField=new GameField();
// Сцена размещается в графическом виде
ui->graphicsView->setScene(gameField);
ui->graphicsView->fitInView(0.0, 0.0, 5.0, 5.0, Qt::KeepAspectRatio);
// ui->graphicsView->fitInView(0.0, 0.0, 1.0, 1.0, Qt::KeepAspectRatio);
connect(gameField, SIGNAL(setScore(int)), this, SLOT(onSetScore(int)));
connect(gameField, SIGNAL(setLives(int)), this, SLOT(onSetLives(int)));
connect(gameField, SIGNAL(closeGame()), this, SLOT(reject()));
gameField->runGame();
}
GameWindow::~GameWindow()
{
delete gameField;
delete ui;
}
void GameWindow::reject()
{
qDebug() << "Reject game window";
QDialog::reject();
}
void GameWindow::onSetScore(const int iScore)
{
ui->lcdScreenScore->display(iScore);
}
void GameWindow::onSetLives(const int iLives)
{
ui->lcdScreenLives->display(iLives);
}