-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamegui.cpp
56 lines (47 loc) · 1.3 KB
/
gamegui.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
#include "gamegui.h"
#include "ui_gamegui.h"
//Create an item to put into the scene
#include <QApplication>
#include <QGraphicsScene>
#include "Snake.h"
#include "redsnake.h"
#include "greensnake.h"
#include "eat.h"
#include <QGraphicsView>
#include <QThread>
#include <QRandomGenerator>
#include <QTime>
#include <QScopedPointer>
#include "elementx.h"
#include <QDebug>
#include <QMessageBox>
GameGUI::GameGUI(QWidget *parent) :
QWidget(parent),
ui(new Ui::GameGUI)
{
ui->setupUi(this);
scene =new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
setAttribute(Qt::WA_QuitOnClose);
scene->addItem(snake);
snake->spawn();
ElementX *element = new ElementX();
scene->addItem(element);
qDebug()<<element->pos().y();
ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
ui->graphicsView->setFixedSize(402,402);
ui->graphicsView->setWindowTitle("Snake");
scene->setSceneRect(-0,-0,410,410);
}
void GameGUI::closeEvent (QCloseEvent *event) {
qDebug()<<"ggggg";
scene->removeItem(snake);
delete snake;
event->accept();
}
GameGUI::~GameGUI()
{
delete ui;
}