-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cpp
More file actions
61 lines (46 loc) · 1.28 KB
/
Copy pathgame.cpp
File metadata and controls
61 lines (46 loc) · 1.28 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
#include "game.h"
#include <QTimer>
#include <QGraphicsTextItem>
#include <QFont>
#include "fruit.h"
#include "myrect.h"
#include <QApplication>
#include <QDebug>
#include <QGraphicsView>
extern Game * game;
QGraphicsView * view;
Game::Game()
{
//create a scene
points = 0;
QGraphicsScene * scene = new QGraphicsScene();
//creat rect
MyRect * player = new MyRect();
player->setRect(0,0,50,50);
scene->addItem(player);
//make item focusable
player->setFlag(QGraphicsItem::ItemIsFocusable);
player->setFocus();
player->setBrush(QBrush(Qt::black));
//creating fruit
Fruit * fruit = new Fruit();
fruit->setBrush(QBrush(Qt::lightGray));
scene->addItem(fruit);
//creating score
//create the view
view = new QGraphicsView(scene);
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->show();
view->setFixedSize(600,600);
scene->setSceneRect(0,0,600,600);
scene->setBackgroundBrush(QBrush(Qt::white));
player->setPos(view->width()/2,view->height()/2 - player->rect().height());
}
void Game::gameOverBro()
{
if(gameover){
qDebug() << "\nGAME OVER.\n\nYou got the score " << game->points;
QApplication::quit();
}
}