-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
51 lines (40 loc) · 1.24 KB
/
mainwindow.cpp
File metadata and controls
51 lines (40 loc) · 1.24 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <QGraphicsEllipseItem>
#include "gameplay.h"
#include <QPen>
#include <QResizeEvent>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
iScore ( 0 )
{
ui->setupUi(this);
QGraphicsScene *scene = new QGraphicsScene(this);
QGraphicsRectItem *p1 = new QGraphicsRectItem(0, 0, 80, 20);
p1->setBrush(QBrush(Qt::blue));
QGraphicsRectItem *p2 = new QGraphicsRectItem(0, 0, 80, 20);
p2->setBrush(QBrush(Qt::green));
QGraphicsEllipseItem *ball = new QGraphicsEllipseItem(0, 0, 15, 15);
ball->setBrush(QBrush(Qt::magenta));
ui->boardView->setScene(scene);
iLoop = new Gameplay(*scene, p1, p2, ball, this);
QSize m(scene->sceneRect().size().width() + 10, scene->sceneRect().size().height() + 10);
ui->boardView->setMinimumSize(m);
resize(minimumSize());
ui->boardView->installEventFilter(iLoop);
QObject::connect(iLoop, SIGNAL(goal(int)),
this, SLOT(addScore(int)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::addScore(int count)
{
iScore += count;
ui->lcdNumber->display(iScore);
}