-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgamewidget.h
83 lines (76 loc) · 1.47 KB
/
gamewidget.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
82
83
#ifndef GAMEWIDGET_H
#define GAMEWIDGET_H
#include <QWidget>
#include <QLabel>
#include <QList>
#include <QTimer>
#include <QKeyEvent>
#include <ctime>
#include <QPushButton>
#include <QFont>
#include <QLineEdit>
#include <QLCDNumber>
#define MAX_X 40
#define MAX_Y 40
#define Label_Size 20
enum Labeltype{
bg_label,
snake_label,
food_label,
border_label,
};
struct Snake{
QLabel *label;
int type;
int x;
int y;
};
namespace Ui {
class GameWidget;
}
class GameWidget : public QWidget
{
Q_OBJECT
protected:
void keyPressEvent(QKeyEvent *e);
void mousePressEvent(QMouseEvent *event);
public:
explicit GameWidget(QWidget *parent = nullptr);
~GameWidget();
void initGame();
void initBorder();
void initSnake();
void moveSnake();
void createFood();
void startGame(double);
void pauseGame();
void continueGame(double);
void enableCreate();
void saveGame();
void loadGame();
void restartGame();
void quitGame();
void gameOver();
signals:
void gameOverSignal();
void displayStepSignal(int);
void displayScoreSignal(int);
private:
int steps=0;
int scores=0;
double speed;
Ui::GameWidget *ui;
Snake *map_label[MAX_X][MAX_Y];
QTimer timer;
QList<Snake*> snake;
Snake* head;
Snake* tail;
int dX,dY;
bool canCreat;
bool clicked[MAX_X][MAX_Y];
bool pressed;
bool canMove;
public slots:
void snakeMoveSlots();
};
#endif // GAMEWIDGET_H