This repository has been archived by the owner on Dec 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamearea.h
71 lines (60 loc) · 1.49 KB
/
gamearea.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
#ifndef GAMEAREA_H
#define GAMEAREA_H
#include <QWidget>
#include <QVector>
#include <QPoint>
#include <QKeyEvent>
#include <QDebug>
#include <QTime>
#include "parameters.h"
#include "snake.h"
#include "fruit.h"
class GameArea : public QWidget
{
Q_OBJECT
private:
static const int padding = 10;
enum State {STOPPED, PLAYING, PAUSED, RESET} m_state;
bool dir_lock;
bool select = false;
Snake *snake = nullptr;
Direction snake_dir;
QPoint snake_head;
Fruit *fruit = nullptr;
QVector<bool> draw_walls;
QVector<QPoint> walls;
int delay = 0;
int timerId = 0;
int steps = 0;
void start_game();
void stop_game();
void pause_game();
void init_game();
void make_fruit();
void set_direction(const Direction &dir);
bool check_collision() const;
QPoint convertAbsToGrid(int x, int y);
protected:
void paintEvent(QPaintEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void timerEvent(QTimerEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
public:
explicit GameArea(QWidget *parent = nullptr);
public slots:
void stateChanged();
void saveGame();
void loadGame();
void startGame();
void pauseGame();
void resumeGame();
void resetGame();
signals:
void gamePaused();
void gameResumed();
void gameReset();
void gameEnded();
void updateTimer(int steps);
};
#endif // GAMEAREA_H