-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysnake.h
81 lines (65 loc) · 1.35 KB
/
mysnake.h
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
74
75
76
77
78
79
80
81
#ifndef MYSNAKE_H
#define MYSNAKE_H
#include <QWidget>
#include <QTime>
#include <QList>
#include <QRect>
#include <QTimer>
#include <QPainter>
#include <QKeyEvent>
#include <QApplication>
#include <QDesktopWidget>
class MySnake : public QWidget
{
Q_OBJECT
public:
explicit MySnake(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *e);
void keyPressEvent(QKeyEvent *e);
private:
QImage dot;
QImage head;
QImage apple;
QTimer *timer;
int WINDOW_WIDTH;
int DOT_SIZE;
int START_DOTS;
int START_LEVEL;
int WINDOW_HEIGHT;
int ALL_DOTS;
int RAND_POS_X;
int RAND_POS_Y;
int DELTA_LEVEL;
int MAX_LEVEL;
int dots;
int level;
int new_level;
int apple_x;
int apple_y;
bool leftDirection;
bool rightDirection;
bool upDirection;
bool downDirection;
bool keyPressed;
bool inGame;
bool startGame;
bool pauseGame;
bool winGame;
QList<int> x;
QList<int> y;
private:
void loadImages();
void checkImages(QImage &image);
void initGame();
void locateApple();
void checkApple();
void checkCollision();
void move();
void gameOver(QString s);
private Q_SLOTS:
void myTimer();
Q_SIGNALS:
void closeIt();
};
#endif // MYSNAKE_H